00001 #ifndef BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
00002 #define BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <booster/config.h>
00016 #include <booster/smart_ptr/sp_typeinfo.h>
00017
00018 #ifndef BOOSTER_WIN32
00019 #include <pthread.h>
00020 #endif
00021
00022 namespace booster
00023 {
00024
00025 namespace detail
00026 {
00027
00028 typedef union sp_counted_base_atomic {
00029 int i;
00030 unsigned int ui;
00031 long int li;
00032 unsigned long int uli;
00033 long long int lli;
00034 unsigned long long int ulli;
00035 char at_least[8];
00036 } sp_counted_base_atomic_type;
00037
00038
00039 class BOOSTER_API sp_counted_base
00040 {
00041 private:
00042
00043 sp_counted_base( sp_counted_base const & );
00044 sp_counted_base & operator= ( sp_counted_base const & );
00045
00046 typedef sp_counted_base_atomic_type atomic_type;
00047
00048 mutable atomic_type use_count_;
00049 mutable atomic_type weak_count_;
00050 #ifndef BOOSTER_WIN32
00051 mutable pthread_mutex_t lock_;
00052 #endif
00053
00054 public:
00055
00056 sp_counted_base();
00057 virtual ~sp_counted_base();
00058
00059
00060
00061
00062 virtual void dispose() = 0;
00063
00064
00065
00066 virtual void destroy();
00067 virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
00068 void add_ref_copy();
00069 bool add_ref_lock();
00070 void release();
00071 void weak_add_ref();
00072 void weak_release();
00073 long use_count() const;
00074 };
00075
00076 }
00077
00078 }
00079
00080 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
00081