public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/4] shared/queue: Add way to iterate over queue contents
@ 2026-04-03  8:40 Bastien Nocera
  2026-04-03  8:40 ` [PATCH BlueZ 2/4] shared: Remove glib dependency from src/shared/ad.c Bastien Nocera
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Bastien Nocera @ 2026-04-03  8:40 UTC (permalink / raw)
  To: linux-bluetooth

There were no accessors that would give us an iteratable structure,
leaving us with just *_foreach() constructs that are cumbersome.

Add a way to get the first entry in the queue.
---
 src/shared/queue.c |  8 ++++++++
 src/shared/queue.h |  1 +
 unit/test-queue.c  | 20 ++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/src/shared/queue.c b/src/shared/queue.c
index 0b53b5b7976e..20fe2a913f58 100644
--- a/src/shared/queue.c
+++ b/src/shared/queue.c
@@ -179,6 +179,14 @@ void *queue_peek_head(struct queue *queue)
 	return queue->head->data;
 }
 
+struct queue_entry *queue_peek_head_entry(struct queue *queue)
+{
+	if (!queue || !queue->head)
+		return NULL;
+
+	return queue->head;
+}
+
 void *queue_peek_tail(struct queue *queue)
 {
 	if (!queue || !queue->tail)
diff --git a/src/shared/queue.h b/src/shared/queue.h
index 122f4eaa6c2f..5ea7ce4fd768 100644
--- a/src/shared/queue.h
+++ b/src/shared/queue.h
@@ -27,6 +27,7 @@ bool queue_push_head(struct queue *queue, void *data);
 bool queue_push_after(struct queue *queue, void *entry, void *data);
 void *queue_pop_head(struct queue *queue);
 void *queue_peek_head(struct queue *queue);
+struct queue_entry *queue_peek_head_entry(struct queue *queue);
 void *queue_peek_tail(struct queue *queue);
 
 typedef void (*queue_foreach_func_t)(void *data, void *user_data);
diff --git a/unit/test-queue.c b/unit/test-queue.c
index 46018ef9cf1f..e47199497d41 100644
--- a/unit/test-queue.c
+++ b/unit/test-queue.c
@@ -246,6 +246,25 @@ static void test_remove_all(const void *data)
 	tester_test_passed();
 }
 
+static void test_peek_head_entry(const void *data)
+{
+	struct queue *queue;
+	struct queue_entry *entry;
+
+	queue = queue_new();
+	g_assert(queue != NULL);
+
+	g_assert(queue_push_tail(queue, INT_TO_PTR(10)));
+
+	entry = queue_peek_head_entry(queue);
+	g_assert(entry->data == queue_peek_head(queue));
+	g_assert_cmpint(PTR_TO_INT(entry->data), ==, PTR_TO_INT(queue_peek_head(queue)));
+	g_assert_cmpint(PTR_TO_INT(entry->data), ==, 10);
+
+	queue_destroy(queue, NULL);
+	tester_test_passed();
+}
+
 int main(int argc, char *argv[])
 {
 	tester_init(&argc, &argv);
@@ -263,6 +282,7 @@ int main(int argc, char *argv[])
 						test_destroy_remove, NULL);
 	tester_add("/queue/push_after",  NULL, NULL, test_push_after, NULL);
 	tester_add("/queue/remove_all",  NULL, NULL, test_remove_all, NULL);
+	tester_add("/queue/peek_head_entry", NULL, NULL, test_peek_head_entry, NULL);
 
 	return tester_run();
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-04-03 10:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03  8:40 [PATCH BlueZ 1/4] shared/queue: Add way to iterate over queue contents Bastien Nocera
2026-04-03  8:40 ` [PATCH BlueZ 2/4] shared: Remove glib dependency from src/shared/ad.c Bastien Nocera
2026-04-03  8:40 ` [PATCH BlueZ 3/4] shared/queue: Fix warning when compiling ad.c Bastien Nocera
2026-04-03  8:40 ` [PATCH BlueZ 4/4] shared: Remove unneeded glib includes Bastien Nocera
2026-04-03 10:17 ` [BlueZ,1/4] shared/queue: Add way to iterate over queue contents bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox