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.
This commit is contained in:
@@ -127,8 +127,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual T pop() {
|
virtual T pop() {
|
||||||
SGGuard<SGMutex> g(mutex);
|
SGGuard<SGMutex> g(mutex);
|
||||||
//if (fifo.empty()) throw NoSuchElementException();
|
if (this->fifo.empty()) return T(); // assumes T is default constructable
|
||||||
assert( ! this->fifo.empty() );
|
|
||||||
// if (fifo.empty())
|
// if (fifo.empty())
|
||||||
// {
|
// {
|
||||||
// mutex.unlock();
|
// mutex.unlock();
|
||||||
|
|||||||
Reference in New Issue
Block a user