X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Flock.c;h=326d38e70713443f86aa45e821b20e883d3df44a;hp=bcd560d792231ff2defce3430cf6feb7117fa243;hb=4f14d7bbd5afcda4fd0f1f70e8c9aae2a929c4d4;hpb=ac0e87d7ecf790c187ce3c5d837b971fdd016b57 diff --git a/ccan/tdb/lock.c b/ccan/tdb/lock.c index bcd560d7..326d38e7 100644 --- a/ccan/tdb/lock.c +++ b/ccan/tdb/lock.c @@ -304,17 +304,18 @@ int tdb_transaction_lock(struct tdb_context *tdb, int ltype) if (tdb->global_lock.count) { return 0; } - if (tdb->have_transaction_lock) { - tdb->have_transaction_lock++; + if (tdb->transaction_lock_count > 0) { + tdb->transaction_lock_count++; return 0; } + if (tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, ltype, F_SETLKW, 0, 1) == -1) { TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_lock: failed to get transaction lock\n")); tdb->ecode = TDB_ERR_LOCK; return -1; } - tdb->have_transaction_lock++; + tdb->transaction_lock_count++; return 0; } @@ -323,13 +324,19 @@ int tdb_transaction_lock(struct tdb_context *tdb, int ltype) */ int tdb_transaction_unlock(struct tdb_context *tdb) { + int ret; if (tdb->global_lock.count) { return 0; } - if (--tdb->have_transaction_lock) { + if (tdb->transaction_lock_count > 1) { + tdb->transaction_lock_count--; return 0; } - return tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); + ret = tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); + if (ret == 0) { + tdb->transaction_lock_count = 0; + } + return ret; }