diff options
author | Vikas Gorur <vikas@gluster.com> | 2009-04-07 03:27:24 -0700 |
---|---|---|
committer | Anand V. Avati <avati@amp.gluster.com> | 2009-04-07 16:01:42 +0530 |
commit | d71e72248096d12ce2a8ca7ccb36ef97ae486583 (patch) | |
tree | 22e950f26c76f9fa38fbc746e7167799b61521b6 /libglusterfs/src | |
parent | 27996c714f7fd6a7686f2d4a3552efbc1e54c2c7 (diff) |
Add lock-less versions of fd_ctx_*
Added __fd_ctx_get
__fd_ctx_set
__fd_ctx_del which do not hold any lock.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/fd.c | 147 | ||||
-rw-r--r-- | libglusterfs/src/fd.h | 9 |
2 files changed, 104 insertions, 52 deletions
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index deb3c800145..fc78acc7caa 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -586,7 +586,7 @@ fd_list_empty (inode_t *inode) } int -fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) +__fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) { int index = 0; int ret = 0; @@ -595,37 +595,52 @@ fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) if (!fd || !xlator) return -1; - LOCK (&fd->lock); - { - for (index = 0; index < xlator->ctx->xl_count; index++) { - if (!fd->_ctx[index].key) { - if (set_idx == -1) - set_idx = index; - /* dont break, to check if key already exists - further on */ - } - if (fd->_ctx[index].key == (uint64_t)(long) xlator) { + for (index = 0; index < xlator->ctx->xl_count; index++) { + if (!fd->_ctx[index].key) { + if (set_idx == -1) set_idx = index; - break; - } + /* dont break, to check if key already exists + further on */ } - - if (set_idx == -1) { - ret = -1; - goto unlock; + if (fd->_ctx[index].key == (uint64_t)(long) xlator) { + set_idx = index; + break; } + } + + if (set_idx == -1) { + ret = -1; + goto out; + } + + fd->_ctx[set_idx].key = (uint64_t)(long) xlator; + fd->_ctx[set_idx].value = value; + +out: + return ret; +} + + +int +fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) +{ + int ret = 0; - fd->_ctx[set_idx].key = (uint64_t)(long) xlator; - fd->_ctx[set_idx].value = value; + if (!fd || !xlator) + return -1; + + LOCK (&fd->lock); + { + ret = __fd_ctx_set (fd, xlator, value); } -unlock: UNLOCK (&fd->lock); - return ret; + return ret; } + int -fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) +__fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) { int index = 0; int ret = 0; @@ -633,24 +648,68 @@ fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) if (!fd || !xlator) return -1; + for (index = 0; index < xlator->ctx->xl_count; index++) { + if (fd->_ctx[index].key == (uint64_t)(long)xlator) + break; + } + + if (index == xlator->ctx->xl_count) { + ret = -1; + goto out; + } + + if (value) + *value = fd->_ctx[index].value; + +out: + return ret; +} + + +int +fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) +{ + int ret = 0; + + if (!fd || !xlator) + return -1; + LOCK (&fd->lock); { - for (index = 0; index < xlator->ctx->xl_count; index++) { - if (fd->_ctx[index].key == (uint64_t)(long)xlator) - break; - } + ret = __fd_ctx_get (fd, xlator, value); + } + UNLOCK (&fd->lock); - if (index == xlator->ctx->xl_count) { - ret = -1; - goto unlock; - } + return ret; +} + + +int +__fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) +{ + int index = 0; + int ret = 0; - if (value) - *value = fd->_ctx[index].value; + if (!fd || !xlator) + return -1; + + for (index = 0; index < xlator->ctx->xl_count; index++) { + if (fd->_ctx[index].key == (uint64_t)(long)xlator) + break; } -unlock: - UNLOCK (&fd->lock); + + if (index == xlator->ctx->xl_count) { + ret = -1; + goto out; + } + + if (value) + *value = fd->_ctx[index].value; + + fd->_ctx[index].key = 0; + fd->_ctx[index].value = 0; +out: return ret; } @@ -658,7 +717,6 @@ unlock: int fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) { - int index = 0; int ret = 0; if (!fd || !xlator) @@ -666,24 +724,9 @@ fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) LOCK (&fd->lock); { - for (index = 0; index < xlator->ctx->xl_count; index++) { - if (fd->_ctx[index].key == (uint64_t)(long)xlator) - break; - } - - if (index == xlator->ctx->xl_count) { - ret = -1; - goto unlock; - } - - if (value) - *value = fd->_ctx[index].value; - - fd->_ctx[index].key = 0; - fd->_ctx[index].value = 0; + ret = __fd_ctx_del (fd, xlator, value); } -unlock: UNLOCK (&fd->lock); - return ret; + return ret; } diff --git a/libglusterfs/src/fd.h b/libglusterfs/src/fd.h index 2916a44812e..d3c9afde3f9 100644 --- a/libglusterfs/src/fd.h +++ b/libglusterfs/src/fd.h @@ -110,4 +110,13 @@ fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value); int fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value); +int +__fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value); + +int +__fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value); + +int +__fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value); + #endif /* _FD_H */ |