aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2013-07-14 01:43:04 +0400
committerAlexander Chemeris <Alexander.Chemeris@gmail.com>2013-07-14 23:11:54 +0400
commit69b6a6dfcd882df180e9d5e9856225f4b1d2eeed (patch)
tree9b2be48304b7a4f4572f6e23d554ef3f8cd9a2aa
parentb8646946526903d2bbfa657690936b9bcba80ca5 (diff)
CommonLibs: Allow NULLs to be retrieved from InterthreadQueue.
We need a way to stop InterthreadQueue blocking read to be able to shutdown a thread. The easiest way to do that is to push NULL to the queue, but the original implementation will just ignore that and continue blocking. After the change the blocking read() will exit with NULL result which is perfectly fine with us. Ideally we should change all methods of InterthreadQueue to return a status value to indicate normal exits, timeouts, etc. Right now the only way to indicate an error is returning NULL, which could be a valid operation.
-rw-r--r--CommonLibs/Interthread.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/CommonLibs/Interthread.h b/CommonLibs/Interthread.h
index cdc2e74..132b935 100644
--- a/CommonLibs/Interthread.h
+++ b/CommonLibs/Interthread.h
@@ -1,5 +1,6 @@
/*
* Copyright 2008, 2011 Free Software Foundation, Inc.
+* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
@@ -99,7 +100,7 @@ template <class T, class Fifo=PointerFIFO> class InterthreadQueue {
{
ScopedLock lock(mLock);
T* retVal = (T*)mQ.get();
- while (retVal==NULL) {
+ if (retVal==NULL) {
mWriteSignal.wait(mLock);
retVal = (T*)mQ.get();
}