1 #ifndef _GPXE_REFCNT_H 2 #define _GPXE_REFCNT_H 3 4 /** @file 5 * 6 * Reference counting 7 * 8 */ 9 10 FILE_LICENCE ( GPL2_OR_LATER ); 11 12 /** 13 * A reference counter 14 * 15 * This data structure is designed to be embedded within a 16 * reference-counted object. 17 * 18 * Reference-counted objects are freed when their reference count 19 * drops below zero. This means that a freshly allocated-and-zeroed 20 * reference-counted object will be freed on the first call to 21 * ref_put(). 22 */ 23 struct refcnt { 24 /** Current reference count 25 * 26 * When this count is decremented below zero, the free() 27 * method will be called. 28 */ 29 int refcnt; 30 /** Free containing object 31 * 32 * This method is called when the reference count is 33 * decremented below zero. 34 * 35 * If this method is left NULL, the standard library free() 36 * function will be called. The upshot of this is that you 37 * may omit the free() method if the @c refcnt object is the 38 * first element of your reference-counted struct. 39 */ 40 void ( * free ) ( struct refcnt *refcnt ); 41 }; 42 43 extern struct refcnt * ref_get ( struct refcnt *refcnt ); 44 extern void ref_put ( struct refcnt *refcnt ); 45 46 #endif /* _GPXE_REFCNT_H */ 47