summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2018-11-01 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2018-11-13 14:52:50 +0100
commitd2fd53df036af9a931a39b6d28d42fea9f6b5d18 (patch)
treefa5867a961c5aaa01bcb0e676b955679d88ea001
parent1c8f3c67c39a5425efdd46075a988c9d0ce87b2c (diff)
downloadglib-d2fd53df036af9a931a39b6d28d42fea9f6b5d18.tar.gz
gmain: Make GChildWatchSource child_exited field atomic
Ensure synchronization between prepare / check of GChildWatchsource and UNIX signal dispatcher by making operations on `child_exited` field atomic. Use `child_exited` as publication flag for `child_status`. Issue #1312.
-rw-r--r--glib/gmain.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/glib/gmain.c b/glib/gmain.c
index e1a680433..ad57b4927 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -5107,7 +5107,7 @@ dispatch_unix_signals_unlocked (void)
{
GChildWatchSource *source = node->data;
- if (!source->child_exited)
+ if (!g_atomic_int_get (&source->child_exited))
{
pid_t pid;
do
@@ -5117,14 +5117,14 @@ dispatch_unix_signals_unlocked (void)
pid = waitpid (source->pid, &source->child_status, WNOHANG);
if (pid > 0)
{
- source->child_exited = TRUE;
+ g_atomic_int_set (&source->child_exited, TRUE);
wake_source ((GSource *) source);
}
else if (pid == -1 && errno == ECHILD)
{
g_warning ("GChildWatchSource: Exit status of a child process was requested but ECHILD was received by waitpid(). See the documentation of g_child_watch_source_new() for possible causes.");
- source->child_exited = TRUE;
source->child_status = 0;
+ g_atomic_int_set (&source->child_exited, TRUE);
wake_source ((GSource *) source);
}
}
@@ -5167,7 +5167,7 @@ g_child_watch_prepare (GSource *source,
child_watch_source = (GChildWatchSource *) source;
- return child_watch_source->child_exited;
+ return g_atomic_int_get (&child_watch_source->child_exited);
}
static gboolean
@@ -5177,7 +5177,7 @@ g_child_watch_check (GSource *source)
child_watch_source = (GChildWatchSource *) source;
- return child_watch_source->child_exited;
+ return g_atomic_int_get (&child_watch_source->child_exited);
}
static gboolean