diff options
author | Krishnan Parthasarathi <kparthas@redhat.com> | 2013-04-15 15:41:21 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2013-04-17 01:53:20 -0700 |
commit | 563b608126e812482a25464df7c70079fb0ba2c0 (patch) | |
tree | 0f85cd9accc5cb885ea587f5b75bb72340b536c7 /libglusterfs/src/globals.c | |
parent | 4c8bb7c4b0471fe2a5095639f0fd44f50ba28dc8 (diff) |
synctask: introduce synclocks for co-operative locking
This patch introduces a synclocks - co-operative locks for synctasks.
Synctasks yield themselves when a lock cannot be acquired at the time
of the lock call, and the unlocker will wake the yielded locker at
the time of unlock.
The implementation is safe in a multi-threaded syncenv framework.
It is also safe for sharing the lock between non-synctasks. i.e, the
same lock can be used for synchronization between a synctask and
a regular thread. In such a situation, waiting synctasks will yield
themselves while non-synctasks will sleep on a cond variable. The
unlocker (which could be either a synctask or a regular thread) will
wake up any type of lock waiter (synctask or regular).
Usage:
Declaration and Initialization
------------------------------
synclock_t lock;
ret = synclock_init (&lock);
if (ret) {
/* lock could not be allocated */
}
Locking and non-blocking lock attempt
-------------------------------------
ret = synclock_trylock (&lock);
if (ret && (errno == EBUSY)) {
/* lock is held by someone else */
return;
}
synclock_lock (&lock);
{
/* critical section */
}
synclock_unlock (&lock);
BUG: 763820
Change-Id: I23066f7b66b41d3d9fb2311fdaca333e98dd7442
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Original-author: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/4830
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs/src/globals.c')
0 files changed, 0 insertions, 0 deletions