mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-28 16:36:14 +01:00
gmain: use atomic operation instead of GMutex to access g_main_context_default()
I think it is wasteful to use a mutex every time the default main context is accessed. Especially, as the default main context is used all the time.
This commit is contained in:
parent
038ec3de31
commit
39dd2be538
22
glib/gmain.c
22
glib/gmain.c
@ -439,9 +439,6 @@ static void block_source (GSource *source);
|
|||||||
|
|
||||||
static GMainContext *glib_worker_context;
|
static GMainContext *glib_worker_context;
|
||||||
|
|
||||||
G_LOCK_DEFINE_STATIC (main_loop);
|
|
||||||
static GMainContext *default_main_context;
|
|
||||||
|
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
|
|
||||||
|
|
||||||
@ -678,23 +675,24 @@ g_main_context_new (void)
|
|||||||
GMainContext *
|
GMainContext *
|
||||||
g_main_context_default (void)
|
g_main_context_default (void)
|
||||||
{
|
{
|
||||||
/* Slow, but safe */
|
static GMainContext *default_main_context;
|
||||||
|
|
||||||
G_LOCK (main_loop);
|
if (g_once_init_enter (&default_main_context))
|
||||||
|
|
||||||
if (!default_main_context)
|
|
||||||
{
|
{
|
||||||
default_main_context = g_main_context_new ();
|
GMainContext *context;
|
||||||
|
|
||||||
TRACE (GLIB_MAIN_CONTEXT_DEFAULT (default_main_context));
|
context = g_main_context_new ();
|
||||||
|
|
||||||
|
TRACE (GLIB_MAIN_CONTEXT_DEFAULT (context));
|
||||||
|
|
||||||
#ifdef G_MAIN_POLL_DEBUG
|
#ifdef G_MAIN_POLL_DEBUG
|
||||||
if (_g_main_poll_debug)
|
if (_g_main_poll_debug)
|
||||||
g_print ("default context=%p\n", default_main_context);
|
g_print ("default context=%p\n", context);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
G_UNLOCK (main_loop);
|
g_once_init_leave ((gsize *) &default_main_context, (gsize) context);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return default_main_context;
|
return default_main_context;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user