]> code.delx.au - pulseaudio/commitdiff
rtclock: fix issues found by Lennart
authorMarc-André Lureau <marcandre.lureau@gmail.com>
Sat, 20 Jun 2009 13:52:41 +0000 (16:52 +0300)
committerMarc-André Lureau <marcandre.lureau@gmail.com>
Sat, 20 Jun 2009 14:29:34 +0000 (17:29 +0300)
src/pulse/context.c
src/pulse/mainloop.c
src/pulsecore/core-rtclock.c
src/tests/mainloop-test.c

index 0c1810f379799398586bdbcd6c69f6bd1c54f2d6..b71659de2a949ad3fd0d9931d8140ece58832235 100644 (file)
@@ -54,6 +54,8 @@
 #include <pulse/utf8.h>
 #include <pulse/util.h>
 #include <pulse/i18n.h>
+#include <pulse/mainloop.h>
+#include <pulse/timeval.h>
 
 #include <pulsecore/winsock.h>
 #include <pulsecore/core-error.h>
@@ -1451,6 +1453,9 @@ pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_even
     pa_assert(c);
     pa_assert(c->mainloop);
 
+    if (usec == PA_USEC_INVALID)
+        return c->mainloop->time_new(c->mainloop, NULL, cb, userdata);
+
     pa_timeval_rtstore(&tv, usec, c->use_rtclock);
 
     return c->mainloop->time_new(c->mainloop, &tv, cb, userdata);
@@ -1462,7 +1467,10 @@ void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec)
     pa_assert(c);
     pa_assert(c->mainloop);
 
-    pa_timeval_rtstore(&tv, usec, c->use_rtclock);
-
-    c->mainloop->time_restart(e, &tv);
+    if (usec == PA_USEC_INVALID)
+        c->mainloop->time_restart(e, NULL);
+    else {
+        pa_timeval_rtstore(&tv, usec, c->use_rtclock);
+        c->mainloop->time_restart(e, &tv);
+    }
 }
index 1b779468801cf14659ccfd5410c5f200fb5d08e8..5d0e0ffc18ba7ee4094b3dab8573b33281241a4f 100644 (file)
@@ -319,19 +319,21 @@ static void mainloop_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy
 }
 
 /* Time events */
-static pa_usec_t timeval_load(struct timeval *tv) {
+static pa_usec_t timeval_load(const struct timeval *tv) {
     pa_bool_t is_rtclock;
+    struct timeval ttv;
 
     if (!tv)
         return PA_USEC_INVALID;
 
-    is_rtclock = !!(tv->tv_usec & PA_TIMEVAL_RTCLOCK);
-    tv->tv_usec &= ~PA_TIMEVAL_RTCLOCK;
+    ttv = *tv;
+    is_rtclock = !!(ttv.tv_usec & PA_TIMEVAL_RTCLOCK);
+    ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
 
     if (!is_rtclock)
-        pa_rtclock_from_wallclock(tv);
+        pa_rtclock_from_wallclock(&ttv);
 
-    return pa_timeval_load(tv);
+    return pa_timeval_load(&ttv);
 }
 
 static pa_time_event* mainloop_time_new(
@@ -343,13 +345,13 @@ static pa_time_event* mainloop_time_new(
     pa_mainloop *m;
     pa_time_event *e;
     pa_usec_t t;
-    struct timeval ttv;
 
     pa_assert(a);
     pa_assert(a->userdata);
     pa_assert(callback);
 
-    t = timeval_load(tv? ttv = *tv, &ttv : NULL);
+    t = timeval_load(tv);
+
     m = a->userdata;
     pa_assert(a == &m->api);
 
@@ -385,12 +387,12 @@ static pa_time_event* mainloop_time_new(
 static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
     pa_bool_t valid;
     pa_usec_t t;
-    struct timeval ttv;
 
     pa_assert(e);
     pa_assert(!e->dead);
 
-    t = timeval_load(tv? ttv = *tv, &ttv : NULL);
+    t = timeval_load(tv);
+
     valid = (t != PA_USEC_INVALID);
     if (e->enabled && !valid) {
         pa_assert(e->mainloop->n_enabled_time_events > 0);
index 1fa71c80a29775e0cad9e615068bae6670363378..a4a70bee2a74e79def138a902720b6ea9d8508b6 100644 (file)
@@ -176,6 +176,9 @@ static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
 struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, pa_bool_t rtclock) {
     pa_assert(tv);
 
+    if (v == PA_USEC_INVALID)
+        return NULL;
+
     pa_timeval_store(tv, v);
 
     if (rtclock)
index 55331d12038f25329776ce8f4d9e70e373b0dfb5..3ec6d1156c89c5bbc724108e1ddaf6d3c2ad1c6f 100644 (file)
@@ -31,6 +31,7 @@
 #include <pulse/gccmacro.h>
 
 #include <pulsecore/core-util.h>
+#include <pulsecore/core-rtclock.h>
 
 #ifdef GLIB_MAIN_LOOP