]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb/lock.c
Speed up tracing by factor of 4-6, by writing less stupid code.
[ccan] / ccan / tdb / lock.c
index 473a9bf52c3b0b855d892cf1c1b611dede6c3547..bcd560d792231ff2defce3430cf6feb7117fa243 100644 (file)
@@ -301,7 +301,11 @@ 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) {
+       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, 
@@ -310,7 +314,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 +323,13 @@ 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->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);
 }
 
 
@@ -504,7 +506,7 @@ int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key)
 
 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);
 }