linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ 2/5] shared: Add function to insert element after entry
Date: Tue, 25 Nov 2014 21:26:46 -0800	[thread overview]
Message-ID: <1416979609-3056-3-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1416979609-3056-1-git-send-email-armansito@chromium.org>

This patch adds queue_insert_after, which inserts the given "data"
after the first occurence of element "entry" in a queue.
---
 src/shared/queue.c | 30 ++++++++++++++++++++++++++++++
 src/shared/queue.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/src/shared/queue.c b/src/shared/queue.c
index 5329a80..1373d0d 100644
--- a/src/shared/queue.c
+++ b/src/shared/queue.c
@@ -134,6 +134,36 @@ bool queue_push_head(struct queue *queue, void *data)
 	return true;
 }
 
+bool queue_insert_after(struct queue *queue, void *entry, void *data)
+{
+	struct queue_entry *qentry = NULL, *tmp, *new_entry;
+
+	if (!queue)
+		return false;
+
+	for (tmp = queue->head; tmp; tmp = tmp->next)
+		if (tmp->data == entry)
+			qentry = tmp;
+
+	if (!qentry)
+		return false;
+
+	new_entry = new0(struct queue_entry, 1);
+	if (!new_entry)
+		return false;
+
+	new_entry->data = data;
+	new_entry->next = qentry->next;
+
+	if (!qentry->next)
+		queue->tail = new_entry;
+
+	qentry->next = new_entry;
+	queue->entries++;
+
+	return true;
+}
+
 void *queue_pop_head(struct queue *queue)
 {
 	struct queue_entry *entry;
diff --git a/src/shared/queue.h b/src/shared/queue.h
index 709590b..6ddc889 100644
--- a/src/shared/queue.h
+++ b/src/shared/queue.h
@@ -32,6 +32,7 @@ void queue_destroy(struct queue *queue, queue_destroy_func_t destroy);
 
 bool queue_push_tail(struct queue *queue, void *data);
 bool queue_push_head(struct queue *queue, void *data);
+bool queue_insert_after(struct queue *queue, void *entry, void *data);
 void *queue_pop_head(struct queue *queue);
 void *queue_peek_head(struct queue *queue);
 void *queue_peek_tail(struct queue *queue);
-- 
2.2.0.rc0.207.ga3a616c


  parent reply	other threads:[~2014-11-26  5:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26  5:26 [PATCH BlueZ 0/5] shared/gatt-db: Add support for client role Arman Uguray
2014-11-26  5:26 ` [PATCH BlueZ 1/5] shared/gatt-db: Add high-level functions for client Arman Uguray
2014-11-26 10:37   ` Luiz Augusto von Dentz
2014-11-26 21:48     ` Arman Uguray
2014-11-26  5:26 ` Arman Uguray [this message]
2014-11-26 10:15   ` [PATCH BlueZ 2/5] shared: Add function to insert element after entry Luiz Augusto von Dentz
2014-11-26  5:26 ` [PATCH BlueZ 3/5] unit/test-queue: Add /queue/insert_after test Arman Uguray
2014-11-26  5:26 ` [PATCH BlueZ 4/5] shared/gatt-db: Add gatt_db_insert_service function Arman Uguray
2014-11-26  5:26 ` [PATCH BlueZ 5/5] shared/gatt-db: Add clear functions Arman Uguray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1416979609-3056-3-git-send-email-armansito@chromium.org \
    --to=armansito@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).