]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/asyncq.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / asyncq.c
index 8e0dfbc3086b5ef28520ebf0a46c0969d8817efe..559b57744251737cb553bd3011ae30067b980e4d 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -28,6 +26,8 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include <pulse/xmalloc.h>
+
 #include <pulsecore/atomic.h>
 #include <pulsecore/log.h>
 #include <pulsecore/thread.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/llist.h>
 #include <pulsecore/flist.h>
-#include <pulse/xmalloc.h>
+#include <pulsecore/fdsem.h>
 
 #include "asyncq.h"
-#include "fdsem.h"
 
 #define ASYNCQ_SIZE 256
 
@@ -66,14 +65,14 @@ struct pa_asyncq {
 
     PA_LLIST_HEAD(struct localq, localq);
     struct localq *last_localq;
-    pa_bool_t waiting_for_post;
+    bool waiting_for_post;
 };
 
 PA_STATIC_FLIST_DECLARE(localq, 0, pa_xfree);
 
 #define PA_ASYNCQ_CELLS(x) ((pa_atomic_ptr_t*) ((uint8_t*) (x) + PA_ALIGN(sizeof(struct pa_asyncq))))
 
-static int reduce(pa_asyncq *l, int value) {
+static unsigned reduce(pa_asyncq *l, unsigned value) {
     return value & (unsigned) (l->size - 1);
 }
 
@@ -91,7 +90,7 @@ pa_asyncq *pa_asyncq_new(unsigned size) {
 
     PA_LLIST_HEAD_INIT(struct localq, l->localq);
     l->last_localq = NULL;
-    l->waiting_for_post = FALSE;
+    l->waiting_for_post = false;
 
     if (!(l->read_fdsem = pa_fdsem_new())) {
         pa_xfree(l);
@@ -133,8 +132,8 @@ void pa_asyncq_free(pa_asyncq *l, pa_free_cb_t free_cb) {
     pa_xfree(l);
 }
 
-static int push(pa_asyncq*l, void *p, pa_bool_t wait) {
-    int idx;
+static int push(pa_asyncq*l, void *p, bool wait_op) {
+    unsigned idx;
     pa_atomic_ptr_t *cells;
 
     pa_assert(l);
@@ -147,7 +146,7 @@ static int push(pa_asyncq*l, void *p, pa_bool_t wait) {
 
     if (!pa_atomic_ptr_cmpxchg(&cells[idx], NULL, p)) {
 
-        if (!wait)
+        if (!wait_op)
             return -1;
 
 /*         pa_log("sleeping on push"); */
@@ -165,15 +164,15 @@ static int push(pa_asyncq*l, void *p, pa_bool_t wait) {
     return 0;
 }
 
-static pa_bool_t flush_postq(pa_asyncq *l) {
+static bool flush_postq(pa_asyncq *l, bool wait_op) {
     struct localq *q;
 
     pa_assert(l);
 
     while ((q = l->last_localq)) {
 
-        if (push(l, q->data, FALSE) < 0)
-            return FALSE;
+        if (push(l, q->data, wait_op) < 0)
+            return false;
 
         l->last_localq = q->prev;
 
@@ -183,16 +182,16 @@ static pa_bool_t flush_postq(pa_asyncq *l) {
             pa_xfree(q);
     }
 
-    return TRUE;
+    return true;
 }
 
-int pa_asyncq_push(pa_asyncq*l, void *p, pa_bool_t wait) {
+int pa_asyncq_push(pa_asyncq*l, void *p, bool wait_op) {
     pa_assert(l);
 
-    if (!flush_postq(l))
+    if (!flush_postq(l, wait_op))
         return -1;
 
-    return push(l, p, wait);
+    return push(l, p, wait_op);
 }
 
 void pa_asyncq_post(pa_asyncq*l, void *p) {
@@ -201,13 +200,15 @@ void pa_asyncq_post(pa_asyncq*l, void *p) {
     pa_assert(l);
     pa_assert(p);
 
-    if (pa_asyncq_push(l, p, FALSE) >= 0)
-        return;
+    if (flush_postq(l, false))
+        if (pa_asyncq_push(l, p, false) >= 0)
+            return;
 
     /* OK, we couldn't push anything in the queue. So let's queue it
      * locally and push it later */
 
-    pa_log("q overrun, queuing locally");
+    if (pa_log_ratelimit(PA_LOG_WARN))
+        pa_log_warn("q overrun, queuing locally");
 
     if (!(q = pa_flist_pop(PA_STATIC_FLIST_GET(localq))))
         q = pa_xnew(struct localq, 1);
@@ -221,8 +222,8 @@ void pa_asyncq_post(pa_asyncq*l, void *p) {
     return;
 }
 
-void* pa_asyncq_pop(pa_asyncq*l, pa_bool_t wait) {
-    int idx;
+void* pa_asyncq_pop(pa_asyncq*l, bool wait_op) {
+    unsigned idx;
     void *ret;
     pa_atomic_ptr_t *cells;
 
@@ -235,7 +236,7 @@ void* pa_asyncq_pop(pa_asyncq*l, pa_bool_t wait) {
 
     if (!(ret = pa_atomic_ptr_load(&cells[idx]))) {
 
-        if (!wait)
+        if (!wait_op)
             return NULL;
 
 /*         pa_log("sleeping on pop"); */
@@ -265,7 +266,7 @@ int pa_asyncq_read_fd(pa_asyncq *q) {
 }
 
 int pa_asyncq_read_before_poll(pa_asyncq *l) {
-    int idx;
+    unsigned idx;
     pa_atomic_ptr_t *cells;
 
     pa_assert(l);
@@ -282,8 +283,6 @@ int pa_asyncq_read_before_poll(pa_asyncq *l) {
         if (pa_fdsem_before_poll(l->write_fdsem) >= 0)
             return 0;
     }
-
-    return 0;
 }
 
 void pa_asyncq_read_after_poll(pa_asyncq *l) {
@@ -303,11 +302,11 @@ void pa_asyncq_write_before_poll(pa_asyncq *l) {
 
     for (;;) {
 
-        if (flush_postq(l))
+        if (flush_postq(l, false))
             break;
 
         if (pa_fdsem_before_poll(l->read_fdsem) >= 0) {
-            l->waiting_for_post = TRUE;
+            l->waiting_for_post = true;
             break;
         }
     }
@@ -318,6 +317,6 @@ void pa_asyncq_write_after_poll(pa_asyncq *l) {
 
     if (l->waiting_for_post) {
         pa_fdsem_after_poll(l->read_fdsem);
-        l->waiting_for_post = FALSE;
+        l->waiting_for_post = false;
     }
 }