From 0955e3d45b6e992308e2d51fcbf28a9f9376f788 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Sun, 5 Apr 2009 02:13:43 +0300 Subject: Base mainloop on pa_rtclock_now() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the mainloop to monotonic based time events. Introduces 4 helper functions: pa_{context,core}_rttime_{new,restart}(), that fill correctly a timeval with the rtclock flag set if the mainloop supports it. Both mainloop-test and mainloop-test-glib works with rt and timeval based time events. PulseAudio and clients should be fully functional. This patch has received several iterations, and this one as been largely untested. Signed-off-by: Marc-André Lureau --- src/modules/module-suspend-on-idle.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/modules/module-suspend-on-idle.c') diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c index c5b78911..70a7b049 100644 --- a/src/modules/module-suspend-on-idle.c +++ b/src/modules/module-suspend-on-idle.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -75,11 +76,11 @@ struct device_info { struct userdata *userdata; pa_sink *sink; pa_source *source; - struct timeval last_use; + pa_usec_t last_use; pa_time_event *time_event; }; -static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { +static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) { struct device_info *d = userdata; pa_assert(d); @@ -98,22 +99,20 @@ static void timeout_cb(pa_mainloop_api*a, pa_time_event* e, const struct timeval } static void restart(struct device_info *d) { - struct timeval tv; + pa_usec_t now; const char *s; uint32_t timeout; + pa_assert(d); pa_assert(d->sink || d->source); - pa_gettimeofday(&tv); - d->last_use = tv; + d->last_use = now = pa_rtclock_now(); s = pa_proplist_gets(d->sink ? d->sink->proplist : d->source->proplist, "module-suspend-on-idle.timeout"); if (!s || pa_atou(s, &timeout) < 0) - timeout = d->userdata->timeout; - - pa_timeval_add(&tv, timeout * PA_USEC_PER_SEC); + timeout = d->userdata->timeout; - d->userdata->core->mainloop->time_restart(d->time_event, &tv); + pa_core_rttime_restart(d->userdata->core, d->time_event, now + timeout * PA_USEC_PER_SEC); if (d->sink) pa_log_debug("Sink %s becomes idle, timeout in %u seconds.", d->sink->name, timeout); @@ -338,7 +337,7 @@ static pa_hook_result_t device_new_hook_cb(pa_core *c, pa_object *o, struct user d->userdata = u; d->source = source ? pa_source_ref(source) : NULL; d->sink = sink ? pa_sink_ref(sink) : NULL; - d->time_event = c->mainloop->time_new(c->mainloop, NULL, timeout_cb, d); + d->time_event = pa_core_rttime_new(c, PA_USEC_INVALID, timeout_cb, d); pa_hashmap_put(u->device_infos, o, d); if ((d->sink && pa_sink_check_suspend(d->sink) <= 0) || -- cgit