Skip to content

Commit

Permalink
feat(lib): add queue safe peek
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez committed May 11, 2022
1 parent 21c1bcf commit 4072a61
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/src/util/queue/safe_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ void safe_queue_pop(safe_queue_t *this)
queue_pop(this->_queue);
pthread_mutex_unlock(&this->_mtx);
}

void *safe_queue_peek(safe_queue_t *this)
{
// The element to be peeked in the queue
void *e = NULL;

if (this)
{
pthread_mutex_lock(&this->_mtx);
e = queue_peek(this);
pthread_mutex_unlock(&this->_mtx);
}

return e;
}

0 comments on commit 4072a61

Please sign in to comment.