Skip to content

Commit

Permalink
feat(lib): safe queue is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez committed Jun 2, 2022
1 parent 3dbfe2c commit 5d559e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/inc/util/queue/safe_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ void *safe_queue_pop(safe_queue_t *queue);
* @return an element reference
*/
void *safe_queue_peek(safe_queue_t *queue);

/**
* @brief Tells wether a queue is empty or not (thread safe)
*
* @param queue the queue itself
* @return true when no elements are equeued, false when there are elements
*/
bool safe_queue_is_empty(safe_queue_t *queue);
8 changes: 8 additions & 0 deletions lib/src/util/queue/safe_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ void *safe_queue_pop(safe_queue_t *this)
return e;
}

bool safe_queue_is_empty(safe_queue_t *this)
{
pthread_mutex_lock(&this->_mtx);
bool is_empty = queue_is_empty(this->_queue);
pthread_mutex_unlock(&this->_mtx);
return is_empty;
}

void *safe_queue_peek(safe_queue_t *this)
{
// The element to be peeked in the queue
Expand Down

0 comments on commit 5d559e9

Please sign in to comment.