diff options
Diffstat (limited to 'dbus/dbus-memory.c')
-rw-r--r-- | dbus/dbus-memory.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index fbda7139..8efbec59 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -633,13 +633,17 @@ dbus_free_string_array (char **str_array) */ int _dbus_current_generation = 1; -static DBusList *registered_globals = NULL; +typedef struct ShutdownClosure ShutdownClosure; -typedef struct +struct ShutdownClosure { + ShutdownClosure *next; DBusShutdownFunction func; void *data; -} ShutdownClosure; +}; + +_DBUS_DEFINE_GLOBAL_LOCK (shutdown_funcs); +static ShutdownClosure *registered_globals = NULL; /** * The D-BUS library keeps some internal global variables, for example @@ -656,22 +660,18 @@ typedef struct void dbus_shutdown (void) { - DBusList *link; - - link = _dbus_list_get_first_link (®istered_globals); - while (link != NULL) + while (registered_globals != NULL) { - ShutdownClosure *c = link->data; + ShutdownClosure *c; + c = registered_globals; + registered_globals = c->next; + (* c->func) (c->data); - - dbus_free (c); - link = _dbus_list_get_next_link (®istered_globals, link); + dbus_free (c); } - _dbus_list_clear (®istered_globals); - _dbus_current_generation += 1; } @@ -693,20 +693,17 @@ _dbus_register_shutdown_func (DBusShutdownFunction func, if (c == NULL) return FALSE; - + c->func = func; c->data = data; - /* We prepend, then shutdown the list in order, so - * we shutdown last-registered stuff first which - * is right. - */ - if (!_dbus_list_prepend (®istered_globals, c)) - { - dbus_free (c); - return FALSE; - } + _DBUS_LOCK (shutdown_funcs); + + c->next = registered_globals; + registered_globals = c; + _DBUS_UNLOCK (shutdown_funcs); + return TRUE; } |