git-svn-id: svn://db.shs.com.ru/pip@961 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:

View File

@@ -119,13 +119,14 @@ public:
* @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
*/
T poll(int timeoutMs, const T & defaultVal) {
T poll(int timeoutMs, const T & defaultVal, bool* isOk = nullptr) {
T t;
mutex.lock();
bool isOk = cond_var_add->waitFor(mutex, timeoutMs, [&]() { return !PIDeque<T>::isEmpty(); });
t = isOk ? T(PIDeque<T>::take_front()) : defaultVal;
bool isNotEmpty = cond_var_add->waitFor(mutex, timeoutMs, [&]() { return !PIDeque<T>::isEmpty(); });
t = isNotEmpty ? T(PIDeque<T>::take_front()) : defaultVal;
mutex.unlock();
if (isOk) cond_var_rem->notifyOne();
if (isNotEmpty) cond_var_rem->notifyOne();
if (isOk != nullptr) *isOk = isNotEmpty;
return t;
}