blocking_queue: add remove() function

Allows to remove an object which is still in the queue.
This commit is contained in:
Alexander Couzens 2023-02-26 11:04:32 +01:00
parent 4817d5ed0d
commit dfa0f7daf5
2 changed files with 23 additions and 0 deletions

View File

@ -51,6 +51,20 @@ struct private_blocking_queue_t {
};
METHOD(blocking_queue_t, remove_, void*,
private_blocking_queue_t *this, void *item)
{
int removed = 0;
this->mutex->lock(this->mutex);
removed = this->list->remove(this->list, item, NULL);
this->mutex->unlock(this->mutex);
if (removed)
return item;
return NULL;
}
METHOD(blocking_queue_t, enqueue, void,
private_blocking_queue_t *this, void *item)
{
@ -115,6 +129,7 @@ blocking_queue_t *blocking_queue_create()
.public = {
.enqueue = _enqueue,
.dequeue = _dequeue,
.remove = _remove_,
.destroy = _destroy,
.destroy_offset = _destroy_offset,
.destroy_function = _destroy_function,

View File

@ -49,6 +49,14 @@ struct blocking_queue_t {
*/
void *(*dequeue)(blocking_queue_t *this);
/**
* Removes a specific item from the queue.
*
* @param item item to be removed from the queue
* @return item if item was on the queue. Otherwise NULL`
*/
void *(*remove)(blocking_queue_t *this, void *item);
/**
* Destroys a blocking_queue_t object.
*