summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-02-23 12:45:53 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-07-28 18:23:23 +0100
commit0688924ed21a7a0d975b9e01c39d059a18738b86 (patch)
tree2d687d66e26c685555b3ebed3d10ef2add91b2dd
parent429573e69a6bd1f579a217c3dc1b8a97b57f4c09 (diff)
downloaddbus-0688924ed21a7a0d975b9e01c39d059a18738b86.tar.gz
Add _dbus_counter_notify and call it after every adjustment
When fd-passing is implemented, adjustments happen in pairs; in that case we coalesce the two calls into one. Reviewed-by: Colin Walters <walters@verbum.org> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
-rw-r--r--dbus/dbus-message.c4
-rw-r--r--dbus/dbus-resources.c35
-rw-r--r--dbus/dbus-resources.h1
3 files changed, 34 insertions, 6 deletions
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index dcb8d082..92c8325c 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -254,6 +254,8 @@ _dbus_message_add_counter_link (DBusMessage *message,
#ifdef HAVE_UNIX_FD_PASSING
_dbus_counter_adjust_unix_fd (link->data, message->unix_fd_counter_delta);
#endif
+
+ _dbus_counter_notify (link->data);
}
/**
@@ -313,6 +315,7 @@ _dbus_message_remove_counter (DBusMessage *message,
_dbus_counter_adjust_unix_fd (counter, - message->unix_fd_counter_delta);
#endif
+ _dbus_counter_notify (counter);
_dbus_counter_unref (counter);
}
@@ -575,6 +578,7 @@ free_counter (void *element,
_dbus_counter_adjust_unix_fd (counter, - message->unix_fd_counter_delta);
#endif
+ _dbus_counter_notify (counter);
_dbus_counter_unref (counter);
}
diff --git a/dbus/dbus-resources.c b/dbus/dbus-resources.c
index d7346d6f..42aedf58 100644
--- a/dbus/dbus-resources.c
+++ b/dbus/dbus-resources.c
@@ -68,6 +68,7 @@ struct DBusCounter
DBusCounterNotifyFunction notify_function; /**< notify function */
void *notify_data; /**< data for notify function */
+ dbus_bool_t notify_pending : 1; /**< TRUE if the guard value has been crossed */
};
/** @} */ /* end of resource limits internals docs */
@@ -105,6 +106,7 @@ _dbus_counter_new (void)
counter->notify_unix_fd_guard_value = 0;
counter->notify_function = NULL;
counter->notify_data = NULL;
+ counter->notify_pending = FALSE;
return counter;
}
@@ -148,8 +150,9 @@ _dbus_counter_unref (DBusCounter *counter)
/**
* Adjusts the value of the size counter by the given
* delta which may be positive or negative.
- * Calls the notify function from _dbus_counter_set_notify()
- * if that function has been specified.
+ *
+ * This function may be called with locks held. After calling it, when
+ * any relevant locks are no longer held you must call _dbus_counter_notify().
*
* @param counter the counter
* @param delta value to add to the size counter's current value
@@ -177,14 +180,33 @@ _dbus_counter_adjust_size (DBusCounter *counter,
counter->size_value >= counter->notify_size_guard_value) ||
(old >= counter->notify_size_guard_value &&
counter->size_value < counter->notify_size_guard_value)))
- (* counter->notify_function) (counter, counter->notify_data);
+ counter->notify_pending = TRUE;
+}
+
+/**
+ * Calls the notify function from _dbus_counter_set_notify(),
+ * if that function has been specified and the counter has crossed the
+ * guard value (in either direction) since the last call to this function.
+ *
+ * This function must not be called with locks held, since it can call out
+ * to user code.
+ */
+void
+_dbus_counter_notify (DBusCounter *counter)
+{
+ if (counter->notify_pending)
+ {
+ counter->notify_pending = FALSE;
+ (* counter->notify_function) (counter, counter->notify_data);
+ }
}
/**
* Adjusts the value of the unix fd counter by the given
* delta which may be positive or negative.
- * Calls the notify function from _dbus_counter_set_notify()
- * if that function has been specified.
+ *
+ * This function may be called with locks held. After calling it, when
+ * any relevant locks are no longer held you must call _dbus_counter_notify().
*
* @param counter the counter
* @param delta value to add to the unix fds counter's current value
@@ -212,7 +234,7 @@ _dbus_counter_adjust_unix_fd (DBusCounter *counter,
counter->unix_fd_value >= counter->notify_unix_fd_guard_value) ||
(old >= counter->notify_unix_fd_guard_value &&
counter->unix_fd_value < counter->notify_unix_fd_guard_value)))
- (* counter->notify_function) (counter, counter->notify_data);
+ counter->notify_pending = TRUE;
}
/**
@@ -261,6 +283,7 @@ _dbus_counter_set_notify (DBusCounter *counter,
counter->notify_unix_fd_guard_value = unix_fd_guard_value;
counter->notify_function = function;
counter->notify_data = user_data;
+ counter->notify_pending = FALSE;
}
#ifdef DBUS_ENABLE_STATS
diff --git a/dbus/dbus-resources.h b/dbus/dbus-resources.h
index ebbdce97..781a5756 100644
--- a/dbus/dbus-resources.h
+++ b/dbus/dbus-resources.h
@@ -42,6 +42,7 @@ void _dbus_counter_adjust_size (DBusCounter *counter,
long delta);
void _dbus_counter_adjust_unix_fd (DBusCounter *counter,
long delta);
+void _dbus_counter_notify (DBusCounter *counter);
long _dbus_counter_get_size_value (DBusCounter *counter);
long _dbus_counter_get_unix_fd_value (DBusCounter *counter);