summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe
diff options
context:
space:
mode:
authorMichael Brown2010-06-15 18:33:23 +0200
committerMichael Brown2010-06-22 15:26:40 +0200
commit4bfd5b52c1fae75eb0449af626ec69543f9334fa (patch)
tree297bc75308e763df909fb0733c0ca2ac109ebcbc /src/include/ipxe
parent[pcnet32] Replace pcnet32 with native driver (diff)
downloadipxe-4bfd5b52c1fae75eb0449af626ec69543f9334fa.tar.gz
ipxe-4bfd5b52c1fae75eb0449af626ec69543f9334fa.tar.xz
ipxe-4bfd5b52c1fae75eb0449af626ec69543f9334fa.zip
[refcnt] Add ref_init() wrapper function
Standardise on using ref_init() to initialise an embedded reference count, to match the coding style used by other embedded objects. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe')
-rw-r--r--src/include/ipxe/refcnt.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/include/ipxe/refcnt.h b/src/include/ipxe/refcnt.h
index 4b023225e..f359ac9c1 100644
--- a/src/include/ipxe/refcnt.h
+++ b/src/include/ipxe/refcnt.h
@@ -40,6 +40,41 @@ struct refcnt {
void ( * free ) ( struct refcnt *refcnt );
};
+/**
+ * Initialise a reference counter
+ *
+ * @v refcnt Reference counter
+ * @v free Freeing function
+ */
+static inline __attribute__ (( always_inline )) void
+ref_init ( struct refcnt *refcnt,
+ void ( * free ) ( struct refcnt *refcnt ) ) {
+ refcnt->free = free;
+}
+
+/**
+ * Initialise a reference counter
+ *
+ * @v refcnt Reference counter
+ * @v free Free containing object
+ */
+#define ref_init( refcnt, free ) do { \
+ if ( __builtin_constant_p ( (free) ) && ( (free) == NULL ) ) { \
+ /* Skip common case of no initialisation required */ \
+ } else { \
+ ref_init ( (refcnt), (free) ); \
+ } \
+ } while ( 0 )
+
+/**
+ * Initialise a static reference counter
+ *
+ * @v free Free containing object
+ */
+#define REF_INIT( free ) { \
+ .free = free, \
+ }
+
extern struct refcnt * ref_get ( struct refcnt *refcnt );
extern void ref_put ( struct refcnt *refcnt );