]> code.delx.au - pulseaudio/blobdiff - src/pulse/mainloop.c
Fix up according to Coding Style
[pulseaudio] / src / pulse / mainloop.c
index 62659d89e2dd2eaa908d0d14aa9232b028194497..8c261381b42ad9cb212ad87dfcd4bcf627b10059 100644 (file)
 #include <fcntl.h>
 #include <errno.h>
 
-#ifdef HAVE_POLL_H
-#include <poll.h>
-#else
-#include <pulsecore/poll.h>
-#endif
-
 #ifndef HAVE_PIPE
 #include <pulsecore/pipe.h>
 #endif
 #include <pulse/timeval.h>
 #include <pulse/xmalloc.h>
 
+#include <pulsecore/poll.h>
 #include <pulsecore/core-rtclock.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/llist.h>
 #include <pulsecore/log.h>
 #include <pulsecore/core-error.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
 #include <pulsecore/macro.h>
 
 #include "mainloop.h"
@@ -78,6 +73,7 @@ struct pa_time_event {
     pa_bool_t dead:1;
 
     pa_bool_t enabled:1;
+    pa_bool_t use_rtclock:1;
     pa_usec_t time;
 
     pa_time_event_cb_t callback;
@@ -315,19 +311,23 @@ static void mainloop_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy
 }
 
 /* Time events */
-static pa_usec_t make_rt(const struct timeval *tv) {
+static pa_usec_t make_rt(const struct timeval *tv, pa_bool_t *use_rtclock) {
     struct timeval ttv;
 
-    if (!tv)
+    if (!tv) {
+        *use_rtclock = FALSE;
         return PA_USEC_INVALID;
+    }
+
+    ttv = *tv;
+    *use_rtclock = !!(ttv.tv_usec & PA_TIMEVAL_RTCLOCK);
 
-    if (tv->tv_usec & PA_TIMEVAL_RTCLOCK) {
-        ttv = *tv;
+    if (*use_rtclock)
         ttv.tv_usec &= ~PA_TIMEVAL_RTCLOCK;
-        tv = pa_rtclock_from_wallclock(&ttv);
-    }
+    else
+        pa_rtclock_from_wallclock(&ttv);
 
-    return pa_timeval_load(tv);
+    return pa_timeval_load(&ttv);
 }
 
 static pa_time_event* mainloop_time_new(
@@ -339,12 +339,13 @@ static pa_time_event* mainloop_time_new(
     pa_mainloop *m;
     pa_time_event *e;
     pa_usec_t t;
+    pa_bool_t use_rtclock = FALSE;
 
     pa_assert(a);
     pa_assert(a->userdata);
     pa_assert(callback);
 
-    t = make_rt(tv);
+    t = make_rt(tv, &use_rtclock);
 
     m = a->userdata;
     pa_assert(a == &m->api);
@@ -354,6 +355,7 @@ static pa_time_event* mainloop_time_new(
 
     if ((e->enabled = (t != PA_USEC_INVALID))) {
         e->time = t;
+        e->use_rtclock= use_rtclock;
 
         m->n_enabled_time_events++;
 
@@ -379,11 +381,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;
+    pa_bool_t use_rtclock = FALSE;
 
     pa_assert(e);
     pa_assert(!e->dead);
 
-    t = make_rt(tv);
+    t = make_rt(tv, &use_rtclock);
 
     valid = (t != PA_USEC_INVALID);
     if (e->enabled && !valid) {
@@ -394,6 +397,7 @@ static void mainloop_time_restart(pa_time_event *e, const struct timeval *tv) {
 
     if ((e->enabled = valid)) {
         e->time = t;
+        e->use_rtclock = use_rtclock;
         pa_mainloop_wakeup(e->mainloop);
     }
 
@@ -473,7 +477,7 @@ pa_mainloop *pa_mainloop_new(void) {
 
     m = pa_xnew0(pa_mainloop, 1);
 
-    if (pipe(m->wakeup_pipe) < 0) {
+    if (pa_pipe_cloexec(m->wakeup_pipe) < 0) {
         pa_log_error("ERROR: cannot create wakeup pipe");
         pa_xfree(m);
         return NULL;
@@ -481,8 +485,6 @@ pa_mainloop *pa_mainloop_new(void) {
 
     pa_make_fd_nonblock(m->wakeup_pipe[0]);
     pa_make_fd_nonblock(m->wakeup_pipe[1]);
-    pa_make_fd_cloexec(m->wakeup_pipe[0]);
-    pa_make_fd_cloexec(m->wakeup_pipe[1]);
 
     m->rebuild_pollfds = TRUE;
 
@@ -779,7 +781,7 @@ static unsigned dispatch_timeout(pa_mainloop *m) {
             /* Disable time event */
             mainloop_time_restart(e, NULL);
 
-            e->callback(&m->api, e, pa_timeval_rtstore(&tv, e->time, FALSE), e->userdata);
+            e->callback(&m->api, e, pa_timeval_rtstore(&tv, e->time, e->use_rtclock), e->userdata);
 
             r++;
         }
@@ -880,7 +882,7 @@ int pa_mainloop_poll(pa_mainloop *m) {
                     m->prepared_timeout == PA_USEC_INVALID ? NULL : pa_timespec_store(&ts, m->prepared_timeout),
                     NULL);
 #else
-            m->poll_func_ret = poll(
+            m->poll_func_ret = pa_poll(
                     m->pollfds, m->n_pollfds,
                     usec_to_timeout(m->prepared_timeout));
 #endif