STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::atomic_counted_object Class Reference

Detailed Description

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.

+ Inheritance diagram for stxxl::atomic_counted_object:
+ Collaboration diagram for stxxl::atomic_counted_object:

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_objectoperator= (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...
 

Constructor & Destructor Documentation

stxxl::atomic_counted_object::atomic_counted_object ( )
inline

new objects have zero reference count

Definition at line 473 of file counting_ptr.h.

stxxl::atomic_counted_object::atomic_counted_object ( const atomic_counted_object )
inline

coping still creates a new object with zero reference count

Definition at line 477 of file counting_ptr.h.

stxxl::atomic_counted_object::~atomic_counted_object ( )
inline

Definition at line 484 of file counting_ptr.h.

Member Function Documentation

bool stxxl::atomic_counted_object::dec_reference ( ) const
inline

Call whenever resetting (i.e. overwriting) a pointer to the object. IMPORTANT: In case of self-assignment, call AFTER inc_reference().

Returns
if the object has to be deleted (i.e. if it's reference count dropped to zero)

Definition at line 498 of file counting_ptr.h.

unsigned_type stxxl::atomic_counted_object::get_reference_count ( ) const
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().

void stxxl::atomic_counted_object::inc_reference ( ) const
inline

Call whenever setting a pointer to the object.

Definition at line 489 of file counting_ptr.h.

atomic_counted_object& stxxl::atomic_counted_object::operator= ( const atomic_counted_object )
inline

assignment operator, leaves pointers unchanged

Definition at line 481 of file counting_ptr.h.

bool stxxl::atomic_counted_object::unique ( ) const
inline

Test if the counted_object is referenced by only one counting_ptr.

Definition at line 505 of file counting_ptr.h.

Member Data Documentation

unsigned_type stxxl::atomic_counted_object::m_reference_count
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.

mutex stxxl::atomic_counted_object::m_reference_count_mutex
mutableprivate

the mutex used to synchronize access to the reference counter.

Definition at line 469 of file counting_ptr.h.


The documentation for this class was generated from the following file: