summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/refcount.c21
-rw-r--r--libglusterfs/src/refcount.h10
2 files changed, 12 insertions, 19 deletions
diff --git a/libglusterfs/src/refcount.c b/libglusterfs/src/refcount.c
index 96edc10982a..9d33b733cf0 100644
--- a/libglusterfs/src/refcount.c
+++ b/libglusterfs/src/refcount.c
@@ -13,7 +13,7 @@
#ifndef REFCOUNT_NEEDS_LOCK
-unsigned int
+void *
_gf_ref_get (gf_ref_t *ref)
{
unsigned int cnt = __sync_fetch_and_add (&ref->cnt, 1);
@@ -27,10 +27,10 @@ _gf_ref_get (gf_ref_t *ref)
*/
GF_ASSERT (cnt != 0);
- return cnt;
+ return cnt ? ref->data : NULL;
}
-unsigned int
+void
_gf_ref_put (gf_ref_t *ref)
{
unsigned int cnt = __sync_fetch_and_sub (&ref->cnt, 1);
@@ -43,18 +43,13 @@ _gf_ref_put (gf_ref_t *ref)
*/
GF_ASSERT (cnt != 0);
- if (cnt == 1 && ref->release) {
+ if (cnt == 1 && ref->release)
ref->release (ref->data);
- /* set return value to 0 to inform the caller correctly */
- cnt = 0;
- }
-
- return cnt;
}
#else
-unsigned int
+void *
_gf_ref_get (gf_ref_t *ref)
{
unsigned int cnt = 0;
@@ -69,10 +64,10 @@ _gf_ref_get (gf_ref_t *ref)
}
UNLOCK (&ref->lk);
- return cnt;
+ return cnt ? ref->data : NULL;
}
-unsigned int
+void
_gf_ref_put (gf_ref_t *ref)
{
unsigned int cnt = 0;
@@ -91,8 +86,6 @@ _gf_ref_put (gf_ref_t *ref)
if (release && ref->release)
ref->release (ref->data);
-
- return cnt;
}
#endif /* REFCOUNT_NEEDS_LOCK */
diff --git a/libglusterfs/src/refcount.h b/libglusterfs/src/refcount.h
index e850e6389ae..db9432acbbc 100644
--- a/libglusterfs/src/refcount.h
+++ b/libglusterfs/src/refcount.h
@@ -42,7 +42,7 @@ typedef struct _gf_ref_t gf_ref_t;
*
* @return: greater then 0 when a reference was taken, 0 when not
*/
-unsigned int
+void *
_gf_ref_get (gf_ref_t *ref);
/* _gf_ref_put -- decrease the refcount
@@ -50,7 +50,7 @@ _gf_ref_get (gf_ref_t *ref);
* @return: greater then 0 when there are still references, 0 when cleanup
* should be done, gf_ref_release_t is called on cleanup
*/
-unsigned int
+void
_gf_ref_put (gf_ref_t *ref);
/* _gf_ref_init -- initalize an embedded refcount object
@@ -84,20 +84,20 @@ _gf_ref_init (gf_ref_t *ref, gf_ref_release_t release, void *data);
*
* Sets the refcount to 1.
*/
-#define GF_REF_INIT(p, d) _gf_ref_init (&p->_ref, d, p)
+#define GF_REF_INIT(p, d) _gf_ref_init (&(p)->_ref, d, p)
/* GF_REF_GET -- increase the refcount of a GF_REF_DECL structure
*
* @return: greater then 0 when a reference was taken, 0 when not
*/
-#define GF_REF_GET(p) _gf_ref_get (&p->_ref)
+#define GF_REF_GET(p) _gf_ref_get (&(p)->_ref)
/* GF_REF_PUT -- decrease the refcount of a GF_REF_DECL structure
*
* @return: greater then 0 when there are still references, 0 when cleanup
* should be done, gf_ref_release_t is called on cleanup
*/
-#define GF_REF_PUT(p) _gf_ref_put (&p->_ref)
+#define GF_REF_PUT(p) _gf_ref_put (&(p)->_ref)
#endif /* _REFCOUNT_H */