[wing/mutex-cond] wingservice: acquire the mutex before signalling the condition variable




commit 0e93307c8d1f028cf9cd6193dbb540ce95373c94
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]