[wing/mutex-cond: 2/2] wingservice: acquire the mutex before signalling the condition variable
- From: Silvio Lazzeretti <silviol src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [wing/mutex-cond: 2/2] wingservice: acquire the mutex before signalling the condition variable
- Date: Wed, 27 Apr 2022 18:40:14 +0000 (UTC)
commit 0a23bf459a777ad7b4131713ccf8da54ea966a3c
Author: Silvio Lazzeretti <silviola amazon com>
Date: Wed Apr 27 19:10:05 2022 +0200
wingservice: acquire the mutex before signalling the condition variable
It might happen that due to multithreading,
the condition variable is signaled before
anyone is waiting on it and that signal got lost.
This scenario causes a hang since the service manager will
remain blocked on waiting on the condition variable.
wing/wingservice.c | 8 ++++++++
1 file changed, 8 insertions(+)
---
diff --git a/wing/wingservice.c b/wing/wingservice.c
index 4c9758d..bb8138a 100644
--- a/wing/wingservice.c
+++ b/wing/wingservice.c
@@ -502,20 +502,28 @@ on_control_handler_idle (gpointer user_data)
{
case WING_SERVICE_STARTUP:
g_signal_emit (G_OBJECT (service), signals[START], 0);
+ g_mutex_lock (&priv->control_mutex);
g_cond_signal (&priv->control_cond);
+ g_mutex_unlock (&priv->control_mutex);
break;
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
g_signal_emit (G_OBJECT (service), signals[STOP], 0);
+ g_mutex_lock (&priv->control_mutex);
g_cond_signal (&priv->control_cond);
+ g_mutex_unlock (&priv->control_mutex);
break;
case SERVICE_CONTROL_PAUSE:
g_signal_emit (G_OBJECT (service), signals[PAUSE], 0);
+ g_mutex_lock (&priv->control_mutex);
g_cond_signal (&priv->control_cond);
+ g_mutex_unlock (&priv->control_mutex);
break;
case SERVICE_CONTROL_CONTINUE:
g_signal_emit (G_OBJECT (service), signals[RESUME], 0);
+ g_mutex_lock (&priv->control_mutex);
g_cond_signal (&priv->control_cond);
+ g_mutex_unlock (&priv->control_mutex);
break;
case SERVICE_CONTROL_SESSIONCHANGE:
g_signal_emit (G_OBJECT (service), signals[SESSION_CHANGE], 0, data->event_type, data->event_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]