mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
gthread: avoid locking in _get_mutex_impl
When getting the mutex implementation of a static mutex, avoid taking the global lock every time but only take the lock when there was no mutex and we need to create one. https://bugzilla.gnome.org/show_bug.cgi?id=599954
This commit is contained in:
parent
fca330dafa
commit
496157ffd3
@ -1267,19 +1267,30 @@ g_static_mutex_init (GStaticMutex *mutex)
|
|||||||
GMutex *
|
GMutex *
|
||||||
g_static_mutex_get_mutex_impl (GMutex** mutex)
|
g_static_mutex_get_mutex_impl (GMutex** mutex)
|
||||||
{
|
{
|
||||||
|
GMutex *result;
|
||||||
|
|
||||||
if (!g_thread_supported ())
|
if (!g_thread_supported ())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
result = g_atomic_pointer_get (mutex);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
g_assert (g_once_mutex);
|
g_assert (g_once_mutex);
|
||||||
|
|
||||||
g_mutex_lock (g_once_mutex);
|
g_mutex_lock (g_once_mutex);
|
||||||
|
|
||||||
if (!(*mutex))
|
result = *mutex;
|
||||||
g_atomic_pointer_set (mutex, g_mutex_new());
|
if (!result)
|
||||||
|
{
|
||||||
|
result = g_mutex_new ();
|
||||||
|
g_atomic_pointer_set (mutex, result);
|
||||||
|
}
|
||||||
|
|
||||||
g_mutex_unlock (g_once_mutex);
|
g_mutex_unlock (g_once_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
return *mutex;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IMPLEMENTATION NOTE:
|
/* IMPLEMENTATION NOTE:
|
||||||
|
Loading…
Reference in New Issue
Block a user