]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/conf-journal.c
Redblack: Added search_up
[libucw.git] / ucw / conf-journal.c
index 75af51ad69d3021743cf796945901c9663a8e818..7d3ccdce1e7f83347ebe73d8db4de0681cdb3dfa 100644 (file)
@@ -24,15 +24,23 @@ struct old_pools {
 struct cf_journal_item {
   struct cf_journal_item *prev;
   byte *ptr;
-  uns len;
+  uint len;
   byte copy[0];
 };
 
 void
-cf_journal_block(void *ptr, uns len)
+cf_set_journalling(int enable)
 {
   struct cf_context *cc = cf_get_context();
-  if (!cc->need_journal)
+  ASSERT(!cc->journal);
+  cc->enable_journal = enable;
+}
+
+void
+cf_journal_block(void *ptr, uint len)
+{
+  struct cf_context *cc = cf_get_context();
+  if (!cc->enable_journal)
     return;
   struct cf_journal_item *ji = cf_malloc(sizeof(struct cf_journal_item) + len);
   ji->prev = cc->journal;
@@ -52,7 +60,7 @@ cf_journal_swap(void)
   {
     prev = curr->prev;
     curr->prev = next;
-    for (uns i=0; i<curr->len; i++)
+    for (uint i=0; i<curr->len; i++)
     {
       byte x = curr->copy[i];
       curr->copy[i] = curr->ptr[i];
@@ -63,7 +71,7 @@ cf_journal_swap(void)
 }
 
 struct cf_journal_item *
-cf_journal_new_transaction(uns new_pool)
+cf_journal_new_transaction(uint new_pool)
 {
   struct cf_context *cc = cf_get_context();
   if (new_pool)
@@ -74,7 +82,7 @@ cf_journal_new_transaction(uns new_pool)
 }
 
 void
-cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj)
+cf_journal_commit_transaction(uint new_pool, struct cf_journal_item *oldj)
 {
   struct cf_context *cc = cf_get_context();
   if (new_pool)
@@ -94,11 +102,11 @@ cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj)
 }
 
 void
-cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj)
+cf_journal_rollback_transaction(uint new_pool, struct cf_journal_item *oldj)
 {
   struct cf_context *cc = cf_get_context();
-  if (!cc->need_journal)
-    die("Cannot rollback the configuration, because the journal is disabled.");
+  if (!cc->enable_journal)
+    return;
   cf_journal_swap();
   cc->journal = oldj;
   if (new_pool)
@@ -118,5 +126,3 @@ cf_journal_delete(void)
     mp_delete(p->pool);
   }
 }
-
-/* TODO: more space efficient journal */