- return _tdb_lock(tdb, list, ltype, TDB_LOCK_NOWAIT);
+ /* a allrecord lock allows us to avoid per chain locks */
+ if (tdb->allrecord_lock.count &&
+ (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) {
+ return 0;
+ }
+
+ if (tdb->allrecord_lock.count) {
+ tdb->ecode = TDB_ERR_LOCK;
+ return -1;
+ }
+
+ return tdb_nest_lock(tdb, lock_offset(list), ltype, TDB_LOCK_NOWAIT);