cur_blocks_end(blocks.end()),
pending_block(0),
stop_at_block(0),
- reserving(false)
+ reserving(false),
+ advancing(false)
{
Layout &layout = train.get_layout();
layout.signal_block_reserved.connect(sigc::mem_fun(this, &BlockAllocator::block_reserved));
void BlockAllocator::clear()
{
- active = false;
release_blocks_begin(blocks.end());
+ active = false;
pending_block = 0;
stop_at_block = 0;
}
void BlockAllocator::release_block(const BlockList::iterator &i)
{
+ if(advancing)
+ throw logic_error("cannot release while advancing");
if(i==cur_blocks_end)
++cur_blocks_end;
if(&**i==pending_block)
if(result==1)
{
- // Move blocks up to the next sensor to our current blocks
- for(BlockList::iterator j=cur_blocks_end; j!=end; ++j)
- train.signal_advanced.emit(**j);
+ /* Advance the train to the new blocks. Update cur_blocks_end first
+ to keep things in sync. */
+ SetFlag setf(advancing);
+ BlockList::iterator i = cur_blocks_end;
cur_blocks_end = end;
+ for(; i!=end; ++i)
+ train.signal_advanced.emit(**i);
+ advancing = false;
if(active)
reserve_more();