00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00034
00035 #ifndef GROOVX_NUB_REFCOUNTED_H_UTC20050626084018_DEFINED
00036 #define GROOVX_NUB_REFCOUNTED_H_UTC20050626084018_DEFINED
00037
00038 #include "rutz/atomic.h"
00039
00040 #include <cstdlib>
00041
00042 namespace nub
00043 {
00044 class ref_counts;
00045 class ref_counted;
00046 }
00047
00048
00049
00050
00051
00052
00053 #ifndef GVX_DTOR_NOTHROW
00054 # define GVX_DTOR_NOTHROW
00055 #endif
00056
00058
00070
00071
00072 struct nub::ref_counts
00073 {
00074 public:
00075 friend class nub::ref_counted;
00076
00077 void* operator new(size_t bytes);
00078 void operator delete(void* space, size_t bytes);
00079
00080 ref_counts() throw();
00081
00082 private:
00084 ~ref_counts() throw();
00085
00086 public:
00087
00088 bool is_owner_alive() const throw() { return m_owner_alive; }
00089
00090 void acquire_weak() throw();
00091 int release_weak() throw();
00092
00093 void debug_dump() const throw();
00094
00095 private:
00096 ref_counts(const ref_counts&) throw();
00097 ref_counts& operator=(const ref_counts&) throw();
00098
00099 void acquire_strong() throw();
00100 int release_strong() throw();
00101 void release_strong_no_delete() throw();
00102
00103 rutz::atomic_int_t m_strong;
00104 rutz::atomic_int_t m_weak;
00105 bool m_owner_alive;
00106 bool m_volatile;
00107 };
00108
00109
00110
00112
00127
00128
00129 class nub::ref_counted
00130 {
00131 private:
00132 ref_counts* const m_ref_counts;
00133
00134
00135
00136 ref_counted(const ref_counted& other);
00137 ref_counted& operator=(const ref_counted& other);
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 #ifdef GVX_ENFORCE_FACTORY_FUNCTIONS
00150 protected:
00151 #else
00152 public:
00153 #endif
00154
00157 void* operator new(size_t bytes);
00158
00161 void operator delete(void* space, size_t bytes);
00162
00164 ref_counted();
00165
00173 virtual ~ref_counted() GVX_DTOR_NOTHROW;
00174
00176 void mark_as_volatile() throw();
00177
00178 public:
00180
00183 void incr_ref_count() const throw();
00184
00186
00191 void decr_ref_count() const throw();
00192
00194
00199 void decr_ref_count_no_delete() const throw();
00200
00202
00205 bool is_shared() const throw();
00206
00208
00210 bool is_unshared() const throw();
00211
00217 bool is_not_shareable() const throw();
00218
00220 ref_counts* get_counts() const throw();
00221
00222
00224 int dbg_ref_count() const throw();
00225
00227 int dbg_weak_ref_count() const throw();
00228 };
00229
00230 static const char __attribute__((used)) vcid_groovx_nub_refcounted_h_utc20050626084018[] = "$Id: refcounted.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00231 #endif // !GROOVX_NUB_REFCOUNTED_H_UTC20050626084018_DEFINED