]> git.tdb.fi Git - r2c2.git/commitdiff
Remove a queued block reservation if the block is released
authorMikko Rasa <tdb@tdb.fi>
Tue, 7 Apr 2015 10:56:47 +0000 (13:56 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 7 Apr 2015 11:14:13 +0000 (14:14 +0300)
This can happen in some situations with instantly changing turnouts.

source/libr2c2/layout.cpp
source/libr2c2/layout.h

index 0aa5333d36238779b8e49bc02fdf1ae67702b363..bc149dff1f904a014a0518052dacb36818a62fe6 100644 (file)
@@ -565,7 +565,19 @@ void Layout::sensor_state_changed(Sensor &sensor, Sensor::State state)
 void Layout::block_reserved(Block &block, Train *train)
 {
        if(emitting_block_reserved)
+       {
+               if(!train)
+               {
+                       for(deque<BlockReservation>::iterator i=block_reserve_queue.end(); i!=block_reserve_queue.begin(); )
+                               if((--i)->block==&block)
+                               {
+                                       block_reserve_queue.erase(i);
+                                       return;
+                               }
+               }
+
                block_reserve_queue.push_back(BlockReservation(block, train));
+       }
        else
        {
                SetFlag setf(emitting_block_reserved);
@@ -574,7 +586,7 @@ void Layout::block_reserved(Block &block, Train *train)
                {
                        BlockReservation br = block_reserve_queue.front();
                        block_reserve_queue.pop_front();
-                       signal_block_reserved.emit(br.block, br.train);
+                       signal_block_reserved.emit(*br.block, br.train);
                }
        }
 }
@@ -634,7 +646,7 @@ void Layout::Storage<B>::del()
 
 
 Layout::BlockReservation::BlockReservation(Block &b, Train *t):
-       block(b),
+       block(&b),
        train(t)
 { }
 
index 4bccb20c9b26b34b436c3dc12dddeba47bc20b68..e06d4fb04f50d8ccb1e581a363e2dce18d13d91a 100644 (file)
@@ -72,7 +72,7 @@ private:
 
        struct BlockReservation
        {
-               Block &block;
+               Block *block;
                Train *train;
 
                BlockReservation(Block &, Train *);