From a10cdf5cbcfc11e948f2e64e3adb4325f96f6bb4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 18 Jul 2012 07:17:44 +0000 Subject: Fixed an issue in the seldomly used dequeue( bool ) function in Bu::SynchroQueue and also added the unblockAll function, which makes the forever-blocking dequeue function suddenly much more useful. --- src/stable/synchroqueue.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/stable/synchroqueue.h b/src/stable/synchroqueue.h index 7ba299f..1c16e15 100644 --- a/src/stable/synchroqueue.h +++ b/src/stable/synchroqueue.h @@ -124,23 +124,25 @@ namespace Bu { if( bBlock ) { - for(;;) + cBlock.wait(); + + if( pStart == NULL ) { - if( pStart != NULL ) - { - cBlock.unlock(); - break; - } - cBlock.wait(); + cBlock.unlock(); + return NULL; } - - T tmp = dequeue( false ); + T pTmp = pStart->pData; + Item *pDel = pStart; + pStart = pStart->pNext; + delete pDel; + nSize--; cBlock.unlock(); - return tmp; + return pTmp; } + cBlock.unlock(); return NULL; } else @@ -226,6 +228,13 @@ namespace Bu return nRet; } + void unblockAll() + { + cBlock.lock(); + cBlock.broadcast(); + cBlock.unlock(); + } + private: Item *pStart; /**< The start of the queue, the next element to dequeue. */ Item *pEnd; /**< The end of the queue, the last element to dequeue. */ -- cgit v1.2.3