]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
DBusLoop: move OOM flag in watches inside the DBusWatch
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 25 Jan 2011 12:37:01 +0000 (12:37 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 13 Jun 2011 15:25:33 +0000 (16:25 +0100)
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
Reviewed-by: Thiago Macieira <thiago@kde.org>
dbus/dbus-mainloop.c
dbus/dbus-watch.c
dbus/dbus-watch.h

index 54065568fb9cdd81174f6cd1e6a1e2b164cbb0b8..8ce00a3c4bdf7cd2520d470443f9c705240dc6f1 100644 (file)
@@ -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;
index f4a5820eec547d1e2644214e696edda8462e7305..b9f4ac236fab798e9cecb5a6c1a4a8c40525056c 100644 (file)
@@ -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.
index fa953ec14824e97730d69a9aa3a3abbe53c3a2a7..dd23b862bec6e1f5f66e24a5a0f6c450e35adac3 100644 (file)
@@ -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