diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-12-24 13:19:38 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-12-24 13:19:38 -0500 |
commit | a8181915a4aac7a37bdd62705e2eac1067eb1904 (patch) | |
tree | 4e90ce29b5fad0d34f268e5ac9d247c3ef034a3f /libdimension/refcount-internal.h | |
parent | babba43cd4d1b9c92a569f19acbe17e429193b01 (diff) | |
download | dimension-a8181915a4aac7a37bdd62705e2eac1067eb1904.tar.xz |
Use macros to initialize refcounts.
Diffstat (limited to 'libdimension/refcount-internal.h')
-rw-r--r-- | libdimension/refcount-internal.h | 15 |
1 files changed, 13 insertions, 2 deletions
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 @@ -24,10 +24,21 @@ */ /** + * 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)) |