@ -49,7 +49,7 @@ public:
push_cv_ . notify_one ( ) ;
}
// try to dequeue item. if no item found. wait up to timeout and try again
// dequeue with a timeout.
// Return true, if succeeded dequeue item, false otherwise
bool dequeue_for ( T & popped_item , std : : chrono : : milliseconds wait_duration )
{
@ -66,6 +66,18 @@ public:
return true ;
}
// blocking dequeue without a timeout.
void dequeue ( T & popped_item )
{
{
std : : unique_lock < std : : mutex > lock ( queue_mutex_ ) ;
push_cv_ . wait ( lock , [ this ] { return ! this - > q_ . empty ( ) ; } ) ;
popped_item = std : : move ( q_ . front ( ) ) ;
q_ . pop_front ( ) ;
}
pop_cv_ . notify_one ( ) ;
}
# else
// apparently mingw deadlocks if the mutex is released before cv.notify_one(),
// so release the mutex at the very end each function.
@ -87,7 +99,7 @@ public:
push_cv_ . notify_one ( ) ;
}
// try to dequeue item. if no item found. wait up to timeout and try again
// dequeue with a timeout.
// Return true, if succeeded dequeue item, false otherwise
bool dequeue_for ( T & popped_item , std : : chrono : : milliseconds wait_duration )
{
@ -102,6 +114,16 @@ public:
return true ;
}
// blocking dequeue without a timeout.
void dequeue ( T & popped_item )
{
std : : unique_lock < std : : mutex > lock ( queue_mutex_ ) ;
push_cv_ . wait ( lock , [ this ] { return ! this - > q_ . empty ( ) ; } ) ;
popped_item = std : : move ( q_ . front ( ) ) ;
q_ . pop_front ( ) ;
pop_cv_ . notify_one ( ) ;
}
# endif
size_t overrun_counter ( )