[pulseaudio-discuss] [PATCH] mainloop: Run defer events in the order they are created

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Tue Mar 18 01:23:15 PDT 2014


module-zeroconf-publish assumes that if it creates two defer events,
then the one that was created first will be dispatched first. That's
a fair assumption in my opinion, so let's fix the ordering in
pa_mainloop.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=76184
---
 src/pulse/mainloop.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 66a1475..e5fbc66 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -98,6 +98,7 @@ struct pa_mainloop {
     PA_LLIST_HEAD(pa_io_event, io_events);
     PA_LLIST_HEAD(pa_time_event, time_events);
     PA_LLIST_HEAD(pa_defer_event, defer_events);
+    pa_defer_event *defer_events_tail;
 
     unsigned n_enabled_defer_events, n_enabled_time_events, n_io_events;
     unsigned io_events_please_scan, time_events_please_scan, defer_events_please_scan;
@@ -245,7 +246,8 @@ static pa_defer_event* mainloop_defer_new(
     e->callback = callback;
     e->userdata = userdata;
 
-    PA_LLIST_PREPEND(pa_defer_event, m->defer_events, e);
+    PA_LLIST_INSERT_AFTER(pa_defer_event, m->defer_events, m->defer_events_tail, e);
+    m->defer_events_tail = e;
 
     pa_mainloop_wakeup(e->mainloop);
 
@@ -547,6 +549,9 @@ static void cleanup_defer_events(pa_mainloop *m, bool force) {
             break;
 
         if (force || e->dead) {
+            if (e == m->defer_events_tail)
+                m->defer_events_tail = e->prev;
+
             PA_LLIST_REMOVE(pa_defer_event, m->defer_events, e);
 
             if (e->dead) {
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list