]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb.c
tdb2: use counters to decide when to coalesce records.
[ccan] / ccan / tdb2 / tdb.c
index 18cf2e93a598ea7c3f742bcb3e445a5985686d55..f11701d9ea9c686cfc2b0beefbea069eb3602542 100644 (file)
@@ -41,7 +41,8 @@ static enum TDB_ERROR replace_data(struct tdb_context *tdb,
                tdb->stats.frees++;
                ecode = add_free_record(tdb, old_off,
                                        sizeof(struct tdb_used_record)
-                                       + key.dsize + old_room);
+                                       + key.dsize + old_room,
+                                       TDB_LOCK_WAIT, true);
                if (ecode == TDB_SUCCESS)
                        ecode = replace_in_hash(tdb, h, new_off);
        } else {
@@ -290,7 +291,8 @@ enum TDB_ERROR tdb_delete(struct tdb_context *tdb, struct tdb_data key)
                                sizeof(struct tdb_used_record)
                                + rec_key_length(&rec)
                                + rec_data_length(&rec)
-                               + rec_extra_padding(&rec));
+                               + rec_extra_padding(&rec),
+                               TDB_LOCK_WAIT, true);
 
        if (tdb->flags & TDB_SEQNUM)
                tdb_inc_seqnum(tdb);
@@ -327,6 +329,9 @@ void tdb_add_flag(struct tdb_context *tdb, unsigned flag)
        case TDB_SEQNUM:
                tdb->flags |= TDB_SEQNUM;
                break;
+       case TDB_ALLOW_NESTING:
+               tdb->flags |= TDB_ALLOW_NESTING;
+               break;
        default:
                tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
                                             TDB_LOG_USE_ERROR,
@@ -357,6 +362,9 @@ void tdb_remove_flag(struct tdb_context *tdb, unsigned flag)
        case TDB_SEQNUM:
                tdb->flags &= ~TDB_SEQNUM;
                break;
+       case TDB_ALLOW_NESTING:
+               tdb->flags &= ~TDB_ALLOW_NESTING;
+               break;
        default:
                tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
                                             TDB_LOG_USE_ERROR,