X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Flock.c;h=6809ce37d87513986cc54fab82251004379557cb;hp=473a9bf52c3b0b855d892cf1c1b611dede6c3547;hb=010c8d465aa1e8810bd060ecf5d124ca2d990b0e;hpb=efda07f8f8bb9f07b8242a443aab91f8279476db diff --git a/ccan/tdb/lock.c b/ccan/tdb/lock.c index 473a9bf5..6809ce37 100644 --- a/ccan/tdb/lock.c +++ b/ccan/tdb/lock.c @@ -302,6 +302,7 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype) int tdb_transaction_lock(struct tdb_context *tdb, int ltype) { if (tdb->have_transaction_lock || tdb->global_lock.count) { + tdb->have_transaction_lock++; return 0; } if (tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, ltype, @@ -310,7 +311,7 @@ int tdb_transaction_lock(struct tdb_context *tdb, int ltype) tdb->ecode = TDB_ERR_LOCK; return -1; } - tdb->have_transaction_lock = 1; + tdb->have_transaction_lock++; return 0; } @@ -319,15 +320,10 @@ int tdb_transaction_lock(struct tdb_context *tdb, int ltype) */ int tdb_transaction_unlock(struct tdb_context *tdb) { - int ret; - if (!tdb->have_transaction_lock) { + if (--tdb->have_transaction_lock) { return 0; } - ret = tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); - if (ret == 0) { - tdb->have_transaction_lock = 0; - } - return ret; + return tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); }