Base mainloop on pa_rtclock_now()

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 <marca-andre.lureau@nokia.com>
This commit is contained in:
Marc-André Lureau 2009-04-05 02:13:43 +03:00 committed by Marc-André Lureau
parent 125c528896
commit 0955e3d45b
42 changed files with 311 additions and 233 deletions

View file

@ -320,14 +320,10 @@ static void request_auto_timing_update(pa_stream *s, pa_bool_t force) {
}
if (s->auto_timing_update_event) {
struct timeval next;
if (force)
s->auto_timing_interval_usec = AUTO_TIMING_INTERVAL_START_USEC;
pa_gettimeofday(&next);
pa_timeval_add(&next, s->auto_timing_interval_usec);
s->mainloop->time_restart(s->auto_timing_update_event, &next);
pa_context_rttime_restart(s->context, s->auto_timing_update_event, pa_rtclock_now() + s->auto_timing_interval_usec);
s->auto_timing_interval_usec = PA_MIN(AUTO_TIMING_INTERVAL_END_USEC, s->auto_timing_interval_usec*2);
}
@ -801,7 +797,7 @@ static void invalidate_indexes(pa_stream *s, pa_bool_t r, pa_bool_t w) {
request_auto_timing_update(s, TRUE);
}
static void auto_timing_update_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) {
static void auto_timing_update_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
pa_stream *s = userdata;
pa_assert(s);
@ -823,12 +819,9 @@ static void create_stream_complete(pa_stream *s) {
s->write_callback(s, (size_t) s->requested_bytes, s->write_userdata);
if (s->flags & PA_STREAM_AUTO_TIMING_UPDATE) {
struct timeval tv;
pa_gettimeofday(&tv);
s->auto_timing_interval_usec = AUTO_TIMING_INTERVAL_START_USEC;
pa_timeval_add(&tv, s->auto_timing_interval_usec);
pa_assert(!s->auto_timing_update_event);
s->auto_timing_update_event = s->mainloop->time_new(s->mainloop, &tv, &auto_timing_update_callback, s);
s->auto_timing_update_event = pa_context_rttime_new(s->context, pa_rtclock_now() + s->auto_timing_interval_usec, &auto_timing_update_callback, s);
request_auto_timing_update(s, TRUE);
}