[vlc-devel] [PATCH 1/7] objects: add back legacy list node

Thomas Guillem thomas at gllm.fr
Mon May 27 16:45:10 CEST 2019


This has been removed from c7e98fa75a88466b94b1bafae3bac3ba5f634537 as a side
effect.

This partially reverts commit c7e98fa75a88466b94b1bafae3bac3ba5f634537.

Refs #21997
---
 src/misc/objects.c   | 20 +++++++++++++++++++-
 src/misc/variables.h |  3 +++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index f87edd9827..940c39ab16 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -55,8 +55,12 @@
 #include <limits.h>
 #include <assert.h>
 
+static vlc_mutex_t tree_lock = VLC_STATIC_MUTEX;
+static struct vlc_list tree_list = VLC_LIST_INITIALIZER(&tree_list);
+
 #define vlc_children_foreach(pos, priv) \
-    while (((void)(pos), (void)(priv), 0))
+    vlc_list_foreach(pos, &tree_list, list) \
+        if (vlc_internals(pos->parent) == priv)
 
 int vlc_object_init(vlc_object_t *restrict obj, vlc_object_t *parent,
                     const char *typename)
@@ -79,6 +83,11 @@ int vlc_object_init(vlc_object_t *restrict obj, vlc_object_t *parent,
     {
         obj->logger = parent->logger;
         obj->no_interact = parent->no_interact;
+
+        /* Attach the parent to its child (structure lock needed) */
+        vlc_mutex_lock(&tree_lock);
+        vlc_list_append(&priv->list, &tree_list);
+        vlc_mutex_unlock(&tree_lock);
     }
     else
     {
@@ -123,6 +132,13 @@ void vlc_object_deinit(vlc_object_t *obj)
 
     assert(priv->resources == NULL);
 
+    if (likely(priv->parent != NULL))
+    {
+        vlc_mutex_lock(&tree_lock);
+        vlc_list_remove(&priv->list);
+        vlc_mutex_unlock(&tree_lock);
+    }
+
     /* Destroy the associated variables. */
     int canc = vlc_savecancel();
     var_DestroyAll(obj);
@@ -196,11 +212,13 @@ size_t vlc_list_children(vlc_object_t *obj, vlc_object_t **restrict tab,
     vlc_object_internals_t *priv;
     size_t count = 0;
 
+    vlc_mutex_lock(&tree_lock);
     vlc_children_foreach(priv, vlc_internals(obj))
     {
          if (count < max)
              tab[count] = vlc_object_hold(vlc_externals(priv));
          count++;
     }
+    vlc_mutex_unlock(&tree_lock);
     return count;
 }
diff --git a/src/misc/variables.h b/src/misc/variables.h
index 5ef84f1b2a..710460989d 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -42,6 +42,9 @@ struct vlc_object_internals
     vlc_mutex_t     var_lock;
     vlc_cond_t      var_wait;
 
+    /* Objects tree structure */
+    struct vlc_list list; /**< Legacy list node */
+
     /* Object resources */
     struct vlc_res *resources;
 };
-- 
2.20.1



More information about the vlc-devel mailing list