diff options
author | Andrew Tridgell <tridge@samba.org> | 2007-04-21 07:25:40 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:51:17 -0500 |
commit | 046870c023c950377c97c58e79ec730351a3fa97 (patch) | |
tree | b9b21e414514ad173b977cd737c05138b5bd45c3 /source4/lib/tdb/common/lock.c | |
parent | 650d81b252cc669ef848448afad7e9bb79c4f20e (diff) | |
download | samba-046870c023c950377c97c58e79ec730351a3fa97.tar.gz samba-046870c023c950377c97c58e79ec730351a3fa97.tar.bz2 samba-046870c023c950377c97c58e79ec730351a3fa97.zip |
r22422: merged tdb changes from ctdb
(This used to be commit a0ff739bcab32065d9d3957eb1d93f7791f84f04)
Diffstat (limited to 'source4/lib/tdb/common/lock.c')
-rw-r--r-- | source4/lib/tdb/common/lock.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/source4/lib/tdb/common/lock.c b/source4/lib/tdb/common/lock.c index 8a964371d3..14ccbe3976 100644 --- a/source4/lib/tdb/common/lock.c +++ b/source4/lib/tdb/common/lock.c @@ -105,7 +105,7 @@ int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len) /* lock a list in the database. list -1 is the alloc list */ -int tdb_lock(struct tdb_context *tdb, int list, int ltype) +static int _tdb_lock(struct tdb_context *tdb, int list, int ltype, int op) { struct tdb_lock_type *new_lck; int i; @@ -158,10 +158,8 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype) /* Since fcntl locks don't nest, we do a lock for the first one, and simply bump the count for future ones */ - if (tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list,ltype,F_SETLKW, + if (tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list,ltype, op, 0, 1)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d " - "ltype=%d (%s)\n", list, ltype, strerror(errno))); return -1; } @@ -175,6 +173,25 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype) return 0; } +/* lock a list in the database. list -1 is the alloc list */ +int tdb_lock(struct tdb_context *tdb, int list, int ltype) +{ + int ret; + ret = _tdb_lock(tdb, list, ltype, F_SETLKW); + if (ret) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d " + "ltype=%d (%s)\n", list, ltype, strerror(errno))); + } + return ret; +} + +/* lock a list in the database. list -1 is the alloc list. non-blocking lock */ +int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype) +{ + return _tdb_lock(tdb, list, ltype, F_SETLK); +} + + /* unlock the database: returns void because it's too late for errors. */ /* changed to return int it may be interesting to know there has been an error --simo */ @@ -351,6 +368,14 @@ int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key) return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); } +/* lock/unlock one hash chain, non-blocking. This is meant to be used + to reduce contention - it cannot guarantee how many records will be + locked */ +int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_lock_nonblock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); +} + int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key) { return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); |