summaryrefslogtreecommitdiff
path: root/lib/tdb2/hash.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:56:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:56:13 +0930
commit9140fca812063be69842a6c64030e32c65c9dff1 (patch)
tree73b9e12160be66ce7853e0e9b44ad44c17269b65 /lib/tdb2/hash.c
parent30294c7b91456dd49b89a9b26eb0b1066087815c (diff)
downloadsamba-9140fca812063be69842a6c64030e32c65c9dff1.tar.gz
samba-9140fca812063be69842a6c64030e32c65c9dff1.tar.bz2
samba-9140fca812063be69842a6c64030e32c65c9dff1.zip
tdb2: unify tdb1_chainlock et al. into tdb_chainlock
Switch on the TDB_VERSION1 flag. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit ceb2f3eacbad917ee990afbc3dd800bfb0607887)
Diffstat (limited to 'lib/tdb2/hash.c')
-rw-r--r--lib/tdb2/hash.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/tdb2/hash.c b/lib/tdb2/hash.c
index 56c5086e74..5eee41a88d 100644
--- a/lib/tdb2/hash.c
+++ b/lib/tdb2/hash.c
@@ -852,6 +852,11 @@ static enum TDB_ERROR chainlock(struct tdb_context *tdb, const TDB_DATA *key,
contention - it cannot guarantee how many records will be locked */
enum TDB_ERROR tdb_chainlock(struct tdb_context *tdb, TDB_DATA key)
{
+ if (tdb->flags & TDB_VERSION1) {
+ if (tdb1_chainlock(tdb, key) == -1)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
return tdb->last_error = chainlock(tdb, &key, F_WRLCK, TDB_LOCK_WAIT,
"tdb_chainlock");
}
@@ -862,6 +867,11 @@ void tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
tdb_off_t lockstart, locksize;
unsigned int group, gbits;
+ if (tdb->flags & TDB_VERSION1) {
+ tdb1_chainunlock(tdb, key);
+ return;
+ }
+
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
group = bits_from(h, 64 - gbits, gbits);
@@ -873,6 +883,11 @@ void tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
enum TDB_ERROR tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key)
{
+ if (tdb->flags & TDB_VERSION1) {
+ if (tdb1_chainlock_read(tdb, key) == -1)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
return tdb->last_error = chainlock(tdb, &key, F_RDLCK, TDB_LOCK_WAIT,
"tdb_chainlock_read");
}
@@ -883,6 +898,10 @@ void tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key)
tdb_off_t lockstart, locksize;
unsigned int group, gbits;
+ if (tdb->flags & TDB_VERSION1) {
+ tdb1_chainunlock_read(tdb, key);
+ return;
+ }
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
group = bits_from(h, 64 - gbits, gbits);