]> git.sesse.net Git - vlc/commitdiff
Privatize b_die
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 10 Nov 2012 17:38:53 +0000 (19:38 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 10 Nov 2012 17:47:54 +0000 (19:47 +0200)
include/vlc_common.h
include/vlc_objects.h
src/libvlccore.sym
src/misc/objects.c
src/misc/variables.h

index 2e6914bfa397528989a4077215d2aa98f7e8982e..55715e615390e3737824091ac7ab629728ab310e 100644 (file)
@@ -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 */                             \
index 8489aaffcb63379ae1c63864638cb3b7b14953eb..c6708750ee9cd68a9fce0246f019ad8aec80432b 100644 (file)
@@ -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) )
 
 /** @} */
index a3cfbd495ef4b15e958555a80875ef7fdb073277..04dfbc890f86b05bf038f521014719b6b99281ea 100644 (file)
@@ -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
index 292bba3ea58fc19abe541347a1674048f9ee6bdd..3e365bda3c66cc936d5f74eb4bdd9b4bed557ef1 100644 (file)
@@ -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
index 671f3375894295b33145e1c560e60b21f80328e0..8c203b686749226e31d9b918942d428cf84b688e 100644 (file)
@@ -41,6 +41,7 @@ struct vlc_object_internals
 
     /* Objects thread synchronization */
     int             pipes[2];
+    atomic_bool     alive;
 
     /* Objects management */
     atomic_uint     refs;