From 4bfd5b52c1fae75eb0449af626ec69543f9334fa Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 15 Jun 2010 17:33:23 +0100 Subject: [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 --- src/include/ipxe/refcnt.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/include/ipxe/refcnt.h') 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 ); -- cgit v1.2.3-55-g7522