[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>
This commit is contained in:
Michael Brown
2010-06-15 17:33:23 +01:00
parent f4faa27dfd
commit 4bfd5b52c1
22 changed files with 59 additions and 14 deletions

View File

@@ -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 );