Skip to contentSkip to conversation

shared/queue: Add way to iterate over queue contents

PATCH In review Bastien Nocera 4 participants 9 messages Apr 3 – Apr 16 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 shared/queue: Add way to iterate over queue contents

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(+)
src/shared/queue.c +8 -0
index 0b53b5b7976e..20fe2a913f58 100644
@@ -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)
src/shared/queue.h +1 -0
index 122f4eaa6c2f..5ea7ce4fd768 100644
@@ -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);
unit/test-queue.c +20 -0
index 46018ef9cf1f..e47199497d41 100644
@@ -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();
 }
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/4 shared: Remove glib dependency from src/shared/ad.c

src/shared/ad.c includes src/eir.h, which uses glib, which means that the non-glib shared library can't be used without linking to glib.

Use our own queue implementation to remove the glib linked-list usage.

---
 plugins/neard.c |  4 ++--
 src/adapter.c   | 10 +++++-----
 src/device.c    | 29 +++++++++++++++--------------
 src/device.h    | 10 ++++++----
 src/eir.c       | 41 ++++++++++++++++++++++-------------------
 src/eir.h       | 11 +++++------
 unit/test-eir.c | 29 ++++++++++++++---------------
 7 files changed, 69 insertions(+), 65 deletions(-)
plugins/neard.c +2 -2
index c84934025cd8..edfc115373ef 100644
@@ -58,7 +58,7 @@ struct oob_params {
 	bdaddr_t address;
 	uint32_t class;
 	char *name;
-	GSList *services;
+	struct queue *services;
 	uint8_t *hash;
 	uint8_t *randomizer;
 	uint8_t *pin;
@@ -68,7 +68,7 @@ struct oob_params {
 
 static void free_oob_params(struct oob_params *params)
 {
-	g_slist_free_full(params->services, free);
+	queue_destroy(params->services, free);
 	g_free(params->name);
 	g_free(params->hash);
 	g_free(params->randomizer);
src/adapter.c +5 -5
index 04568dae6e98..aa5aca7d5fe3 100644
@@ -7171,20 +7171,20 @@ static void confirm_name(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
 
 static void adapter_msd_notify(struct btd_adapter *adapter,
 							struct btd_device *dev,
-							GSList *msd_list)
+							struct queue *msd_list)
 {
 	GSList *cb_l, *cb_next;
-	GSList *msd_l, *msd_next;
+	struct queue_entry *msd_l, *msd_next;
 
 	for (cb_l = adapter->msd_callbacks; cb_l != NULL; cb_l = cb_next) {
 		btd_msd_cb_t cb = cb_l->data;
 
 		cb_next = g_slist_next(cb_l);
 
-		for (msd_l = msd_list; msd_l != NULL; msd_l = msd_next) {
+		for (msd_l = queue_peek_head_entry(msd_list); msd_l != NULL; msd_l = msd_next) {
 			const struct eir_msd *msd = msd_l->data;
 
-			msd_next = g_slist_next(msd_l);
+			msd_next = msd_l->next;
 
 			cb(adapter, dev, msd->company, msd->data,
 								msd->data_len);
@@ -7223,7 +7223,7 @@ static bool is_filter_match(GSList *discovery_filter, struct eir_data *eir_data,
 				/* m->data contains string representation of
 				 * uuid.
 				 */
-				if (g_slist_find_custom(eir_data->services,
+				if (queue_find(eir_data->services,
 							m->data,
 							g_strcmp) != NULL)
 					got_match = true;
src/device.c +15 -14
index 0e8ca28d3809..f755851280c0 100644
@@ -2432,16 +2432,16 @@ unref:
 	dev->connect = NULL;
 }
 
-void device_add_eir_uuids(struct btd_device *dev, GSList *uuids)
+void device_add_eir_uuids(struct btd_device *dev, struct queue *uuids)
 {
-	GSList *l;
+	struct queue_entry *q;
 	GSList *added = NULL;
 
 	if (dev->bredr_state.svc_resolved || dev->le_state.svc_resolved)
 		return;
 
-	for (l = uuids; l != NULL; l = l->next) {
-		const char *str = l->data;
+	for (q = queue_peek_head_entry(uuids); q != NULL; q = q->next) {
+		const char *str = q->data;
 		if (g_slist_find_custom(dev->eir_uuids, str, bt_uuid_strcmp))
 			continue;
 		added = g_slist_append(added, (void *)str);
@@ -2465,13 +2465,13 @@ static void add_manufacturer_data(void *data, void *user_data)
 					DEVICE_INTERFACE, "ManufacturerData");
 }
 
-void device_set_manufacturer_data(struct btd_device *dev, GSList *list,
+void device_set_manufacturer_data(struct btd_device *dev, struct queue *queue,
 								bool duplicate)
 {
 	if (duplicate)
 		bt_ad_clear_manufacturer_data(dev->ad);
 
-	g_slist_foreach(list, add_manufacturer_data, dev);
+	queue_foreach(queue, add_manufacturer_data, dev);
 }
 
 static void add_service_data(void *data, void *user_data)
@@ -2479,7 +2479,7 @@ static void add_service_data(void *data, void *user_data)
 	struct eir_sd *sd = data;
 	struct btd_device *dev = user_data;
 	bt_uuid_t uuid;
-	GSList *l;
+	struct queue *q;
 
 	if (bt_string_to_uuid(&uuid, sd->uuid) < 0)
 		return;
@@ -2487,21 +2487,22 @@ static void add_service_data(void *data, void *user_data)
 	if (!bt_ad_add_service_data(dev->ad, &uuid, sd->data, sd->data_len))
 		return;
 
-	l = g_slist_append(NULL, sd->uuid);
-	device_add_eir_uuids(dev, l);
-	g_slist_free(l);
+	q = queue_new();
+	queue_push_tail(q, sd->uuid);
+	device_add_eir_uuids(dev, q);
+	queue_destroy(q, NULL);
 
 	g_dbus_emit_property_changed(dbus_conn, dev->path,
 					DEVICE_INTERFACE, "ServiceData");
 }
 
-void device_set_service_data(struct btd_device *dev, GSList *list,
+void device_set_service_data(struct btd_device *dev, struct queue *queue,
 							bool duplicate)
 {
 	if (duplicate)
 		bt_ad_clear_service_data(dev->ad);
 
-	g_slist_foreach(list, add_service_data, dev);
+	queue_foreach(queue, add_service_data, dev);
 }
 
 static void add_data(void *data, void *user_data)
@@ -2518,13 +2519,13 @@ static void add_data(void *data, void *user_data)
 						"AdvertisingData");
 }
 
-void device_set_data(struct btd_device *dev, GSList *list,
+void device_set_data(struct btd_device *dev, struct queue *queue,
 							bool duplicate)
 {
 	if (duplicate)
 		bt_ad_clear_data(dev->ad);
 
-	g_slist_foreach(list, add_data, dev);
+	queue_foreach(queue, add_data, dev);
 }
 
 static struct btd_service *find_connectable_service(struct btd_device *dev,
src/device.h +6 -4
index c7b8b2a16eb9..b36f9af66dd2 100644
@@ -9,6 +9,8 @@
  *
  */
 
+#include "src/shared/queue.h"
+
 #define DEVICE_INTERFACE	"org.bluez.Device1"
 
 struct btd_device;
@@ -78,12 +80,12 @@ void btd_device_gatt_set_service_changed(struct btd_device *device,
 						uint16_t start, uint16_t end);
 bool device_attach_att(struct btd_device *dev, GIOChannel *io);
 void btd_device_add_uuid(struct btd_device *device, const char *uuid);
-void device_add_eir_uuids(struct btd_device *dev, GSList *uuids);
-void device_set_manufacturer_data(struct btd_device *dev, GSList *list,
+void device_add_eir_uuids(struct btd_device *dev, struct queue *uuids);
+void device_set_manufacturer_data(struct btd_device *dev, struct queue *queue,
 							bool duplicate);
-void device_set_service_data(struct btd_device *dev, GSList *list,
+void device_set_service_data(struct btd_device *dev, struct queue *queue,
 							bool duplicate);
-void device_set_data(struct btd_device *dev, GSList *list,
+void device_set_data(struct btd_device *dev, struct queue *queue,
 							bool duplicate);
 void device_probe_profile(gpointer a, gpointer b);
 void device_remove_profile(gpointer a, gpointer b);
src/eir.c +22 -19

108 lines not on this page · raw message

src/eir.h +5 -6
index b9f7c3874eb3..7d7125e756ce 100644
@@ -9,10 +9,9 @@
  *
  */
 
-#include <glib.h>
-
 #include "bluetooth/sdp.h"
 #include "bluetooth/uuid.h"
+#include "src/shared/queue.h"
 
 #define EIR_FLAGS                   0x01  /* flags */
 #define EIR_UUID16_SOME             0x02  /* 16-bit UUID, more available */
@@ -73,7 +72,7 @@ struct eir_ad {
 };
 
 struct eir_data {
-	GSList *services;
+	struct queue *services;
 	unsigned int flags;
 	char *name;
 	uint32_t class;
@@ -88,9 +87,9 @@ struct eir_data {
 	uint16_t did_product;
 	uint16_t did_version;
 	uint16_t did_source;
-	GSList *msd_list;
-	GSList *sd_list;
-	GSList *data_list;
+	struct queue *msd_list;
+	struct queue *sd_list;
+	struct queue *data_list;
 };
 
 void eir_data_free(struct eir_data *eir);
unit/test-eir.c +14 -15
index 55967e957c82..8d67b1973e6e 100644
@@ -587,7 +587,7 @@ static void print_debug(const char *str, void *user_data)
 static void test_ad(const struct test_data *test, struct eir_data *eir)
 {
 	struct bt_ad *ad;
-	GSList *list;
+	struct queue_entry *q;
 
 	ad = bt_ad_new_with_data(test->eir_size, test->eir_data);
 	g_assert(ad);
@@ -607,8 +607,8 @@ static void test_ad(const struct test_data *test, struct eir_data *eir)
 		}
 	}
 
-	for (list = eir->msd_list; list; list = list->next) {
-		struct eir_msd *msd = list->data;
+	for (q = queue_peek_head_entry(eir->msd_list); q; q = q->next) {
+		struct eir_msd *msd = q->data;
 		struct bt_ad_manufacturer_data adm;
 
 		adm.manufacturer_id = msd->company;
@@ -618,8 +618,8 @@ static void test_ad(const struct test_data *test, struct eir_data *eir)
 		g_assert(bt_ad_has_manufacturer_data(ad, &adm));
 	}
 
-	for (list = eir->sd_list; list; list = list->next) {
-		struct eir_sd *sd = list->data;
+	for (q = queue_peek_head_entry(eir->sd_list); q; q = q->next) {
+		struct eir_sd *sd = q->data;
 		struct bt_ad_service_data ads;
 
 		bt_string_to_uuid(&ads.uuid, sd->uuid);
@@ -636,7 +636,7 @@ static void test_parsing(gconstpointer data)
 {
 	const struct test_data *test = data;
 	struct eir_data eir;
-	GSList *list;
+	struct queue_entry *q;
 
 	memset(&eir, 0, sizeof(eir));
 
@@ -646,8 +646,8 @@ static void test_parsing(gconstpointer data)
 	tester_debug("Name: %s", eir.name);
 	tester_debug("TX power: %d", eir.tx_power);
 
-	for (list = eir.services; list; list = list->next) {
-		char *uuid_str = list->data;
+	for (q = queue_peek_head_entry(eir.services); q; q = q->next) {
+		char *uuid_str = q->data;
 
 		tester_debug("UUID: %s", uuid_str);
 	}
@@ -664,11 +664,10 @@ static void test_parsing(gconstpointer data)
 	g_assert(eir.tx_power == test->tx_power);
 
 	if (test->uuid) {
-		GSList *list;
 		int n = 0;
 
-		for (list = eir.services; list; list = list->next, n++) {
-			char *uuid_str = list->data;
+		for (q = queue_peek_head_entry(eir.services); q; q = q->next, n++) {
+			char *uuid_str = q->data;
 			g_assert(test->uuid[n]);
 			g_assert_cmpstr(test->uuid[n], ==, uuid_str);
 		}
@@ -676,16 +675,16 @@ static void test_parsing(gconstpointer data)
 		g_assert(eir.services == NULL);
 	}
 
-	for (list = eir.msd_list; list; list = list->next) {
-		struct eir_msd *msd = list->data;
+	for (q = queue_peek_head_entry(eir.msd_list); q; q = q->next) {
+		struct eir_msd *msd = q->data;
 
 		tester_debug("Manufacturer ID: 0x%04x", msd->company);
 		util_hexdump(' ', msd->data, msd->data_len, print_debug,
 							"Manufacturer Data:");
 	}
 
-	for (list = eir.sd_list; list; list = list->next) {
-		struct eir_sd *sd = list->data;
+	for (q = queue_peek_head_entry(eir.sd_list); q; q = q->next) {
+		struct eir_sd *sd = q->data;
 
 		tester_debug("Service UUID: %s", sd->uuid);
 		util_hexdump(' ', sd->data, sd->data_len, print_debug,
Signature · 1 line
2.53.0
#2 lore raw

PATCH 3/4 shared/queue: Fix warning when compiling ad.c

In reply to Bastien Nocera

Both ad.c and eir.h include queue.h as both use the struct declared in this header. Quiet the warnings with a stanza that means it will be ignored second time around.

---
 src/shared/queue.h | 2 ++
 1 file changed, 2 insertions(+)
src/shared/queue.h +2 -0
index 5ea7ce4fd768..3a2dc407d91b 100644
@@ -8,6 +8,8 @@
  *
  */
 
+#pragma once
+
 #include <stdbool.h>
 
 typedef void (*queue_destroy_func_t)(void *data);
Signature · 1 line
2.53.0
#3 lore raw

PATCH 4/4 shared: Remove unneeded glib includes

In reply to Bastien Nocera

glib was included, but no glib functions or data types were being used, so remove those includes.

---
 src/shared/csip.c | 2 --
 src/shared/rap.c  | 1 -
 2 files changed, 3 deletions(-)
src/shared/csip.c +0 -2
index c5b77001a1aa..06b1606d9123 100644
@@ -15,8 +15,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
-
 #include "bluetooth/bluetooth.h"
 #include "bluetooth/uuid.h"
 
src/shared/rap.c +0 -1
index 39ef3f2783c4..ccf3e6f33793 100644
@@ -12,7 +12,6 @@
 #include <stdbool.h>
 #include <unistd.h>
 #include <errno.h>
-#include <glib.h>
 
 #include "bluetooth/bluetooth.h"
 #include "bluetooth/uuid.h"
Signature · 1 line
2.53.0
#4 lore raw
In reply to Bastien Nocera

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1076877

---Test result---

Test Summary:

CheckPatch                    PENDING   0.49 seconds
GitLint                       PENDING   0.33 seconds
BuildEll                      PASS      19.98 seconds
BluezMake                     PASS      633.06 seconds
MakeCheck                     PASS      18.61 seconds
MakeDistcheck                 PASS      242.45 seconds
CheckValgrind                 PASS      288.97 seconds
CheckSmatch                   PASS      345.38 seconds
bluezmakeextell               PASS      180.10 seconds
IncrementalBuild              PENDING   0.31 seconds
ScanBuild                     PASS      998.84 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

https://github.com/bluez/bluez/pull/2008/checks

---
Regards,
Linux Bluetooth

#5 lore raw
In reply to Bastien Nocera

Hey,

Could I please get a review on this patchset?

Cheers

Quoted 85 lines · Bastien Nocera

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(+)
src/shared/queue.c +0 -0
index 0b53b5b7976e..20fe2a913f58 100644
@@ -179,6 +179,14 @@ void *queue_peek_head(struct queue *queue)
  	return queue->head->data;
  }

src/shared/queue.c +8 -0
+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)

src/shared/queue.h +1 -0
index 122f4eaa6c2f..5ea7ce4fd768 100644
@@ -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);

unit/test-queue.c +0 -0
index 46018ef9cf1f..e47199497d41 100644
@@ -246,6 +246,25 @@ static void test_remove_all(const void *data)
  	tester_test_passed();
  }

unit/test-queue.c +13 -0
+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)));

unit/test-queue.c +6 -0
+	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);

unit/test-queue.c +1 -0
@@ -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();
 }

#6 lore raw

Hi Bastien,

Quoted 4 lines · Bastien Nocera

Hey,

Could I please get a review on this patchset?

There is already a function to iterate manually:

queue_get_entries

Quoted 89 lines

Cheers

Quoted 85 lines · Bastien Nocera

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(+)
src/shared/queue.c +8 -0
index 0b53b5b7976e..20fe2a913f58 100644
@@ -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)
src/shared/queue.h +1 -0
index 122f4eaa6c2f..5ea7ce4fd768 100644
@@ -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);

unit/test-queue.c +19 -0
index 46018ef9cf1f..e47199497d41 100644
@@ -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);
unit/test-queue.c +1 -0
@@ -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();

}

Signature · 1 line
Luiz Augusto von Dentz
#7 lore raw
Quoted 5 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 1 line · Bastien Nocera
Quoted 7 lines
Quoted 3 lines

Hey,

Could I please get a review on this patchset?

There is already a function to iterate manually:

queue_get_entries

Well, this is starting to be embarrassing. I've sent in a v3 that uses this API instead.

Cheers

Quoted 96 lines
Quoted 95 lines

Cheers

Quoted 90 lines · Bastien Nocera

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(+)
src/shared/queue.c +8 -0
index 0b53b5b7976e..20fe2a913f58 100644
@@ -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)
src/shared/queue.h +0 -0
index 122f4eaa6c2f..5ea7ce4fd768 100644
@@ -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);

unit/test-queue.c +19 -0
index 46018ef9cf1f..e47199497d41 100644
@@ -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);

unit/test-queue.c +0 -0
@@ -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();
 }

#8 lore raw
In reply to Bastien Nocera
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 9 lines · On Fri, 3 Apr 2026 10:40:54 +0200 you wrote:

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(+)

Here is the summary with links:
- [BlueZ,1/4] shared/queue: Add way to iterate over queue contents (no matching commit)
- [BlueZ,2/4] shared: Remove glib dependency from src/shared/ad.c (no matching commit)
- [BlueZ,3/4] shared/queue: Fix warning when compiling ad.c
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6a6aaeba6aed
- [BlueZ,4/4] shared: Remove unneeded glib includes

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=07a0b87e6b34

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html