From 7d8d4a03fbcbc08921626d7b4698fec11e0aacdd Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 25 Nov 2012 22:36:15 +0000 Subject: [PATCH] Make SGLockingQueue::pop usable. Since there's no external lock, it was impossible to check the queue was non-empty before a pop, without a race condition. To avoid this, tolerate an empty queue and return a default constructed value. --- simgear/threads/SGQueue.hxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simgear/threads/SGQueue.hxx b/simgear/threads/SGQueue.hxx index 37122c5a..c4fab564 100644 --- a/simgear/threads/SGQueue.hxx +++ b/simgear/threads/SGQueue.hxx @@ -127,8 +127,8 @@ public: */ virtual T pop() { SGGuard g(mutex); - //if (fifo.empty()) throw NoSuchElementException(); - assert( ! this->fifo.empty() ); + if (this->fifo.empty()) return T(); // assumes T is default constructable + // if (fifo.empty()) // { // mutex.unlock(); -- 2.39.5