[vlc-devel] [PATCH 06/14] vlm: move vlm instances counter to private struct

Romain Vimont rom1v at videolabs.io
Tue Sep 15 19:37:38 CEST 2020


In order to move the VLM implementation to a separate module, move the
instances counter to a separate private struct known only by the core.

The other fields will be moved to a "sys" private to the module in
further patches.
---
 src/input/vlm.c          | 28 +++++++++++++++++++++-------
 src/input/vlm_internal.h |  1 -
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/input/vlm.c b/src/input/vlm.c
index 153b6519ae..bd75108498 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -48,6 +48,14 @@
 #include <vlc_url.h>
 #include "../libvlc.h"
 
+typedef struct vlm_priv
+{
+    vlm_t vlm;
+    unsigned users;
+} vlm_priv_t ;
+
+#define vlm_priv(v) container_of(v, vlm_priv_t, vlm)
+
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
@@ -115,8 +123,9 @@ vlm_t *vlm_New( libvlc_int_t *libvlc )
     p_vlm = *pp_vlm;
     if( p_vlm )
     {   /* VLM already exists */
-        if( likely( p_vlm->users < UINT_MAX ) )
-            p_vlm->users++;
+        vlm_priv_t *priv = vlm_priv( p_vlm );
+        if( likely( priv->users < UINT_MAX ) )
+            priv->users++;
         else
             p_vlm = NULL;
         vlc_mutex_unlock( &vlm_mutex );
@@ -125,17 +134,20 @@ vlm_t *vlm_New( libvlc_int_t *libvlc )
 
     msg_Dbg( p_this, "creating VLM" );
 
-    p_vlm = vlc_custom_create( p_this, sizeof( *p_vlm ), "vlm daemon" );
-    if( !p_vlm )
+    vlm_priv_t *priv = vlc_custom_create( p_this, sizeof( *priv ), "vlm daemon" );
+    if( !priv )
     {
         vlc_mutex_unlock( &vlm_mutex );
         return NULL;
     }
 
+    priv->users = 1;
+
+    p_vlm = &priv->vlm;
+
     vlc_mutex_init( &p_vlm->lock );
     vlc_mutex_init( &p_vlm->lock_manage );
     vlc_cond_init( &p_vlm->wait_manage );
-    p_vlm->users = 1;
     p_vlm->input_state_changed = false;
     p_vlm->exiting = false;
     p_vlm->i_id = 1;
@@ -187,8 +199,10 @@ void vlm_Delete( vlm_t *p_vlm )
     /* vlm_Delete() is serialized against itself, and against vlm_New().
      * This mutex protects libvlc_priv->p_vlm and p_vlm->users. */
     vlc_mutex_lock( &vlm_mutex );
-    assert( p_vlm->users > 0 );
-    if( --p_vlm->users == 0 )
+
+    vlm_priv_t *priv = vlm_priv( p_vlm );
+    assert( priv->users > 0 );
+    if( --priv->users == 0 )
         assert( libvlc_priv(vlc_object_instance(p_vlm))->p_vlm == p_vlm );
     else
         p_vlm = NULL;
diff --git a/src/input/vlm_internal.h b/src/input/vlm_internal.h
index 34c58788f1..c54779ef96 100644
--- a/src/input/vlm_internal.h
+++ b/src/input/vlm_internal.h
@@ -80,7 +80,6 @@ struct vlm_t
     vlc_thread_t thread;
     vlc_mutex_t  lock_manage;
     vlc_cond_t   wait_manage;
-    unsigned     users;
 
     /* tell vlm thread there is work to do */
     bool         input_state_changed;
-- 
2.28.0



More information about the vlc-devel mailing list