mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
gmain: Avoid locking dance in g_main_loop_run()
We do it during initialization, this may be if necessary handled by GCond in case we need to acquire the lock.
This commit is contained in:
parent
e7c2ead41b
commit
f8e440335c
17
glib/gmain.c
17
glib/gmain.c
@ -4495,13 +4495,13 @@ g_main_loop_run (GMainLoop *loop)
|
||||
/* Hold a reference in case the loop is unreffed from a callback function */
|
||||
g_atomic_int_inc (&loop->ref_count);
|
||||
|
||||
if (!g_main_context_acquire (loop->context))
|
||||
LOCK_CONTEXT (loop->context);
|
||||
|
||||
if (!g_main_context_acquire_unlocked (loop->context))
|
||||
{
|
||||
gboolean got_ownership = FALSE;
|
||||
|
||||
/* Another thread owns this context */
|
||||
LOCK_CONTEXT (loop->context);
|
||||
|
||||
g_atomic_int_set (&loop->is_running, TRUE);
|
||||
|
||||
while (g_atomic_int_get (&loop->is_running) && !got_ownership)
|
||||
@ -4511,17 +4511,16 @@ g_main_loop_run (GMainLoop *loop)
|
||||
|
||||
if (!g_atomic_int_get (&loop->is_running))
|
||||
{
|
||||
UNLOCK_CONTEXT (loop->context);
|
||||
if (got_ownership)
|
||||
g_main_context_release (loop->context);
|
||||
g_main_context_release_unlocked (loop->context);
|
||||
|
||||
UNLOCK_CONTEXT (loop->context);
|
||||
g_main_loop_unref (loop);
|
||||
return;
|
||||
}
|
||||
|
||||
g_assert (got_ownership);
|
||||
}
|
||||
else
|
||||
LOCK_CONTEXT (loop->context);
|
||||
|
||||
if (loop->context->in_check_or_prepare)
|
||||
{
|
||||
@ -4535,10 +4534,10 @@ g_main_loop_run (GMainLoop *loop)
|
||||
while (g_atomic_int_get (&loop->is_running))
|
||||
g_main_context_iterate_unlocked (loop->context, TRUE, TRUE, self);
|
||||
|
||||
g_main_context_release_unlocked (loop->context);
|
||||
|
||||
UNLOCK_CONTEXT (loop->context);
|
||||
|
||||
g_main_context_release (loop->context);
|
||||
|
||||
g_main_loop_unref (loop);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user