X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fhash.c;h=5eee41a88df0dcaf820ab00cc3cb01df87c4cdf4;hp=56c5086e742552480a23e81a8e2a7baafe583d73;hb=3352e4e947777d4a90a2dd4f3037e1e494231b25;hpb=c8f6f8c2dea76042f74c02eff048847e62adcca6 diff --git a/ccan/tdb2/hash.c b/ccan/tdb2/hash.c index 56c5086e..5eee41a8 100644 --- a/ccan/tdb2/hash.c +++ b/ccan/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);