giomodule: Don’t mandatorily cache GIOModule implementations

While all of the current callers of _g_io_module_get_default() want to
cache the returned GObject for the lifetime of the process, that doesn’t
necessarily have to be the case, so let callers make that decision on a
case-by-case basis.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall
2019-01-23 16:07:51 +00:00
committed by Philip Withnall
parent b207965697
commit 22b924b64a
7 changed files with 121 additions and 31 deletions

View File

@@ -992,6 +992,12 @@ g_settings_backend_verify (gpointer impl)
return TRUE;
}
/* We need to cache the default #GSettingsBackend for the entire process
* lifetime, especially if the backend is #GMemorySettingsBackend: it needs to
* keep the in-memory settings around even while there are no #GSettings
* instances alive. */
static GSettingsBackend *settings_backend_default_singleton = NULL; /* (owned) (atomic) */
/**
* g_settings_backend_get_default:
*
@@ -1010,12 +1016,18 @@ g_settings_backend_verify (gpointer impl)
GSettingsBackend *
g_settings_backend_get_default (void)
{
GSettingsBackend *backend;
if (g_once_init_enter (&settings_backend_default_singleton))
{
GSettingsBackend *singleton;
backend = _g_io_module_get_default (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
"GSETTINGS_BACKEND",
g_settings_backend_verify);
return g_object_ref (backend);
singleton = _g_io_module_get_default (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
"GSETTINGS_BACKEND",
g_settings_backend_verify);
g_once_init_leave (&settings_backend_default_singleton, singleton);
}
return g_object_ref (settings_backend_default_singleton);
}
/*< private >