From c6a810377d9f208aceafaa1cc33ca8b996289129 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 --- dbus/dbus-mainloop.c | 77 ++++++++++++++++--------------------------------- 1 files changed, 25 insertions(+), 52 deletions(-) diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index df2ced5..bc11303 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -182,52 +182,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) { @@ -283,7 +237,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; @@ -312,7 +271,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,10 @@ _dbus_loop_remove_watch (DBusLoop *loop, if (this->watch == watch) { - remove_callback (loop, &loop->oom_watches, link); + _dbus_list_remove_link (&loop->oom_watches, link); + loop->callback_list_serial += 1; + loop->watch_count -= 1; + callback_unref ((Callback *) this); return; } @@ -353,7 +318,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; @@ -378,8 +348,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; } -- 1.7.2.3