BLI_threads Queue: add `BLI_thread_queue_is_empty()`.

Avoids counting the whole queue when we only want to check whether it is empty or not!
This commit is contained in:
Bastien Montagne 2015-06-19 12:30:21 +02:00
parent 1cf1f48893
commit 0f171d4a25
2 changed files with 12 additions and 0 deletions

View File

@ -175,6 +175,7 @@ void BLI_thread_queue_push(ThreadQueue *queue, void *work);
void *BLI_thread_queue_pop(ThreadQueue *queue);
void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms);
int BLI_thread_queue_size(ThreadQueue *queue);
bool BLI_thread_queue_is_empty(ThreadQueue *queue);
void BLI_thread_queue_wait_finish(ThreadQueue *queue);
void BLI_thread_queue_nowait(ThreadQueue *queue);

View File

@ -777,6 +777,17 @@ int BLI_thread_queue_size(ThreadQueue *queue)
return size;
}
bool BLI_thread_queue_is_empty(ThreadQueue *queue)
{
bool is_empty;
pthread_mutex_lock(&queue->mutex);
is_empty = BLI_gsqueue_is_empty(queue->queue);
pthread_mutex_unlock(&queue->mutex);
return is_empty;
}
void BLI_thread_queue_nowait(ThreadQueue *queue)
{
pthread_mutex_lock(&queue->mutex);