summaryrefslogtreecommitdiff
path: root/src/polkitbackend/polkitbackendjsauthority.c
authorDavid Zeuthen <davidz@redhat.com>2012-05-24 15:39:57 (GMT)
committer David Zeuthen <davidz@redhat.com>2012-05-24 15:39:57 (GMT)
commit2ec9e681e0ee17bcc60a0724b201b2e19b573abb (patch) (side-by-side diff)
tree649d4441fb1f768c1ef148d5abeee974f28aef8a /src/polkitbackend/polkitbackendjsauthority.c
parentbe4c87252e8031c3427ca14ad036981f09fd6369 (diff)
downloadpolkit-2ec9e681e0ee17bcc60a0724b201b2e19b573abb.zip
polkit-2ec9e681e0ee17bcc60a0724b201b2e19b573abb.tar.gz
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') (more/less context) (ignore whitespace changes)
-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
@@ -65,9 +65,10 @@ struct _PolkitBackendJsAuthorityPrivate
JSObject *js_polkit;
GThread *runaway_killer_thread;
+ GMutex rkt_init_mutex;
+ GCond rkt_init_cond;
GMainContext *rkt_context;
GMainLoop *rkt_loop;
-
GSource *rkt_source;
/* A list of JSObject instances */
@@ -472,13 +473,17 @@ polkit_backend_js_authority_constructed (GObject *object)
authority->priv->rules_dirs[1] = g_strdup (PACKAGE_DATA_DIR "/polkit-1/rules.d");
}
+ 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",
runaway_killer_thread_func,
authority);
- /* 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);
setup_file_monitors (authority);
load_scripts (authority);
@@ -497,6 +502,9 @@ polkit_backend_js_authority_finalize (GObject *object)
PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (object);
guint n;
+ g_mutex_clear (&authority->priv->rkt_init_mutex);
+ g_cond_clear (&authority->priv->rkt_init_cond);
+
/* shut down the killer thread */
g_assert (authority->priv->rkt_loop != NULL);
g_main_loop_quit (authority->priv->rkt_loop);
@@ -859,7 +867,10 @@ runaway_killer_thread_func (gpointer user_data)
g_main_context_push_thread_default (authority->priv->rkt_context);
- /* 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);
g_main_loop_run (authority->priv->rkt_loop);