diff options
author | Thomas Haller <thaller@redhat.com> | 2015-02-16 15:36:55 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-02-16 17:38:14 +0100 |
commit | 99465a34ca1dfe96299bbc0237702004177dce51 (patch) | |
tree | 65ff7ba6d1a38997ae520ae037bd608b374d8ac5 /src/nm-dbus-manager.c | |
parent | 5e74891b58688a19c43fb8e50880166d94a4e901 (diff) | |
download | NetworkManager-99465a34ca1dfe96299bbc0237702004177dce51.tar.gz |
dbus-manager: refactor singleton getter dropping g_once_init_enter()
The class itself is not thread-safe, so no need for guarding
the creation with g_once_init_*().
Also, assert against multiple creation and log a line when
creating the singleton. The getter is now more similar to what
is created by NM_DEFINE_SINGLETON_GETTER().
Diffstat (limited to 'src/nm-dbus-manager.c')
-rw-r--r-- | src/nm-dbus-manager.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index e29c23dc21..230c4b8e08 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -84,15 +84,17 @@ NM_DEFINE_SINGLETON_WEAK_REF (NMDBusManager); NMDBusManager * nm_dbus_manager_get (void) { - static gsize once = 0; + if (G_UNLIKELY (!singleton_instance)) { + static char already_created = FALSE; - if (g_once_init_enter (&once)) { - singleton_instance = (NMDBusManager *) g_object_new (NM_TYPE_DBUS_MANAGER, NULL); + g_assert (!already_created); + already_created = TRUE; + singleton_instance = g_object_new (NM_TYPE_DBUS_MANAGER, NULL); g_assert (singleton_instance); nm_singleton_instance_weak_ref_register (); + nm_log_dbg (LOGD_CORE, "create %s singleton (%p)", "NMDBusManager", singleton_instance); if (!nm_dbus_manager_init_bus (singleton_instance)) start_reconnection_timeout (singleton_instance); - g_once_init_leave (&once, 1); } return singleton_instance; } |