From 5bd605616966bb1de148dd2c09b3b353c87076ec Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 24 Jan 2011 14:38:13 +0000 Subject: [PATCH] DBusLoop: inline add_callback, remove_callback into their callers The watch and timeout code paths will diverge completely when we change WatchCallback * to just be a DBusWatch *, removing the benefit of having common code. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=33342 Reviewed-by: Thiago Macieira --- dbus/dbus-mainloop.c | 72 +++++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 8ce00a3..d597e1c 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -181,52 +181,6 @@ callback_unref (Callback *cb) } } -static dbus_bool_t -add_callback (DBusLoop *loop, - DBusList **list, - Callback *cb) -{ - - if (!_dbus_list_append (list, cb)) - return FALSE; - - loop->callback_list_serial += 1; - - switch (cb->type) - { - case CALLBACK_WATCH: - loop->watch_count += 1; - break; - case CALLBACK_TIMEOUT: - loop->timeout_count += 1; - break; - } - - return TRUE; -} - -static void -remove_callback (DBusLoop *loop, - DBusList **list, - DBusList *link) -{ - Callback *cb = link->data; - - switch (cb->type) - { - case CALLBACK_WATCH: - loop->watch_count -= 1; - break; - case CALLBACK_TIMEOUT: - loop->timeout_count -= 1; - break; - } - - callback_unref (cb); - _dbus_list_remove_link (list, link); - loop->callback_list_serial += 1; -} - DBusLoop* _dbus_loop_new (void) { @@ -282,7 +236,12 @@ _dbus_loop_add_watch (DBusLoop *loop, if (wcb == NULL) return FALSE; - if (!add_callback (loop, &loop->watches, (Callback*) wcb)) + if (_dbus_list_append (&loop->watches, wcb)) + { + loop->callback_list_serial += 1; + loop->watch_count += 1; + } + else { callback_unref ((Callback*) wcb); return FALSE; @@ -311,7 +270,10 @@ _dbus_loop_remove_watch (DBusLoop *loop, if (this->watch == watch) { - remove_callback (loop, &loop->watches, link); + _dbus_list_remove_link (&loop->watches, link); + loop->callback_list_serial += 1; + loop->watch_count -= 1; + callback_unref ((Callback *) this); return; } @@ -332,7 +294,12 @@ _dbus_loop_add_timeout (DBusLoop *loop, if (tcb == NULL) return FALSE; - if (!add_callback (loop, &loop->timeouts, (Callback*) tcb)) + if (_dbus_list_append (&loop->timeouts, tcb)) + { + loop->callback_list_serial += 1; + loop->timeout_count += 1; + } + else { callback_unref ((Callback*) tcb); return FALSE; @@ -357,8 +324,11 @@ _dbus_loop_remove_timeout (DBusLoop *loop, if (this->timeout == timeout) { - remove_callback (loop, &loop->timeouts, link); - + _dbus_list_remove_link (&loop->timeouts, link); + loop->callback_list_serial += 1; + loop->timeout_count -= 1; + callback_unref ((Callback *) this); + return; } -- 2.7.4