]> git.tdb.fi Git - r2c2.git/commitdiff
Avoid a temporary inconsistent state while reserving the first block
authorMikko Rasa <tdb@tdb.fi>
Tue, 23 Jul 2013 13:41:35 +0000 (16:41 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 23 Jul 2013 13:41:35 +0000 (16:41 +0300)
source/libr2c2/blockallocator.cpp

index a054c157331c9b5e9ed074da4fc99469e2b0ee8e..3b70f5a0ef6c2647c2e6ee44758e6af591802a67 100644 (file)
@@ -257,10 +257,17 @@ bool BlockAllocator::reserve_block(const BlockIter &block)
        /* Add it to the list first to present a consistent state in block_reserved
        signal. */
        blocks.push_back(block);
+
+       bool first_reserve = (cur_blocks_end==blocks.end());
+       if(first_reserve)
+               --cur_blocks_end;
+
        try
        {
                if(!block->reserve(&train))
                {
+                       if(first_reserve)
+                               cur_blocks_end = blocks.end();
                        blocks.pop_back();
                        return false;
                }
@@ -269,6 +276,8 @@ bool BlockAllocator::reserve_block(const BlockIter &block)
        }
        catch(...)
        {
+               if(first_reserve)
+                       cur_blocks_end = blocks.end();
                blocks.pop_back();
                throw;
        }