- struct traverse_info tinfo;
- struct hash_info h;
- struct tdb_used_record rec;
-
- tinfo.prev = find_and_lock(tdb, key, F_RDLCK, &h, &rec, &tinfo);
- if (unlikely(tinfo.prev == TDB_OFF_ERR))
- return tdb_null;
- tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range, F_RDLCK);
-
- switch (next_in_hash(tdb, F_RDLCK, &tinfo, &key, NULL)) {
- case 1:
- return key;
- case 0:
- tdb->ecode = TDB_SUCCESS;
- /* Fall thru... */
- default:
- return tdb_null;
- }
-}
+ 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_off_t lockstart, locksize;
+ unsigned int group, gbits;
+
+ gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
+ group = bits(h, 64 - gbits, gbits);
+
+ lockstart = hlock_range(group, &locksize);
+
+ tdb_trace_1rec(tdb, "tdb_chainunlock", key);
+ return tdb_unlock_hashes(tdb, lockstart, locksize, F_WRLCK);
+}