diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2016-05-13 15:32:44 +0200 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2016-05-13 15:32:44 +0200 |
commit | 8c0d59802996446ff0accdacee8dfe3f4522eb71 (patch) | |
tree | 5d231dad5e8b622e424330e56790ad5641386645 | |
parent | 7f7a6fdb1d9dff1605aa8f568111b879be713f7d (diff) | |
parent | baeea825a4a84858f7df2755853e0b7d2d2c91e7 (diff) |
Merge branch 'dbus-1.10'
-rw-r--r-- | dbus/dbus-internals.h | 1 | ||||
-rw-r--r-- | dbus/dbus-spawn-win.c | 43 | ||||
-rw-r--r-- | dbus/dbus-sysdeps.h | 3 |
3 files changed, 38 insertions, 9 deletions
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 82950a07..7ec77e51 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -124,6 +124,7 @@ static void _dbus_verbose(const char * x,...) {;} # define _dbus_is_verbose() FALSE #endif /* !DBUS_ENABLE_VERBOSE_MODE */ +DBUS_PRIVATE_EXPORT void _dbus_trace_ref (const char *obj_name, void *obj, int old_refcount, diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index 964888f8..9c72c955 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -60,7 +60,7 @@ */ struct DBusBabysitter { - int refcount; + DBusAtomic refcount; HANDLE start_sync_event; #ifdef DBUS_ENABLE_EMBEDDED_TESTS @@ -89,16 +89,33 @@ struct DBusBabysitter int child_status; }; +static void +_dbus_babysitter_trace_ref (DBusBabysitter *sitter, + int old_refcount, + int new_refcount, + const char *why) +{ +#ifdef DBUS_ENABLE_VERBOSE_MODE + static int enabled = -1; + + _dbus_trace_ref ("DBusBabysitter", sitter, old_refcount, new_refcount, why, + "DBUS_BABYSITTER_TRACE", &enabled); +#endif +} + static DBusBabysitter* _dbus_babysitter_new (void) { DBusBabysitter *sitter; + dbus_int32_t old_refcount; sitter = dbus_new0 (DBusBabysitter, 1); if (sitter == NULL) return NULL; - sitter->refcount = 1; + old_refcount = _dbus_atomic_inc (&sitter->refcount); + + _dbus_babysitter_trace_ref (sitter, old_refcount, old_refcount+1, __FUNCTION__); sitter->start_sync_event = CreateEvent (NULL, FALSE, FALSE, NULL); if (sitter->start_sync_event == NULL) @@ -146,11 +163,13 @@ _dbus_babysitter_new (void) DBusBabysitter * _dbus_babysitter_ref (DBusBabysitter *sitter) { + dbus_int32_t old_refcount; PING(); _dbus_assert (sitter != NULL); - _dbus_assert (sitter->refcount > 0); - sitter->refcount += 1; + old_refcount = _dbus_atomic_inc (&sitter->refcount); + _dbus_assert (old_refcount > 0); + _dbus_babysitter_trace_ref (sitter, old_refcount, old_refcount+1, __FUNCTION__); return sitter; } @@ -185,14 +204,16 @@ void _dbus_babysitter_unref (DBusBabysitter *sitter) { int i; + dbus_int32_t old_refcount; PING(); _dbus_assert (sitter != NULL); - _dbus_assert (sitter->refcount > 0); - sitter->refcount -= 1; + old_refcount = _dbus_atomic_dec (&sitter->refcount); + _dbus_assert (old_refcount > 0); + _dbus_babysitter_trace_ref (sitter, old_refcount, old_refcount-1, __FUNCTION__); - if (sitter->refcount == 0) + if (old_refcount == 1) { close_socket_to_babysitter (sitter); @@ -584,7 +605,11 @@ babysitter (void *parameter) DBusBabysitter *sitter = (DBusBabysitter *) parameter; PING(); - _dbus_babysitter_ref (sitter); + if (sitter->child_setup) + { + PING(); + (*sitter->child_setup) (sitter->user_data); + } _dbus_verbose ("babysitter: spawning %s\n", sitter->log_name); @@ -717,7 +742,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, PING(); sitter_thread = (HANDLE) CreateThread (NULL, 0, babysitter, - sitter, 0, &sitter_thread_id); + _dbus_babysitter_ref (sitter), 0, &sitter_thread_id); if (sitter_thread == 0) { diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index a6bc978f..3659dd47 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -296,8 +296,11 @@ struct DBusAtomic # undef DBUS_HAVE_ATOMIC_INT #endif +DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic); +DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic); +DBUS_PRIVATE_EXPORT dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic); #ifdef DBUS_WIN |