[vlc-devel] [PATCH] variables: privatise the callback CV

RĂ©mi Denis-Courmont remi at remlab.net
Tue Dec 15 20:39:08 CET 2020


The condition variable was shared across all variables of a given
object to save space, but it ends up waking up the wrong waiting
threads.

vlc_cond_t is not as large as it used to be. In fact, it could be as
small as a single pointer: if we required holding the mutex during
signal/broadcast. The nested mutex is only there to handle unprotected
signalling.
---
 src/misc/objects.c   | 1 -
 src/misc/variables.c | 8 +++++---
 src/misc/variables.h | 1 -
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index 7b15ae91d0..f43549d1a1 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -69,7 +69,6 @@ int vlc_object_init(vlc_object_t *restrict obj, vlc_object_t *parent,
     priv->typename = typename;
     priv->var_root = NULL;
     vlc_mutex_init (&priv->var_lock);
-    vlc_cond_init (&priv->var_wait);
     priv->resources = NULL;
 
     obj->priv = priv;
diff --git a/src/misc/variables.c b/src/misc/variables.c
index ed284cf4f4..f12e55d4e7 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -96,6 +96,8 @@ struct variable_t
     callback_entry_t    *value_callbacks;
     /** Registered list callbacks */
     callback_entry_t    *list_callbacks;
+
+    vlc_cond_t   wait;
 };
 
 static int CmpBool( vlc_value_t v, vlc_value_t w )
@@ -228,7 +230,7 @@ static void WaitUnused(vlc_object_t *obj, variable_t *var)
 
     mutex_cleanup_push(&priv->var_lock);
     while (var->b_incallback)
-        vlc_cond_wait(&priv->var_wait, &priv->var_lock);
+        vlc_cond_wait(&var->wait, &priv->var_lock);
     vlc_cleanup_pop();
 }
 
@@ -256,7 +258,7 @@ static void TriggerCallback(vlc_object_t *obj, variable_t *var,
 
     vlc_mutex_lock(&priv->var_lock);
     var->b_incallback = false;
-    vlc_cond_broadcast(&priv->var_wait);
+    vlc_cond_broadcast(&var->wait);
 }
 
 static void TriggerListCallback(vlc_object_t *obj, variable_t *var,
@@ -283,7 +285,7 @@ static void TriggerListCallback(vlc_object_t *obj, variable_t *var,
 
     vlc_mutex_lock(&priv->var_lock);
     var->b_incallback = false;
-    vlc_cond_broadcast(&priv->var_wait);
+    vlc_cond_broadcast(&var->wait);
 }
 
 int (var_Create)( vlc_object_t *p_this, const char *psz_name, int i_type )
diff --git a/src/misc/variables.h b/src/misc/variables.h
index 5ef84f1b2a..711cd14b5a 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -40,7 +40,6 @@ struct vlc_object_internals
     /* Object variables */
     void           *var_root;
     vlc_mutex_t     var_lock;
-    vlc_cond_t      var_wait;
 
     /* Object resources */
     struct vlc_res *resources;
-- 
2.20.1



More information about the vlc-devel mailing list