From 69b6ed4ec10571dcf3c7311539489215cba718f6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 25 Jan 2011 12:37:01 +0000 Subject: [PATCH 08/11] DBusLoop: move OOM flag in watches inside the DBusWatch This will eventually let us maintain a DBusPollFD[] of just the active watches, between several iterations. The more immediate benefit is that WatchCallback can go away, because it only contains a refcount, a now-useless type, and a watch that already has its own refcount. This doesn't take any more memory for DBusWatch when not using DBusLoop (e.g. in client/service code or bindings), because we're just using more bits in an existing bitfield. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=33342 --- dbus/dbus-mainloop.c | 14 ++++++-------- dbus/dbus-watch.c | 14 ++++++++++++++ dbus/dbus-watch.h | 4 ++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 5406556..8ce00a3 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -111,8 +111,6 @@ typedef struct { Callback callback; DBusWatch *watch; - /* last watch handle failed due to OOM */ - unsigned int last_iteration_oom : 1; } WatchCallback; typedef struct @@ -136,7 +134,6 @@ watch_callback_new (DBusWatch *watch) return NULL; cb->watch = watch; - cb->last_iteration_oom = FALSE; cb->callback.refcount = 1; cb->callback.type = CALLBACK_WATCH; @@ -593,12 +590,12 @@ _dbus_loop_iterate (DBusLoop *loop, wcb = WATCH_CALLBACK (cb); fd = dbus_watch_get_socket (wcb->watch); - if (wcb->last_iteration_oom) + if (_dbus_watch_get_oom_last_time (wcb->watch)) { /* we skip this one this time, but reenable it next time, * and have a timeout on this iteration */ - wcb->last_iteration_oom = FALSE; + _dbus_watch_set_oom_last_time (wcb->watch, FALSE); oom_watch_pending = TRUE; retval = TRUE; /* return TRUE here to keep the loop going, @@ -817,11 +814,12 @@ _dbus_loop_iterate (DBusLoop *loop, oom = !dbus_watch_handle (wcb->watch, condition); if (oom) - wcb->last_iteration_oom = TRUE; + { + _dbus_watch_set_oom_last_time (wcb->watch, TRUE); + } #if MAINLOOP_SPEW - _dbus_verbose (" Invoked watch, oom = %d\n", - wcb->last_iteration_oom); + _dbus_verbose (" Invoked watch, oom = %d\n", oom); #endif retval = TRUE; diff --git a/dbus/dbus-watch.c b/dbus/dbus-watch.c index f4a5820..b9f4ac2 100644 --- a/dbus/dbus-watch.c +++ b/dbus/dbus-watch.c @@ -50,6 +50,7 @@ struct DBusWatch void *data; /**< Application data. */ DBusFreeFunction free_data_function; /**< Free the application data. */ unsigned int enabled : 1; /**< Whether it's enabled. */ + unsigned int oom_last_time : 1; /**< Whether it was OOM last time. */ }; dbus_bool_t @@ -58,6 +59,19 @@ _dbus_watch_get_enabled (DBusWatch *watch) return watch->enabled; } +dbus_bool_t +_dbus_watch_get_oom_last_time (DBusWatch *watch) +{ + return watch->oom_last_time; +} + +void +_dbus_watch_set_oom_last_time (DBusWatch *watch, + dbus_bool_t oom) +{ + watch->oom_last_time = oom; +} + /** * Creates a new DBusWatch. Used to add a file descriptor to be polled * by a main loop. diff --git a/dbus/dbus-watch.h b/dbus/dbus-watch.h index fa953ec..dd23b86 100644 --- a/dbus/dbus-watch.h +++ b/dbus/dbus-watch.h @@ -76,6 +76,10 @@ void _dbus_watch_list_toggle_watch (DBusWatchList *watch_li dbus_bool_t enabled); dbus_bool_t _dbus_watch_get_enabled (DBusWatch *watch); +dbus_bool_t _dbus_watch_get_oom_last_time (DBusWatch *watch); +void _dbus_watch_set_oom_last_time (DBusWatch *watch, + dbus_bool_t oom); + /** @} */ DBUS_END_DECLS -- 1.7.2.3