Rename gpxe to .
[grub-extras.git] / src / include / gpxe / refcnt.h
blobe56f1d310b187e4dce5e24257669318e95fbdf2a
1 #ifndef _GPXE_REFCNT_H
2 #define _GPXE_REFCNT_H
4 /** @file
6 * Reference counting
8 */
10 FILE_LICENCE ( GPL2_OR_LATER );
12 /**
13 * A reference counter
15 * This data structure is designed to be embedded within a
16 * reference-counted object.
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().
23 struct refcnt {
24 /** Current reference count
26 * When this count is decremented below zero, the free()
27 * method will be called.
29 int refcnt;
30 /** Free containing object
32 * This method is called when the reference count is
33 * decremented below zero.
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.
40 void ( * free ) ( struct refcnt *refcnt );
43 extern struct refcnt * ref_get ( struct refcnt *refcnt );
44 extern void ref_put ( struct refcnt *refcnt );
46 #endif /* _GPXE_REFCNT_H */