summaryrefslogtreecommitdiff
path: root/src/polkitbackend/polkitbackendjsauthority.c
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2012-05-24 11:39:57 -0400
committerDavid Zeuthen <davidz@redhat.com>2012-05-24 11:39:57 -0400
commit2ec9e681e0ee17bcc60a0724b201b2e19b573abb (patch)
tree649d4441fb1f768c1ef148d5abeee974f28aef8a /src/polkitbackend/polkitbackendjsauthority.c
parentbe4c87252e8031c3427ca14ad036981f09fd6369 (diff)
Use a condition variable to signal that runaway killer thread is ready
... instead of the unsafe g_thread_yield() busy-wait loop. Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'src/polkitbackend/polkitbackendjsauthority.c')
-rw-r--r--src/polkitbackend/polkitbackendjsauthority.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.c
index a05d022..cc805e8 100644
--- a/src/polkitbackend/polkitbackendjsauthority.c
+++ b/src/polkitbackend/polkitbackendjsauthority.c
@@ -67,5 +67,6 @@ struct _PolkitBackendJsAuthorityPrivate
GThread *runaway_killer_thread;
+ GMutex rkt_init_mutex;
+ GCond rkt_init_cond;
GMainContext *rkt_context;
GMainLoop *rkt_loop;
-
GSource *rkt_source;
@@ -474,2 +475,5 @@ polkit_backend_js_authority_constructed (GObject *object)
+ g_mutex_init (&authority->priv->rkt_init_mutex);
+ g_cond_init (&authority->priv->rkt_init_cond);
+
authority->priv->runaway_killer_thread = g_thread_new ("runaway-killer-thread",
@@ -478,5 +482,6 @@ polkit_backend_js_authority_constructed (GObject *object)
- /* TODO: use a condition variable */
- while (authority->priv->rkt_loop == NULL)
- g_thread_yield ();
+ /* 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_unlock (&authority->priv->rkt_init_mutex);
+ g_assert (authority->priv->rkt_context != NULL);
@@ -499,2 +504,5 @@ polkit_backend_js_authority_finalize (GObject *object)
+ g_mutex_clear (&authority->priv->rkt_init_mutex);
+ g_cond_clear (&authority->priv->rkt_init_cond);
+
/* shut down the killer thread */
@@ -861,3 +869,6 @@ runaway_killer_thread_func (gpointer user_data)
- /* TODO: signal the main thread that we're done constructing */
+ /* 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);