]> git.mdlowis.com Git - projs/libcds.git/commitdiff
Added function for getting the number of references to an object
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 1 Aug 2014 02:21:34 +0000 (22:21 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 1 Aug 2014 02:21:34 +0000 (22:21 -0400)
source/mem/mem.c
source/mem/mem.h

index 1977a7a1d60091038b2ada18153a248d4d72dd36..c2eb7e658838d880b09784900837b596c0f32702 100644 (file)
@@ -38,6 +38,12 @@ void mem_release(void* p_obj)
     }
 }
 
+int mem_num_references(void* p_obj)
+{
+    obj_t* p_hdr = (((obj_t*)p_obj)-1);
+    return p_hdr->refcount;
+}
+
 void mem_autorelease(void* p_obj)
 {
     (void)p_obj;
index fae9c32c1b553718d5640d7e8a102ce91d9615b5..80534ab0f9ecf9aaacd292a4ce44509517ca12b9 100644 (file)
@@ -28,6 +28,15 @@ typedef void (*destructor_t)(void* p_val);
  */
 void* mem_allocate(size_t size, destructor_t p_destruct_fn);
 
+/**
+ * @brief Returns the reference count for the given object.
+ *
+ * @param p_obj The object whose reference count should be returned.
+ *
+ * @return Number of references.
+ */
+int mem_num_references(void* p_obj);
+
 /**
  * @brief Increments the reference count for the given object.
  *