#endif
#include <stdio.h>
-#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
-#include <string.h>
#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/i18n.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
+#include <pulsecore/poll.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/i18n.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"
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;
/* IO events */
static pa_io_event* mainloop_io_new(
- pa_mainloop_api*a,
+ pa_mainloop_api *a,
int fd,
pa_io_event_flags_t events,
pa_io_event_cb_t callback,
FD_ZERO (&xset);
FD_SET (fd, &xset);
- if ((select((SELECT_TYPE_ARG1) fd, NULL, NULL, SELECT_TYPE_ARG234 &xset,
- SELECT_TYPE_ARG5 &tv) == -1) &&
- (WSAGetLastError() == WSAENOTSOCK)) {
+ if ((select(fd, NULL, NULL, &xset, &tv) == -1) && (WSAGetLastError() == WSAENOTSOCK)) {
pa_log_warn("Cannot monitor non-socket file descriptors.");
e->dead = TRUE;
}
/* Defer events */
static pa_defer_event* mainloop_defer_new(
- pa_mainloop_api*a,
+ pa_mainloop_api *a,
pa_defer_event_cb_t callback,
void *userdata) {
}
/* 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;
+ }
- if (tv->tv_usec & PA_TIMEVAL_RTCLOCK) {
- ttv = *tv;
+ ttv = *tv;
+ *use_rtclock = !!(ttv.tv_usec & PA_TIMEVAL_RTCLOCK);
+
+ 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(
- pa_mainloop_api*a,
+ pa_mainloop_api *a,
const struct timeval *tv,
pa_time_event_cb_t callback,
void *userdata) {
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);
if ((e->enabled = (t != PA_USEC_INVALID))) {
e->time = t;
+ e->use_rtclock = use_rtclock;
m->n_enabled_time_events++;
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) {
if ((e->enabled = valid)) {
e->time = t;
+ e->use_rtclock = use_rtclock;
pa_mainloop_wakeup(e->mainloop);
}
/* quit() */
-static void mainloop_quit(pa_mainloop_api*a, int retval) {
+static void mainloop_quit(pa_mainloop_api *a, int retval) {
pa_mainloop *m;
pa_assert(a);
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;
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;
}
-void pa_mainloop_free(pa_mainloop* m) {
+void pa_mainloop_free(pa_mainloop *m) {
pa_assert(m);
cleanup_io_events(m, TRUE);
/* 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++;
}
}
static int usec_to_timeout(pa_usec_t u) {
+ int timeout;
+
if (u == PA_USEC_INVALID)
return -1;
- return (u + PA_USEC_PER_MSEC - 1) / PA_USEC_PER_MSEC;
+ timeout = (u + PA_USEC_PER_MSEC - 1) / PA_USEC_PER_MSEC;
+ pa_assert(timeout >= 0);
+
+ return timeout;
}
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
pa_mainloop_wakeup(m);
}
-pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m) {
+pa_mainloop_api* pa_mainloop_get_api(pa_mainloop *m) {
pa_assert(m);
return &m->api;
m->poll_func_userdata = userdata;
}
-pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m) {
+pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api *m) {
pa_assert(m);
return m->io_new == mainloop_io_new;