summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/fd-lk.c
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/fd-lk.c')
-rw-r--r--libglusterfs/src/fd-lk.c59
1 files changed, 7 insertions, 52 deletions
diff --git a/libglusterfs/src/fd-lk.c b/libglusterfs/src/fd-lk.c
index 358cf3b616a..e516f64bff6 100644
--- a/libglusterfs/src/fd-lk.c
+++ b/libglusterfs/src/fd-lk.c
@@ -65,15 +65,11 @@ fd_lk_ctx_unref (fd_lk_ctx_t *lk_ctx)
GF_VALIDATE_OR_GOTO ("fd-lk", lk_ctx, err);
- LOCK (&lk_ctx->lock);
- {
- ref = --lk_ctx->ref;
- if (ref < 0)
- GF_ASSERT (!ref);
- if (ref == 0)
- _fd_lk_destroy_lock_list (lk_ctx);
- }
- UNLOCK (&lk_ctx->lock);
+ ref = GF_ATOMIC_DEC (lk_ctx->ref);
+ if (ref < 0)
+ GF_ASSERT (!ref);
+ if (ref == 0)
+ _fd_lk_destroy_lock_list (lk_ctx);
if (ref == 0) {
LOCK_DESTROY (&lk_ctx->lock);
@@ -86,58 +82,17 @@ err:
}
fd_lk_ctx_t *
-_fd_lk_ctx_ref (fd_lk_ctx_t *lk_ctx)
-{
- if (!lk_ctx) {
- gf_msg_callingfn ("fd-lk", GF_LOG_WARNING, EINVAL,
- LG_MSG_INVALID_ARG, "invalid argument");
- return NULL;
- }
-
- ++lk_ctx->ref;
-
- return lk_ctx;
-}
-
-fd_lk_ctx_t *
fd_lk_ctx_ref (fd_lk_ctx_t *lk_ctx)
{
- fd_lk_ctx_t *new_lk_ctx = NULL;
-
if (!lk_ctx) {
gf_msg_callingfn ("fd-lk", GF_LOG_WARNING, EINVAL,
LG_MSG_INVALID_ARG, "invalid argument");
return NULL;
}
- LOCK (&lk_ctx->lock);
- {
- new_lk_ctx = _fd_lk_ctx_ref (lk_ctx);
- }
- UNLOCK (&lk_ctx->lock);
-
- return new_lk_ctx;
-}
-
-fd_lk_ctx_t *
-fd_lk_ctx_try_ref (fd_lk_ctx_t *lk_ctx)
-{
- int ret = -1;
- fd_lk_ctx_t *new_lk_ctx = NULL;
-
- if (!lk_ctx) {
- goto out;
- }
-
- ret = TRY_LOCK (&lk_ctx->lock);
- if (ret)
- goto out;
+ GF_ATOMIC_INC (lk_ctx->ref);
- new_lk_ctx = _fd_lk_ctx_ref (lk_ctx);
- UNLOCK (&lk_ctx->lock);
-
-out:
- return new_lk_ctx;
+ return lk_ctx;
}
fd_lk_ctx_t *