*/
int tdb_transaction_lock(struct tdb_context *tdb, int ltype)
{
- if (tdb->have_transaction_lock || tdb->global_lock.count) {
+ if (tdb->global_lock.count) {
+ return 0;
+ }
+ if (tdb->have_transaction_lock) {
+ tdb->have_transaction_lock++;
return 0;
}
if (tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, ltype,
tdb->ecode = TDB_ERR_LOCK;
return -1;
}
- tdb->have_transaction_lock = 1;
+ tdb->have_transaction_lock++;
return 0;
}
*/
int tdb_transaction_unlock(struct tdb_context *tdb)
{
- int ret;
- if (!tdb->have_transaction_lock) {
+ if (tdb->global_lock.count) {
return 0;
}
- ret = tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1);
- if (ret == 0) {
- tdb->have_transaction_lock = 0;
+ if (--tdb->have_transaction_lock) {
+ return 0;
}
- return ret;
+ return tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1);
}
int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
{
- tdb_trace_1rec(tdb, "tdb_chainlock", key);
+ tdb_trace_1rec(tdb, "tdb_chainunlock", key);
return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
}