#include <pulsecore/macro.h>
#include "mainloop.h"
+#include "internal.h"
struct pa_io_event {
pa_mainloop *mainloop;
}
/* 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(
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);
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);
static const pa_mainloop_api vtable = {
.userdata = NULL,
- .io_new= mainloop_io_new,
- .io_enable= mainloop_io_enable,
- .io_free= mainloop_io_free,
- .io_set_destroy= mainloop_io_set_destroy,
+ .io_new = mainloop_io_new,
+ .io_enable = mainloop_io_enable,
+ .io_free = mainloop_io_free,
+ .io_set_destroy = mainloop_io_set_destroy,
.time_new = mainloop_time_new,
.time_restart = mainloop_time_restart,
static int calc_next_timeout(pa_mainloop *m) {
pa_time_event *t;
- pa_usec_t usec;
+ pa_usec_t clock_now;
if (!m->n_enabled_time_events)
return -1;
- t = find_next_time_event(m);
- pa_assert(t);
+ pa_assert_se(t = find_next_time_event(m));
- if (t->time == 0)
+ if (t->time <= 0)
return 0;
- usec = t->time - pa_rtclock_now();
+ clock_now = pa_rtclock_now();
- if (usec <= 0)
+ if (t->time <= clock_now)
return 0;
- return (int) (usec / 1000); /* in milliseconds */
+ return (int) ((t->time - clock_now) / 1000); /* in milliseconds */
}
static int dispatch_timeout(pa_mainloop *m) {
m->poll_func = poll_func;
m->poll_func_userdata = userdata;
}
+
+pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m) {
+ pa_assert(m);
+
+ return m->io_new == mainloop_io_new;
+}