Reference Counting


Typedefs

typedef struct __os_refcount_impl os_refcount_t

Functions

void os_refcount_init (os_refcount_t *refcount, os_refcount_callback_f func, void *arg)
void os_refcount_destroy (os_refcount_t *refcount)
void os_refcount_get (os_refcount_t *refcount)
void os_refcount_put (os_refcount_t *refcount)

Detailed Description

A reference count is an atomic counter. A callback function is called whenever the count reaches zero.

A generic implementation is provided that is suitable for all platforms that support the spinlock API in <oska/spinlock.h> (see Spinlocks).


Typedef Documentation

typedef struct __os_refcount_impl os_refcount_t

A reference count object.


Function Documentation

void os_refcount_destroy ( os_refcount_t refcount  ) 

Destroy a reference count object.

Parameters:
refcount the reference count.

References os_spinlock_destroy().

void os_refcount_get ( os_refcount_t refcount  ) 

Atomically increase the reference count by 1.

Parameters:
refcount the reference count.

References os_spinlock_lock_intsave(), and os_spinlock_unlock_intrestore().

void os_refcount_init ( os_refcount_t refcount,
os_refcount_callback_f  func,
void *  arg 
)

Initialize a reference count to 1.

Initialized reference counts must be destroyed by calling os_refcount_destroy().

Parameters:
refcount the reference count.
func the function which will be called when the reference count reaches 0.
arg an argument to pass to func.

References os_spinlock_init().

void os_refcount_put ( os_refcount_t refcount  ) 

Atomically decrease the reference count by 1.

The callback function passed to the call to os_refcount_init() is called if the count was decreased to zero.

Parameters:
refcount the reference count.

References os_spinlock_lock_intsave(), and os_spinlock_unlock_intrestore().


Generated on Wed Oct 27 15:14:03 2010 for oska by  doxygen 1.5.5