2 #ifndef _MADARA_THREADSAFE_REFCOUNTER_CPP_
3 #define _MADARA_THREADSAFE_REFCOUNTER_CPP_
17 bool increase_count,
bool manage)
18 : ptr_ (new
Shim (ptr, manage))
47 ptr_ =
new Shim (ptr);
98 return ptr_ && ptr_->refcount_ > 0;
102 template <
typename T>
117 template <
typename T>
121 const T * result (0);
132 template <
typename T>
140 template <
typename T>
149 template <
typename T>
164 template <
typename T>
168 const T * result (0);
179 template <
typename T>
183 if (ptr_ && ptr_->manage_)
185 MADARA_GUARD_TYPE guard (ptr_->mutex_);
191 template <
typename T>
195 if (ptr_&& ptr_->manage_)
197 MADARA_GUARD_TYPE guard (ptr_->mutex_);
199 if (ptr_->refcount_ <= 0)
207 template <
typename T>
209 : t_ (t), refcount_ (1), manage_ (manage)
213 template <
typename T>
This template class provides transparent reference counting of its template parameter T...
T * get_ptr(void)
get the underlying pointer
T * get(void)
get the underlying pointer
ThreadSafeRefcounter(void)
default Ctor
void operator=(T *ptr)
assignment operator for times when you don't want the reference increased for incoming ptr ...
T * operator->(void)
mimic pointer dereferencing
void increment(void)
implementation of the increment operation
virtual ~ThreadSafeRefcounter(void)
Dtor will delete pointer if refcount becomes 0.
A shim class that keeps track of the reference count and a pointer to the type T that's reference cou...
Shim * ptr_
Pointer to the Shim.
Shim(T *t, bool manage=true)
Constructor.
T & operator*(void)
dereference operator
bool is_valid(void) const
checks to see if the underlying pointer is valid
void decrement(void)
implementation of the decrement operation