From dfa0f7daf5d0d3f0760153410c03f8f67b3cea86 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Sun, 26 Feb 2023 11:04:32 +0100 Subject: [PATCH] blocking_queue: add remove() function Allows to remove an object which is still in the queue. --- src/libstrongswan/collections/blocking_queue.c | 15 +++++++++++++++ src/libstrongswan/collections/blocking_queue.h | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/libstrongswan/collections/blocking_queue.c b/src/libstrongswan/collections/blocking_queue.c index 40f65a930..7e5fc3ac6 100644 --- a/src/libstrongswan/collections/blocking_queue.c +++ b/src/libstrongswan/collections/blocking_queue.c @@ -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, diff --git a/src/libstrongswan/collections/blocking_queue.h b/src/libstrongswan/collections/blocking_queue.h index d902c3245..c5d4cc272 100644 --- a/src/libstrongswan/collections/blocking_queue.h +++ b/src/libstrongswan/collections/blocking_queue.h @@ -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. *