git-svn-id: svn://db.shs.com.ru/pip@961 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -119,13 +119,14 @@ public:
|
|||||||
* @param defaultVal value, which returns if the specified waiting time elapses before an element is available
|
* @param defaultVal value, which returns if the specified waiting time elapses before an element is available
|
||||||
* @return the head of this queue, or defaultVal if the specified waiting time elapses before an element is available
|
* @return the head of this queue, or defaultVal if the specified waiting time elapses before an element is available
|
||||||
*/
|
*/
|
||||||
T poll(int timeoutMs, const T & defaultVal) {
|
T poll(int timeoutMs, const T & defaultVal, bool* isOk = nullptr) {
|
||||||
T t;
|
T t;
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
bool isOk = cond_var_add->waitFor(mutex, timeoutMs, [&]() { return !PIDeque<T>::isEmpty(); });
|
bool isNotEmpty = cond_var_add->waitFor(mutex, timeoutMs, [&]() { return !PIDeque<T>::isEmpty(); });
|
||||||
t = isOk ? T(PIDeque<T>::take_front()) : defaultVal;
|
t = isNotEmpty ? T(PIDeque<T>::take_front()) : defaultVal;
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
if (isOk) cond_var_rem->notifyOne();
|
if (isNotEmpty) cond_var_rem->notifyOne();
|
||||||
|
if (isOk != nullptr) *isOk = isNotEmpty;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user