From 4479d25609e26253c4e5fcfc78b093c0b45cefb8 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 28 May 2011 18:16:04 -0600 Subject: Don't allocate reference counts on the heap. --- libdimension/dimension/camera.h | 2 +- libdimension/dimension/canvas.h | 2 +- libdimension/dimension/interior.h | 2 +- libdimension/dimension/object.h | 2 +- libdimension/dimension/refcount.h | 29 +++++++---------------------- libdimension/dimension/texture.h | 4 ++-- 6 files changed, 13 insertions(+), 28 deletions(-) (limited to 'libdimension/dimension') diff --git a/libdimension/dimension/camera.h b/libdimension/dimension/camera.h index 67fffc0..75d86a9 100644 --- a/libdimension/dimension/camera.h +++ b/libdimension/dimension/camera.h @@ -46,7 +46,7 @@ struct dmnsn_camera { void *ptr; /**< @internal Generic pointer for camera info. */ - dmnsn_refcount *refcount; /**< @internal reference count. */ + dmnsn_refcount refcount; /**< @internal reference count. */ }; /** diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h index f33fc88..864e2d6 100644 --- a/libdimension/dimension/canvas.h +++ b/libdimension/dimension/canvas.h @@ -40,7 +40,7 @@ typedef struct { */ dmnsn_color *pixels; - dmnsn_refcount *refcount; /**< @internal Reference count. */ + dmnsn_refcount refcount; /**< @internal Reference count. */ } dmnsn_canvas; /* Forward-declare dmnsn_canvas_optimizer */ diff --git a/libdimension/dimension/interior.h b/libdimension/dimension/interior.h index 76f0a32..22a9091 100644 --- a/libdimension/dimension/interior.h +++ b/libdimension/dimension/interior.h @@ -33,7 +33,7 @@ typedef struct dmnsn_interior { void *ptr; /** @internal Reference count. */ - dmnsn_refcount *refcount; + dmnsn_refcount refcount; } dmnsn_interior; /** diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index efe2323..02daaba 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -92,7 +92,7 @@ struct dmnsn_object { void *ptr; /** @internal Reference count. */ - dmnsn_refcount *refcount; + dmnsn_refcount refcount; }; /** diff --git a/libdimension/dimension/refcount.h b/libdimension/dimension/refcount.h index 9d2c304..4431cbc 100644 --- a/libdimension/dimension/refcount.h +++ b/libdimension/dimension/refcount.h @@ -23,36 +23,21 @@ * Generic reference count implementation. */ -/** - * Increment a reference count. - * @param[in,out] object The reference-counted object to acquire. - */ -#define DMNSN_INCREF(obj) ((void)++(*(obj)->refcount)) - -/** - * @internal - * Decrement a reference count. - * @param[in,out] object The reference-counted object to release. - * @return Whether the object is now garbage. - */ -#define DMNSN_DECREF(obj) (*(obj)->refcount == 0 || --(*(obj)->refcount) == 0) - /** * Reference counter. */ typedef unsigned int dmnsn_refcount; /** - * @internal - * Create a reference count. - * @return A new reference counter, initialized to zero (a "borrowed" reference, - * which will be garbage-collected the first time it is deleted). + * Increment a reference count. + * @param[in,out] object The reference-counted object to acquire. */ -dmnsn_refcount *dmnsn_new_refcount(void); +#define DMNSN_INCREF(obj) ((void)++(obj)->refcount) /** * @internal - * Delete a reference count. Raises an error if the reference count wasn't - * zero. + * Decrement a reference count. + * @param[in,out] object The reference-counted object to release. + * @return Whether the object is now garbage. */ -void dmnsn_delete_refcount(dmnsn_refcount *refcount); +#define DMNSN_DECREF(obj) ((obj)->refcount == 0 || --(obj)->refcount == 0) diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h index 8051c02..7edcabc 100644 --- a/libdimension/dimension/texture.h +++ b/libdimension/dimension/texture.h @@ -31,8 +31,8 @@ typedef struct { dmnsn_matrix trans; /**< Transformation matrix. */ dmnsn_matrix trans_inv; /**< The inverse of the transformation matrix. */ - dmnsn_refcount *refcount; /**< @internal Reference count. */ - bool should_init; /**< @internal Whether to initialize the texture. */ + dmnsn_refcount refcount; /**< @internal Reference count. */ + bool should_init; /**< @internal Whether to initialize the texture. */ } dmnsn_texture; /** -- cgit v1.2.3