From bc86794f23fa538a405813fb61b531c2eacc9ae1 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 31 Mar 2003 04:01:00 +0000 Subject: 2003-03-30 Havoc Pennington * bus/config-parser.c: hacking * dbus/dbus-memory.c: don't use DBusList for the list of stuff to shut down, since it could cause weirdness with the DBusList lock * dbus/dbus-list.c (_dbus_list_test): add tests for the link-oriented stack routines (alloc_link): free the mempool if the first alloc from it fails * dbus/dbus-mempool.c (struct DBusMemBlock): fix alignment issue * dbus/dbus-string.c (UNICODE_VALID): sync new version of this from GLib (_dbus_string_skip_white): new * doc/config-file.txt (Elements): add --- dbus/dbus-memory.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'dbus/dbus-memory.c') 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; } -- cgit