summaryrefslogtreecommitdiffstats
path: root/libdimension/refcount-internal.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-12-24 13:19:38 -0500
committerTavian Barnes <tavianator@gmail.com>2011-12-24 13:19:38 -0500
commita8181915a4aac7a37bdd62705e2eac1067eb1904 (patch)
tree4e90ce29b5fad0d34f268e5ac9d247c3ef034a3f /libdimension/refcount-internal.h
parentbabba43cd4d1b9c92a569f19acbe17e429193b01 (diff)
downloaddimension-a8181915a4aac7a37bdd62705e2eac1067eb1904.tar.xz
Use macros to initialize refcounts.
Diffstat (limited to 'libdimension/refcount-internal.h')
-rw-r--r--libdimension/refcount-internal.h15
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))