From: Mikko Rasa Date: Tue, 23 Jul 2013 13:41:35 +0000 (+0300) Subject: Avoid a temporary inconsistent state while reserving the first block X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5d782dbf80597cc2c99fb1c7f87b9ea1b537b684;p=r2c2.git Avoid a temporary inconsistent state while reserving the first block --- diff --git a/source/libr2c2/blockallocator.cpp b/source/libr2c2/blockallocator.cpp index a054c15..3b70f5a 100644 --- a/source/libr2c2/blockallocator.cpp +++ b/source/libr2c2/blockallocator.cpp @@ -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; }