[pulseaudio-discuss] [PATCH RFCv2 18/27] queue: Add pa_queue_peek() function

Peter Meerwald pmeerw at pmeerw.net
Tue Oct 28 12:46:31 PDT 2014


From: Peter Meerwald <p.meerwald at bct-electronic.com>

gets a pointer to the first entry's data if it exists, NULL
otherwise

Signed-off-by: Peter Meerwald <pmeerw.net>
---
 src/pulsecore/queue.c | 11 +++++++++++
 src/pulsecore/queue.h |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/src/pulsecore/queue.c b/src/pulsecore/queue.c
index f4216ee..de87f33 100644
--- a/src/pulsecore/queue.c
+++ b/src/pulsecore/queue.c
@@ -117,6 +117,17 @@ void* pa_queue_pop(pa_queue *q) {
     return p;
 }
 
+const void* pa_queue_peek(pa_queue *q) {
+    struct queue_entry *e;
+
+    pa_assert(q);
+
+    if (!(e = q->front))
+        return NULL;
+
+    return e->data;
+}
+
 int pa_queue_isempty(pa_queue *q) {
     pa_assert(q);
 
diff --git a/src/pulsecore/queue.h b/src/pulsecore/queue.h
index 1b95ec8..ebaa148 100644
--- a/src/pulsecore/queue.h
+++ b/src/pulsecore/queue.h
@@ -38,6 +38,9 @@ void pa_queue_free(pa_queue *q, pa_free_cb_t free_func);
 void pa_queue_push(pa_queue *q, void *p);
 void* pa_queue_pop(pa_queue *q);
 
+/* Get a pointer to the first entry's data if it exists, NULL otherwise */
+const void* pa_queue_peek(pa_queue *q);
+
 int pa_queue_isempty(pa_queue *q);
 
 #endif
-- 
1.9.1



More information about the pulseaudio-discuss mailing list