From: Marcel Holtmann Date: Sun, 23 Mar 2014 19:09:58 +0000 (-0700) Subject: shared: Add simple function to remove entry from queue X-Git-Tag: android-x86-4.4-r3~4561 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=bc959924328d26250ef24892c27ffba7583d7d2a;p=android-x86%2Fexternal-bluetooth-bluez.git shared: Add simple function to remove entry from queue --- diff --git a/src/shared/queue.c b/src/shared/queue.c index fdf84e875..8a6972925 100644 --- a/src/shared/queue.c +++ b/src/shared/queue.c @@ -202,6 +202,35 @@ void *queue_find(struct queue *queue, queue_match_func_t function, return NULL; } +bool queue_remove(struct queue *queue, void *data) +{ + struct queue_entry *entry, *prev; + + if (!queue || !data) + return false; + + for (entry = queue->head, prev = NULL; entry; + prev = entry, entry = entry->next) { + if (entry->data != data) + continue; + + if (prev) + prev->next = entry->next; + else + queue->head = entry->next; + + if (!entry->next) + queue->tail = prev; + + free(entry); + queue->entries--; + + return true; + } + + return false; +} + void *queue_remove_if(struct queue *queue, queue_match_func_t function, void *user_data) { diff --git a/src/shared/queue.h b/src/shared/queue.h index e9ab440d3..8201ff861 100644 --- a/src/shared/queue.h +++ b/src/shared/queue.h @@ -46,6 +46,7 @@ typedef bool (*queue_match_func_t)(const void *a, const void *b); void *queue_find(struct queue *queue, queue_match_func_t function, void *user_data); +bool queue_remove(struct queue *queue, void *data); void *queue_remove_if(struct queue *queue, queue_match_func_t function, void *user_data); unsigned int queue_remove_all(struct queue *queue, queue_match_func_t function,