Use mutex and condition variables properly
authorDavid Zeuthen <zeuthen@gmail.com>
Wed, 9 Jan 2013 19:22:20 +0000 (14:22 -0500)
committerDavid Zeuthen <zeuthen@gmail.com>
Wed, 9 Jan 2013 19:33:52 +0000 (14:33 -0500)
This was pointed out in bug 57325.

https://bugs.freedesktop.org/show_bug.cgi?id=57325

Signed-off-by: David Zeuthen <zeuthen@gmail.com>
src/polkitbackend/polkitbackendjsauthority.c

index e4aa46b3f504eabf0be16633bc0c75e5b83ac217..28361c34d74cb5a6d4fce9dcf595600d8521f4c9 100644 (file)
@@ -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);