]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/asyncq.c
Merge branch 'master' of git://0pointer.de/pulseaudio into dbus-work
[pulseaudio] / src / pulsecore / asyncq.c
index 34506e496735c230521b6c7fba983feca381de2f..072ef02cc3a135e405200cc0c54d8bfa8b8f5a4a 100644 (file)
@@ -1,9 +1,7 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
-  Copyright 2006 Lennart Poettering
+  Copyright 2006-2008 Lennart Poettering
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
@@ -40,9 +38,9 @@
 #include "asyncq.h"
 #include "fdsem.h"
 
-#define ASYNCQ_SIZE 128
+#define ASYNCQ_SIZE 256
 
-/* For debugging purposes we can define _Y to put and extra thread
+/* For debugging purposes we can define _Y to put an extra thread
  * yield between each operation. */
 
 /* #define PROFILE */
@@ -73,11 +71,7 @@ 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 is_power_of_two(unsigned size) {
-    return !(size & (size - 1));
-}
-
-static int reduce(pa_asyncq *l, int value) {
+static unsigned reduce(pa_asyncq *l, unsigned value) {
     return value & (unsigned) (l->size - 1);
 }
 
@@ -87,7 +81,7 @@ pa_asyncq *pa_asyncq_new(unsigned size) {
     if (!size)
         size = ASYNCQ_SIZE;
 
-    pa_assert(is_power_of_two(size));
+    pa_assert(pa_is_power_of_two(size));
 
     l = pa_xmalloc0(PA_ALIGN(sizeof(pa_asyncq)) + (sizeof(pa_atomic_ptr_t) * size));
 
@@ -137,8 +131,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, pa_bool_t wait_op) {
+    unsigned idx;
     pa_atomic_ptr_t *cells;
 
     pa_assert(l);
@@ -151,7 +145,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"); */
@@ -169,14 +163,14 @@ static int push(pa_asyncq*l, void *p, pa_bool_t wait) {
     return 0;
 }
 
-static pa_bool_t flush_postq(pa_asyncq *l) {
+static pa_bool_t flush_postq(pa_asyncq *l, pa_bool_t wait_op) {
     struct localq *q;
 
     pa_assert(l);
 
     while ((q = l->last_localq)) {
 
-        if (push(l, q->data, FALSE) < 0)
+        if (push(l, q->data, wait_op) < 0)
             return FALSE;
 
         l->last_localq = q->prev;
@@ -190,13 +184,13 @@ static pa_bool_t flush_postq(pa_asyncq *l) {
     return TRUE;
 }
 
-int pa_asyncq_push(pa_asyncq*l, void *p, pa_bool_t wait) {
+int pa_asyncq_push(pa_asyncq*l, void *p, pa_bool_t 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) {
@@ -205,13 +199,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("q overrun, queuing locally");
 
     if (!(q = pa_flist_pop(PA_STATIC_FLIST_GET(localq))))
         q = pa_xnew(struct localq, 1);
@@ -225,8 +221,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, pa_bool_t wait_op) {
+    unsigned idx;
     void *ret;
     pa_atomic_ptr_t *cells;
 
@@ -239,7 +235,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"); */
@@ -269,7 +265,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);
@@ -286,8 +282,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) {
@@ -307,7 +301,7 @@ 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) {