From: Bastien Nocera <hadess@hadess.net>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH BlueZ 1/4] shared/queue: Add way to iterate over queue contents
Date: Thu, 16 Apr 2026 16:15:30 +0200 [thread overview]
Message-ID: <0821f653dc6ff4bdd25399501b57131aaaef281d.camel@hadess.net> (raw)
In-Reply-To: <CABBYNZ+uJUN1njPukM-A4ubMb-yiuCGR+ZO7RqzBe9p5rFQVcQ@mail.gmail.com>
On Thu, 2026-04-16 at 09:46 -0400, Luiz Augusto von Dentz wrote:
> Hi Bastien,
>
> On Thu, Apr 16, 2026 at 5:05 AM Bastien Nocera <hadess@hadess.net>
> wrote:
> >
> > 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
>
> > Cheers
> >
> > On Fri, 2026-04-03 at 10:40 +0200, Bastien Nocera 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(+)
> > >
> > > 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();
> > > }
> >
>
next prev parent reply other threads:[~2026-04-16 14:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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
2026-04-16 9:04 ` [PATCH BlueZ 1/4] " Bastien Nocera
2026-04-16 13:46 ` Luiz Augusto von Dentz
2026-04-16 14:15 ` Bastien Nocera [this message]
2026-04-16 15:20 ` patchwork-bot+bluetooth
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=0821f653dc6ff4bdd25399501b57131aaaef281d.camel@hadess.net \
--to=hadess@hadess.net \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
/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