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

@ -64,6 +64,7 @@
#include <pulsecore/dynarray.h>
#include <pulsecore/socket-client.h>
#include <pulsecore/pstream-util.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/socket-util.h>
@ -540,7 +541,7 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c);
pa_assert(!c->pdispatch);
c->pdispatch = pa_pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX);
c->pdispatch = pa_pdispatch_new(c->mainloop, c->use_rtclock, command_table, PA_COMMAND_MAX);
if (!c->conf->cookie_valid)
pa_log_info(_("No cookie loaded. Attempting to connect without."));
@ -757,7 +758,7 @@ static void track_pulseaudio_on_dbus(pa_context *c, DBusBusType type, pa_dbus_wr
pa_assert(conn);
dbus_error_init(&error);
if (!(*conn = pa_dbus_wrap_connection_new(c->mainloop, type, &error)) || dbus_error_is_set(&error)) {
if (!(*conn = pa_dbus_wrap_connection_new(c->mainloop, c->use_rtclock, type, &error)) || dbus_error_is_set(&error)) {
pa_log_warn("Unable to contact DBUS: %s: %s", error.name, error.message);
goto finish;
}
@ -827,7 +828,7 @@ static int try_next_connection(pa_context *c) {
pa_xfree(c->server);
c->server = pa_xstrdup(u);
if (!(c->client = pa_socket_client_new_string(c->mainloop, u, PA_NATIVE_DEFAULT_PORT)))
if (!(c->client = pa_socket_client_new_string(c->mainloop, c->use_rtclock, u, PA_NATIVE_DEFAULT_PORT)))
continue;
c->is_local = !!pa_socket_client_is_local(c->client);
@ -1443,3 +1444,25 @@ finish:
if (pl)
pa_proplist_free(pl);
}
pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) {
struct timeval tv;
pa_assert(c);
pa_assert(c->mainloop);
pa_timeval_rtstore(&tv, usec, c->use_rtclock);
return c->mainloop->time_new(c->mainloop, &tv, cb, userdata);
}
void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec) {
struct timeval tv;
pa_assert(c);
pa_assert(c->mainloop);
pa_timeval_rtstore(&tv, usec, c->use_rtclock);
c->mainloop->time_restart(e, &tv);
}