X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-resources.c;h=80fb55b2fa2f6a2c24182838f00400ebb221346d;hb=f1ac953748097685a8a7452d9dfe4bdd65192542;hp=d7346d6f6185aa050e23eff967fe1e24bbeb6568;hpb=feb31a33219bc0640c00138c14774995ab1a65a8;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-resources.c b/dbus/dbus-resources.c index d7346d6..80fb55b 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 */ @@ -88,24 +89,12 @@ _dbus_counter_new (void) { DBusCounter *counter; - counter = dbus_new (DBusCounter, 1); + counter = dbus_new0 (DBusCounter, 1); if (counter == NULL) return NULL; - - counter->refcount = 1; - counter->size_value = 0; - counter->unix_fd_value = 0; -#ifdef DBUS_ENABLE_STATS - counter->peak_size_value = 0; - counter->peak_unix_fd_value = 0; -#endif + counter->refcount = 1; - counter->notify_size_guard_value = 0; - counter->notify_unix_fd_guard_value = 0; - counter->notify_function = NULL; - counter->notify_data = NULL; - return counter; } @@ -148,8 +137,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 +167,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 +221,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 +270,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