In file refcount/refcount.hh:

template <class T> class static_ref_counter : public thread mutex

static reference counter.

Inheritance:


Public Fields

typedef T class_type
Parent class type

Public Methods

explicit static_ref_counter (T* parent = 0, bool array = false)
Make a reference counter
int getCount () const
Get the reference count
void setCount (int count)
Set the reference count
T* getParent () const
Get the parent class
void setParent (T* parent, bool array = false)
Set the parent class
static_ref_counter& operator++ ()
increase the reference count (prefix)
static_ref_counter& operator++ (int)
increase the reference count (postfix)
static_ref_counter& operator-- ()
decrease the reference count (prefix); deletes parant if reaches zero
static_ref_counter& operator-- (int)
decrease the reference count (postfix); deletes parant if reaches zero
bool increase ()
increase (returns true if counter value is positive)
bool decrease ()
decrease (returns true if deleted)
T& operator* () const
dereference operator (returns parent)
T* operator-> () const
member access operator (returns parent)

Inherited from mutex:

Public Methods

mutex& operator= (const mutex&)
virtual void lock()
virtual void readlock()
virtual void writelock()
virtual void unlock()
virtual bool trylock(locktype lck = rdlock)

Inherited from abstractsemaphore:

Public Fields

rdlock
wrlock

Public Methods

virtual bool trylock_timed(int timeout, locktype lck = rdlock)

Public

typedef enum locktype

Documentation

A templated reference counter. The counter maintains a count value and a pointer to a parent class. The counter value is initialized with zero and can be increased and decreased with the corresponding operators. If the reference counter reaches zero, the parant class will be deleted. A static reference counter can not be copied. A static refernce counter is MT safe in the sense that it protects its refernce counter. However, it will not protect the parent class. Since the static_ref_counter is derived from the mutex object, it can be used to protect the parent class. To avoid deadlock it must not be locked during increasing or decreasing its count value.

Example:

    // one_resource is a sharable resource which implements 
    // reference counting.
    class one_resource {
       static_ref_count<one_resource> fRef;
    public:
       one_resource() : fRef (this) {++fRef; }
       bool refInc() {retrun fRef.Increase(); }
       bool refDec() {retrun fRef.Decrease(); }
       void modify() {
          thread::semlock (fRef);  // use it as mutex
	  ... }
       ...
    };
    // Since one-resource deleted itself when the refercnce count reaches
    // zero, it has to be created with the new operator. In most cases it 
    // is probably better to use a dynamic refernce counter.
    

typedef T class_type
Parent class type

explicit static_ref_counter(T* parent = 0, bool array = false)
Make a reference counter

int getCount() const
Get the reference count

void setCount(int count)
Set the reference count

T* getParent() const
Get the parent class

void setParent(T* parent, bool array = false)
Set the parent class

static_ref_counter& operator++()
increase the reference count (prefix)

static_ref_counter& operator++(int)
increase the reference count (postfix)

static_ref_counter& operator--()
decrease the reference count (prefix); deletes parant if reaches zero

static_ref_counter& operator--(int)
decrease the reference count (postfix); deletes parant if reaches zero

bool increase()
increase (returns true if counter value is positive)

bool decrease()
decrease (returns true if deleted)

T& operator*() const
dereference operator (returns parent)

T* operator->() const
member access operator (returns parent)


This class has no child classes.

alphabetic index hierarchy of classes


Please send questions and comments to zweizig_j@ligo.caltech.edu


generated by doc++