]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/thread-mq.c
Remove pa_bool_t and replace it with bool.
[pulseaudio] / src / pulsecore / thread-mq.c
index 34f92a7e39040fe2fe010638a44f5793f1e9de82..dd84c9af95c39957e5a3335a24bb44552f660e38 100644 (file)
 #include <unistd.h>
 #include <errno.h>
 
-#include <pulse/xmalloc.h>
-
-#include <pulsecore/atomic.h>
-#include <pulsecore/once.h>
-#include <pulsecore/log.h>
 #include <pulsecore/thread.h>
 #include <pulsecore/semaphore.h>
 #include <pulsecore/macro.h>
-#include <pulsecore/core-util.h>
-#include <pulsecore/flist.h>
 
 #include "thread-mq.h"
 
@@ -49,7 +42,7 @@ static void asyncmsgq_read_cb(pa_mainloop_api*api, pa_io_event* e, int fd, pa_io
     pa_assert(events == PA_IO_EVENT_INPUT);
 
     pa_asyncmsgq_ref(aq = q->outq);
-    pa_asyncmsgq_write_after_poll(aq);
+    pa_asyncmsgq_read_after_poll(aq);
 
     for (;;) {
         pa_msgobject *object;
@@ -59,7 +52,7 @@ static void asyncmsgq_read_cb(pa_mainloop_api*api, pa_io_event* e, int fd, pa_io
         pa_memchunk chunk;
 
         /* Check whether there is a message for us to process */
-        while (pa_asyncmsgq_get(aq, &object, &code, &data, &offset, &chunk, 0) == 0) {
+        while (pa_asyncmsgq_get(aq, &object, &code, &data, &offset, &chunk, 0) >= 0) {
             int ret;
 
             ret = pa_asyncmsgq_dispatch(object, code, data, offset, &chunk);
@@ -104,6 +97,15 @@ void pa_thread_mq_init(pa_thread_mq *q, pa_mainloop_api *mainloop, pa_rtpoll *rt
 void pa_thread_mq_done(pa_thread_mq *q) {
     pa_assert(q);
 
+    /* Since we are called from main context we can be sure that the
+     * inq is empty. However, the outq might still contain messages
+     * for the main loop, which we need to dispatch (e.g. release
+     * msgs, other stuff). Hence do so if we aren't currently
+     * dispatching anyway. */
+
+    if (!pa_asyncmsgq_dispatching(q->outq))
+        pa_asyncmsgq_flush(q->outq, true);
+
     q->mainloop->io_free(q->read_event);
     q->mainloop->io_free(q->write_event);
     q->read_event = q->write_event = NULL;