From 442600c342041bbbe3cff39042e366f9a34242a9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 24 Jan 2011 15:30:02 +0000 Subject: [PATCH] DBusLoop: fold Callback into TimeoutCallback Bug: https://bugs.freedesktop.org/show_bug.cgi?id=33342 --- dbus/dbus-mainloop.c | 42 ++++++++++-------------------------------- 1 files changed, 10 insertions(+), 32 deletions(-) diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 029e1cd..6048d1f 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -96,21 +96,9 @@ watch_flags_from_poll_revents (short revents) return condition; } -typedef enum -{ - CALLBACK_WATCH, - CALLBACK_TIMEOUT -} CallbackType; - typedef struct { int refcount; - CallbackType type; -} Callback; - -typedef struct -{ - Callback callback; DBusTimeout *timeout; unsigned long last_tv_sec; unsigned long last_tv_usec; @@ -130,14 +118,12 @@ timeout_callback_new (DBusTimeout *timeout) cb->timeout = timeout; _dbus_get_current_time (&cb->last_tv_sec, &cb->last_tv_usec); - cb->callback.refcount = 1; - cb->callback.type = CALLBACK_TIMEOUT; - + cb->refcount = 1; return cb; } -static Callback * -callback_ref (Callback *cb) +static TimeoutCallback * +timeout_callback_ref (TimeoutCallback *cb) { _dbus_assert (cb->refcount > 0); @@ -147,7 +133,7 @@ callback_ref (Callback *cb) } static void -callback_unref (Callback *cb) +timeout_callback_unref (TimeoutCallback *cb) { _dbus_assert (cb->refcount > 0); @@ -292,7 +278,7 @@ _dbus_loop_add_timeout (DBusLoop *loop, } else { - callback_unref ((Callback*) tcb); + timeout_callback_unref (tcb); return FALSE; } @@ -311,14 +297,12 @@ _dbus_loop_remove_timeout (DBusLoop *loop, DBusList *next = _dbus_list_get_next_link (&loop->timeouts, link); TimeoutCallback *this = link->data; - _dbus_assert (this->callback.type == CALLBACK_TIMEOUT); - if (this->timeout == timeout) { _dbus_list_remove_link (&loop->timeouts, link); loop->callback_list_serial += 1; loop->timeout_count -= 1; - callback_unref ((Callback *) this); + timeout_callback_unref (this); return; } @@ -611,13 +595,10 @@ _dbus_loop_iterate (DBusLoop *loop, while (link != NULL) { DBusList *next = _dbus_list_get_next_link (&loop->timeouts, link); - Callback *cb = link->data; + TimeoutCallback *tcb = link->data; - _dbus_assert (cb->type == CALLBACK_TIMEOUT); - - if (dbus_timeout_get_enabled (TIMEOUT_CALLBACK (cb)->timeout)) + if (dbus_timeout_get_enabled (tcb->timeout)) { - TimeoutCallback *tcb = TIMEOUT_CALLBACK (cb); int msecs_remaining; check_timeout (tv_sec, tv_usec, tcb, &msecs_remaining); @@ -683,7 +664,7 @@ _dbus_loop_iterate (DBusLoop *loop, while (link != NULL) { DBusList *next = _dbus_list_get_next_link (&loop->timeouts, link); - Callback *cb = link->data; + TimeoutCallback *tcb = link->data; if (initial_serial != loop->callback_list_serial) goto next_iteration; @@ -691,11 +672,8 @@ _dbus_loop_iterate (DBusLoop *loop, if (loop->depth != orig_depth) goto next_iteration; - _dbus_assert (cb->type == CALLBACK_TIMEOUT); - - if (dbus_timeout_get_enabled (TIMEOUT_CALLBACK (cb)->timeout)) + if (dbus_timeout_get_enabled (tcb->timeout)) { - TimeoutCallback *tcb = TIMEOUT_CALLBACK (cb); int msecs_remaining; if (check_timeout (tv_sec, tv_usec, -- 1.7.2.3