From ece91e92af821bd6b468bd1134302efb7c28f019 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 6 Feb 2015 16:37:46 +0200 Subject: [PATCH] Make sure Block::signal_reserved is emitted consistently Sigc++ apparently takes arguments as references, so if someone reached to a signal with null train by reserving the block again, any remaining slots of the release emission would also get the new train pointer. This caused the routing system to malfunction in certain cases as the router saw two emissions for the same block reservation. The simplest solution would be to pass t instead of train to emit(), but then the ordering of the two emissions would be inconsistent. Thus the additional logic to delay further emissions until the outstanding one is completed. --- source/libr2c2/block.cpp | 20 ++++++++++++++++---- source/libr2c2/block.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/source/libr2c2/block.cpp b/source/libr2c2/block.cpp index a0d90f3..25b3bc8 100644 --- a/source/libr2c2/block.cpp +++ b/source/libr2c2/block.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include "block.h" @@ -20,7 +21,9 @@ Block::Block(Layout &l, Track &start): turnout_addr(start.get_turnout_address()), conflict(false), sensor(0), - train(0) + train(0), + pending_train(0), + emitting_reserve(false) { add_track(start); @@ -167,10 +170,19 @@ Block *Block::get_link(unsigned epi) const bool Block::reserve(Train *t) { - if(!t || !train) + if(!t || !(emitting_reserve ? pending_train : train)) { - train = t; - signal_reserved.emit(train); + pending_train = t; + if(!emitting_reserve) + { + while(pending_train!=train) + { + train = pending_train; + SetFlag setf(emitting_reserve); + signal_reserved.emit(train); + } + } + return true; } else diff --git a/source/libr2c2/block.h b/source/libr2c2/block.h index f255e43..6823b27 100644 --- a/source/libr2c2/block.h +++ b/source/libr2c2/block.h @@ -38,6 +38,8 @@ private: TrackCircuit *sensor; std::vector endpoints; Train *train; + Train *pending_train; + bool emitting_reserve; public: Block(Layout &, Track &); -- 2.45.2