From a8181915a4aac7a37bdd62705e2eac1067eb1904 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 24 Dec 2011 13:19:38 -0500 Subject: Use macros to initialize refcounts. --- libdimension/refcount-internal.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'libdimension/refcount-internal.h') diff --git a/libdimension/refcount-internal.h b/libdimension/refcount-internal.h index 5ae5d58..fb6d3c6 100644 --- a/libdimension/refcount-internal.h +++ b/libdimension/refcount-internal.h @@ -23,11 +23,22 @@ * Reference count internal API. */ +/** + * Initialize a reference count. + * @param[in,out] object The reference-counted object. + */ +#define DMNSN_REFCOUNT_INIT(object) (void)((object)->DMNSN_REFCOUNT_FIELD = 1) + +/** + * Initialize a reference count in a statically-allocated object. + */ +#define DMNSN_REFCOUNT_INITIALIZER .DMNSN_REFCOUNT_FIELD = 1 + /** * Decrement a reference count. * @param[in,out] object The reference-counted object to release. * @return Whether the object is now garbage. */ #define DMNSN_DECREF(object) \ - ((object) && ((object)->DMNSN_REFCOUNT_NAME == 0 \ - || --(object)->DMNSN_REFCOUNT_NAME == 0)) + ((object) && ((object)->DMNSN_REFCOUNT_FIELD == 0 \ + || --(object)->DMNSN_REFCOUNT_FIELD == 0)) -- cgit v1.2.3