From 85ae5715fc05579f6c1b5424bb5ebbb183265eae Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Wed, 9 Jan 2013 14:22:20 -0500 Subject: Use mutex and condition variables properly This was pointed out in bug 57325. https://bugs.freedesktop.org/show_bug.cgi?id=57325 Signed-off-by: David Zeuthen --- src/polkitbackend/polkitbackendjsauthority.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.c index e4aa46b..28361c3 100644 --- a/src/polkitbackend/polkitbackendjsauthority.c +++ b/src/polkitbackend/polkitbackendjsauthority.c @@ -622,9 +622,10 @@ polkit_backend_js_authority_constructed (GObject *object) authority); /* wait for runaway_killer_thread to set up its GMainContext */ - g_cond_wait (&authority->priv->rkt_init_cond, &authority->priv->rkt_init_mutex); + g_mutex_lock (&authority->priv->rkt_init_mutex); + while (authority->priv->rkt_context == NULL) + g_cond_wait (&authority->priv->rkt_init_cond, &authority->priv->rkt_init_mutex); g_mutex_unlock (&authority->priv->rkt_init_mutex); - g_assert (authority->priv->rkt_context != NULL); setup_file_monitors (authority); load_scripts (authority); @@ -1011,13 +1012,13 @@ runaway_killer_thread_func (gpointer user_data) { PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (user_data); + g_mutex_lock (&authority->priv->rkt_init_mutex); + authority->priv->rkt_context = g_main_context_new (); authority->priv->rkt_loop = g_main_loop_new (authority->priv->rkt_context, FALSE); - g_main_context_push_thread_default (authority->priv->rkt_context); /* Signal the main thread that we're done constructing */ - g_mutex_lock (&authority->priv->rkt_init_mutex); g_cond_signal (&authority->priv->rkt_init_cond); g_mutex_unlock (&authority->priv->rkt_init_mutex); -- cgit v1.2.1