summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/refcount.c
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2016-11-29 16:51:58 +0100
committerNiels de Vos <ndevos@redhat.com>2016-12-11 00:47:05 -0800
commit2f0e9ab1ef271132b8b7b1af25e23ac7bb0720c8 (patch)
tree050235f872a64ca0f9f5c7153cea319266edd61a /libglusterfs/src/refcount.c
parent2d012c4558046afd6adb3992ff88f937c5f835e4 (diff)
refcount: return pointer to the structure instead of a counter
There are no real users of the counter. It was thought of a handy tool to track and debug refcounting, but it is not used at all. Some parts of the code would benefit from a pointer getting returned instead. BUG: 1399780 Change-Id: I97e52c48420fed61be942ea27ff4849b803eed12 Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: http://review.gluster.org/15971 Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Xavier Hernandez <xhernandez@datalab.es> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'libglusterfs/src/refcount.c')
-rw-r--r--libglusterfs/src/refcount.c21
1 files changed, 7 insertions, 14 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 */