From 5d782dbf80597cc2c99fb1c7f87b9ea1b537b684 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 23 Jul 2013 16:41:35 +0300 Subject: [PATCH] Avoid a temporary inconsistent state while reserving the first block --- source/libr2c2/blockallocator.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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; } -- 2.43.0