]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb/tdb.c
Use -O not -O3: reduces ccan/tdb test time from 24 to 18 seconds.
[ccan] / ccan / tdb / tdb.c
index 3e663345e60c5f9ebc14e1d41813f39a7d3bc4bd..d43418033e7fcc32ea5648b4ac5c2672568e26b8 100644 (file)
@@ -59,13 +59,14 @@ static void tdb_increment_seqnum(struct tdb_context *tdb)
                return;
        }
 
-       if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) {
+       if (tdb_brlock(tdb, F_WRLCK, TDB_SEQNUM_OFS, 1,
+                      TDB_LOCK_WAIT|TDB_LOCK_PROBE) != 0) {
                return;
        }
 
        tdb_increment_seqnum_nonblock(tdb);
 
-       tdb_brlock(tdb, TDB_SEQNUM_OFS, F_UNLCK, F_SETLKW, 1, 1);
+       tdb_brunlock(tdb, F_WRLCK, TDB_SEQNUM_OFS, 1);
 }
 
 static int tdb_key_compare(TDB_DATA key, TDB_DATA data, void *private_data)
@@ -98,12 +99,14 @@ static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
                }
                /* detect tight infinite loop */
                if (rec_ptr == r->next) {
+                       tdb->ecode = TDB_ERR_CORRUPT;
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_find: loop detected.\n"));
-                       return TDB_ERRCODE(TDB_ERR_CORRUPT, 0);
+                       return 0;
                }
                rec_ptr = r->next;
        }
-       return TDB_ERRCODE(TDB_ERR_NOEXIST, 0);
+       tdb->ecode = TDB_ERR_NOEXIST;
+       return 0;
 }
 
 /* As tdb_find, but if you succeed, keep the lock */
@@ -158,7 +161,7 @@ static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
  * then the TDB_DATA will have zero length but
  * a non-zero pointer
  */
-static TDB_DATA do_tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
+static TDB_DATA _tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
 {
        tdb_off_t rec_ptr;
        struct list_struct rec;
@@ -179,7 +182,7 @@ static TDB_DATA do_tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
 
 TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
 {
-       TDB_DATA ret = do_tdb_fetch(tdb, key);
+       TDB_DATA ret = _tdb_fetch(tdb, key);
 
        tdb_trace_1rec_retrec(tdb, "tdb_fetch", key, ret);
        return ret;
@@ -217,7 +220,8 @@ int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
        if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) {
                tdb_trace_1rec_ret(tdb, "tdb_parse_record", key,
                                   -TDB_ERR_NOEXIST);
-               return TDB_ERRCODE(TDB_ERR_NOEXIST, 0);
+               tdb->ecode = TDB_ERR_NOEXIST;
+               return 0;
        }
        tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, 0);
 
@@ -443,8 +447,8 @@ static tdb_off_t tdb_find_dead(struct tdb_context *tdb, uint32_t hash,
        return 0;
 }
 
-static int _tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf,
-                     int flag, uint32_t hash)
+static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
+                     TDB_DATA dbuf, int flag, uint32_t hash)
 {
        struct list_struct rec;
        tdb_off_t rec_ptr;
@@ -610,7 +614,7 @@ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
        if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
                return -1;
 
-       dbuf = do_tdb_fetch(tdb, key);
+       dbuf = _tdb_fetch(tdb, key);
 
        if (dbuf.dptr == NULL) {
                dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize);