[vlc-commits] Privatize b_die

Rémi Denis-Courmont git at videolan.org
Sat Nov 10 18:55:16 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 10 19:38:53 2012 +0200| [a09b86ce6ce15604213da8f80678a49d05f31fba] | committer: Rémi Denis-Courmont

Privatize b_die

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a09b86ce6ce15604213da8f80678a49d05f31fba
---

 include/vlc_common.h  |    1 -
 include/vlc_objects.h |    8 +-------
 src/libvlccore.sym    |    1 +
 src/misc/objects.c    |   24 ++++++++++++++++--------
 src/misc/variables.h  |    1 +
 5 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index 2e6914b..55715e6 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -453,7 +453,6 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *,      /* variable's object */
     int  i_flags;                                                           \
                                                                             \
     /* Object properties */                                                 \
-    volatile bool b_die;                   /**< set by the outside */ \
     bool b_force;      /**< set by the outside (eg. module_need()) */ \
                                                                             \
     /* Stuff related to the libvlc structure */                             \
diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index 8489aaf..c670875 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -73,13 +73,7 @@ VLC_API char *vlc_object_get_name( const vlc_object_t * ) VLC_USED;
     vlc_list_children( VLC_OBJECT(a) )
 
 /* Objects and threading */
-VLC_USED VLC_DEPRECATED
-static inline bool vlc_object_alive (const vlc_object_t *obj)
-{
-    barrier ();
-    return !obj->b_die;
-}
-
+VLC_API VLC_USED VLC_DEPRECATED bool vlc_object_alive (vlc_object_t *);
 #define vlc_object_alive(a) vlc_object_alive( VLC_OBJECT(a) )
 
 /** @} */
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a3cfbd4..04dfbc8 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -556,6 +556,7 @@ vlc_object_find_name
 vlc_object_hold
 vlc_object_release
 vlc_object_get_name
+vlc_object_alive
 vlc_rand_bytes
 vlc_drand48
 vlc_lrand48
diff --git a/src/misc/objects.c b/src/misc/objects.c
index 292bba3..3e365bd 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -133,6 +133,7 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,
     vlc_mutex_init (&priv->var_lock);
     vlc_cond_init (&priv->var_wait);
     priv->pipes[0] = priv->pipes[1] = -1;
+    atomic_init (&priv->alive, true);
     atomic_init (&priv->refs, 1);
     priv->pf_destructor = NULL;
     priv->prev = NULL;
@@ -141,7 +142,6 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,
     vlc_object_t *obj = (vlc_object_t *)(priv + 1);
     obj->psz_object_type = typename;
     obj->psz_header = NULL;
-    obj->b_die = false;
     obj->b_force = false;
     memset (obj + 1, 0, length - sizeof (*obj)); /* type-specific stuff */
 
@@ -367,7 +367,7 @@ int vlc_object_waitpipe( vlc_object_t *obj )
                 internals->pipes[0] = internals->pipes[1] = -1;
         }
 
-        if (internals->pipes[0] != -1 && obj->b_die)
+        if (internals->pipes[0] != -1 && !atomic_load (&internals->alive))
         {   /* Race condition: vlc_object_kill() already invoked! */
             msg_Dbg (obj, "waitpipe: object already dying");
             write (internals->pipes[1], &(uint64_t){ 1 }, sizeof (uint64_t));
@@ -388,16 +388,13 @@ void vlc_object_kill( vlc_object_t *p_this )
     vlc_object_internals_t *priv = vlc_internals( p_this );
     int fd = -1;
 
-    vlc_mutex_lock( &pipe_lock );
-    if( !p_this->b_die )
+    if (atomic_exchange (&priv->alive, false))
     {
+        vlc_mutex_lock (&pipe_lock);
         fd = priv->pipes[1];
-        p_this->b_die = true;
+        vlc_mutex_unlock (&pipe_lock);
     }
 
-    /* This also serves as a memory barrier toward vlc_object_alive(): */
-    vlc_mutex_unlock( &pipe_lock );
-
     if (fd != -1)
     {
         int canc = vlc_savecancel ();
@@ -512,6 +509,17 @@ void vlc_object_release( vlc_object_t *p_this )
     }
 }
 
+#undef vlc_object_alive
+/**
+ * This function returns true, except when it returns false.
+ * \warning Do not use this function. Ever. You were warned.
+ */
+bool vlc_object_alive(vlc_object_t *obj)
+{
+    vlc_object_internals_t *internals = vlc_internals (obj);
+    return atomic_load (&internals->alive);
+}
+
 #undef vlc_list_children
 /**
  * Gets the list of children of an objects, and increment their reference
diff --git a/src/misc/variables.h b/src/misc/variables.h
index 671f337..8c203b6 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -41,6 +41,7 @@ struct vlc_object_internals
 
     /* Objects thread synchronization */
     int             pipes[2];
+    atomic_bool     alive;
 
     /* Objects management */
     atomic_uint     refs;



More information about the vlc-commits mailing list