mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-05 11:20:36 +02:00
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().
This commit is contained in:
parent
5e74891b58
commit
99465a34ca
1 changed files with 6 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue