STXXL
1.4-dev
|
Provides reference counting abilities for use with counting_ptr with mutex locking.
Use as superclass of the actual object, this adds a reference_count value. Then either use counting_ptr as pointer to manage references and deletion, or just do normal new and delete.
This class does thread-safe increment and decrement using scoped locks. A faster version of this class is available using atomic operations.
Definition at line 461 of file counting_ptr.h.
Public Member Functions | |
atomic_counted_object () | |
new objects have zero reference count More... | |
atomic_counted_object (const atomic_counted_object &) | |
coping still creates a new object with zero reference count More... | |
~atomic_counted_object () | |
bool | dec_reference () const |
Call whenever resetting (i.e. overwriting) a pointer to the object. IMPORTANT: In case of self-assignment, call AFTER inc_reference(). More... | |
unsigned_type | get_reference_count () const |
Return the number of references to this object (for debugging) More... | |
void | inc_reference () const |
Call whenever setting a pointer to the object. More... | |
atomic_counted_object & | operator= (const atomic_counted_object &) |
assignment operator, leaves pointers unchanged More... | |
bool | unique () const |
Test if the counted_object is referenced by only one counting_ptr. More... | |
Private Attributes | |
unsigned_type | m_reference_count |
the reference count is kept mutable to all const_counting_ptr() to change the reference count. More... | |
mutex | m_reference_count_mutex |
the mutex used to synchronize access to the reference counter. More... | |
|
inline |
new objects have zero reference count
Definition at line 473 of file counting_ptr.h.
|
inline |
coping still creates a new object with zero reference count
Definition at line 477 of file counting_ptr.h.
|
inline |
Definition at line 484 of file counting_ptr.h.
|
inline |
Call whenever resetting (i.e. overwriting) a pointer to the object. IMPORTANT: In case of self-assignment, call AFTER inc_reference().
Definition at line 498 of file counting_ptr.h.
|
inline |
Return the number of references to this object (for debugging)
Definition at line 512 of file counting_ptr.h.
Referenced by stxxl::request::check_nref_failed(), stxxl::request::request(), stxxl::request_queue_impl_qwqr::worker(), and stxxl::request::~request().
|
inline |
Call whenever setting a pointer to the object.
Definition at line 489 of file counting_ptr.h.
|
inline |
assignment operator, leaves pointers unchanged
Definition at line 481 of file counting_ptr.h.
|
inline |
Test if the counted_object is referenced by only one counting_ptr.
Definition at line 505 of file counting_ptr.h.
|
mutableprivate |
the reference count is kept mutable to all const_counting_ptr() to change the reference count.
Definition at line 466 of file counting_ptr.h.
|
mutableprivate |
the mutex used to synchronize access to the reference counter.
Definition at line 469 of file counting_ptr.h.