X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=ccan%2Ftdb2%2Flock.c;h=14a7b5e5c65904749bd78647bb7558b12489fb15;hb=ee6f11b307599200a574208372bc962eff81a9b1;hp=c8dbf8267a8f9dab5fc92c9a3e7e810e6d8943d1;hpb=2088fa3cd72332f5517edeb9267e381fdf35db01;p=ccan diff --git a/ccan/tdb2/lock.c b/ccan/tdb2/lock.c index c8dbf826..14a7b5e5 100644 --- a/ccan/tdb2/lock.c +++ b/ccan/tdb2/lock.c @@ -485,8 +485,8 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype, /* Lock all the hash buckets. */ again: hash_size = (1ULL << tdb->header.v.hash_bits); - if (tdb_lock_gradual(tdb, ltype, TDB_HASH_LOCK_START, - 1ULL << tdb->header.v.hash_bits, flags)) { + if (tdb_lock_gradual(tdb, ltype, flags, TDB_HASH_LOCK_START, + hash_size)) { if (!(flags & TDB_LOCK_PROBE)) { tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv, "tdb_lockall hashes failed (%s)\n", @@ -719,7 +719,8 @@ void tdb_unlock_free_list(struct tdb_context *tdb, tdb_off_t flist) + flist, F_WRLCK); } -#if 0 +/* Even if the entry isn't in this hash bucket, you'd have to lock this + * bucket to find it. */ static int chainlock(struct tdb_context *tdb, const TDB_DATA *key, int ltype, enum tdb_lock_flags waitflag, const char *func) @@ -739,6 +740,14 @@ int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key) return chainlock(tdb, &key, F_WRLCK, TDB_LOCK_WAIT, "tdb_chainlock"); } +int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key) +{ + uint64_t h = tdb_hash(tdb, key.dptr, key.dsize); + tdb_trace_1rec(tdb, "tdb_chainunlock", key); + return tdb_unlock_list(tdb, h, F_WRLCK); +} + +#if 0 /* 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 */ @@ -748,14 +757,6 @@ int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key) "tdb_chainlock_nonblock"); } -int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key) -{ - uint64_t h = tdb_hash(tdb, key.dptr, key.dsize); - tdb_trace_1rec(tdb, "tdb_chainunlock", key); - return tdb_unlock_list(tdb, h & ((1ULL << tdb->header.v.hash_bits)-1), - F_WRLCK); -} - int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key) { return chainlock(tdb, &key, F_RDLCK, TDB_LOCK_WAIT,