refcnt.h

Go to the documentation of this file.
00001 #ifndef _GPXE_REFCNT_H
00002 #define _GPXE_REFCNT_H
00003 
00004 /** @file
00005  *
00006  * Reference counting
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 /**
00013  * A reference counter
00014  *
00015  * This data structure is designed to be embedded within a
00016  * reference-counted object.
00017  *
00018  * Reference-counted objects are freed when their reference count
00019  * drops below zero.  This means that a freshly allocated-and-zeroed
00020  * reference-counted object will be freed on the first call to
00021  * ref_put().
00022  */
00023 struct refcnt {
00024         /** Current reference count
00025          *
00026          * When this count is decremented below zero, the free()
00027          * method will be called.
00028          */
00029         int refcnt;
00030         /** Free containing object
00031          *
00032          * This method is called when the reference count is
00033          * decremented below zero.
00034          *
00035          * If this method is left NULL, the standard library free()
00036          * function will be called.  The upshot of this is that you
00037          * may omit the free() method if the @c refcnt object is the
00038          * first element of your reference-counted struct.
00039          */
00040         void ( * free ) ( struct refcnt *refcnt );
00041 };
00042 
00043 extern struct refcnt * ref_get ( struct refcnt *refcnt );
00044 extern void ref_put ( struct refcnt *refcnt );
00045 
00046 #endif /* _GPXE_REFCNT_H */

Generated on Tue Apr 6 20:01:08 2010 for gPXE by  doxygen 1.5.7.1