]> code.delx.au - pulseaudio/commitdiff
mainloop, glib-mainloop: time_restart could cause incorrect event ordering
authorBen Brewer <benbrewer@codethink.co.uk>
Thu, 25 Jul 2013 12:44:29 +0000 (13:44 +0100)
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Tue, 29 Oct 2013 17:14:00 +0000 (19:14 +0200)
This fixes a bug where calling time_restart can leave the current event
in the cache, even though the restart scheduled the event in the future.
This would cause the event to get executed more frequently than it should.

src/pulse/glib-mainloop.c
src/pulse/mainloop.c

index bd24913b465cff0069ccf362fd897ac32e0a5c63..34f355673392839b359293cbc4ffba1e6fc6c80a 100644 (file)
@@ -328,13 +328,15 @@ static void glib_time_restart(pa_time_event*e, const struct timeval *tv) {
     if ((e->enabled = !!tv))
         e->timeval = *tv;
 
+    if (e->mainloop->cached_next_time_event == e)
+        e->mainloop->cached_next_time_event = NULL;
+
     if (e->mainloop->cached_next_time_event && e->enabled) {
         g_assert(e->mainloop->cached_next_time_event->enabled);
 
         if (pa_timeval_cmp(tv, &e->mainloop->cached_next_time_event->timeval) < 0)
             e->mainloop->cached_next_time_event = e;
-    } else if (e->mainloop->cached_next_time_event == e)
-        e->mainloop->cached_next_time_event = NULL;
+    }
 }
 
 static void glib_time_free(pa_time_event *e) {
index 60fbbb90697bacc77b3ebfd146e1bcbdf38de6a5..0e1fba0476ac5c8ed8146a90594adc46372f47ec 100644 (file)
@@ -379,13 +379,15 @@ static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
         pa_mainloop_wakeup(e->mainloop);
     }
 
+    if (e->mainloop->cached_next_time_event == e)
+        e->mainloop->cached_next_time_event = NULL;
+
     if (e->mainloop->cached_next_time_event && e->enabled) {
         pa_assert(e->mainloop->cached_next_time_event->enabled);
 
         if (t < e->mainloop->cached_next_time_event->time)
             e->mainloop->cached_next_time_event = e;
-    } else if (e->mainloop->cached_next_time_event == e)
-        e->mainloop->cached_next_time_event = NULL;
+    }
 }
 
 static void mainloop_time_free(pa_time_event *e) {