fix for repeated wait in Queue::remove, better variable naming
This commit is contained in:
Regular → Executable
+8
-5
@@ -109,27 +109,30 @@ class Queue {
|
|||||||
* @return whether the item was removed.
|
* @return whether the item was removed.
|
||||||
*/
|
*/
|
||||||
bool remove(T item, bool wait = false) {
|
bool remove(T item, bool wait = false) {
|
||||||
bool ret = false;
|
bool result = false;
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
|
while (true) {
|
||||||
clockGettime(&t);
|
clockGettime(&t);
|
||||||
t.tv_sec++; // check thread death every second
|
t.tv_sec++; // check thread death every second
|
||||||
do {
|
|
||||||
size_t oldSize = m_queue.size();
|
size_t oldSize = m_queue.size();
|
||||||
if (oldSize > 0) {
|
if (oldSize > 0) {
|
||||||
m_queue.remove(item);
|
m_queue.remove(item);
|
||||||
if (m_queue.size() != oldSize) {
|
if (m_queue.size() != oldSize) {
|
||||||
ret = true;
|
result = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!wait) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
int ret = pthread_cond_timedwait(&m_cond, &m_mutex, &t);
|
int ret = pthread_cond_timedwait(&m_cond, &m_mutex, &t);
|
||||||
if (ret != 0 && ret != ETIMEDOUT) {
|
if (ret != 0 && ret != ETIMEDOUT) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (wait);
|
}
|
||||||
pthread_mutex_unlock(&m_mutex);
|
pthread_mutex_unlock(&m_mutex);
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user