[vlc-devel] commit: vlc_object_alive: lock-less and inlined ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Jul 5 13:20:25 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Jul  5 14:22:09 2008 +0300| [da6732062b23f833e860da223901eeeb75eefaf7]

vlc_object_alive: lock-less and inlined

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

 include/vlc_objects.h |    7 ++++++-
 src/libvlccore.sym    |    1 -
 src/misc/objects.c    |   30 +-----------------------------
 3 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index a027dd9..c3b2078 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -162,7 +162,12 @@ VLC_EXPORT( void, __vlc_object_kill, ( vlc_object_t * ) );
 #define vlc_object_kill(a) \
     __vlc_object_kill( VLC_OBJECT(a) )
 
-VLC_EXPORT( bool, __vlc_object_alive, ( vlc_object_t * ) );
+static inline bool __vlc_object_alive (vlc_object_t *obj)
+{
+    barrier ();
+    return !obj->b_die;
+}
+
 #define vlc_object_alive(a) \
     __vlc_object_alive( VLC_OBJECT(a) )
 
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 698bd85..68438ae 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -433,7 +433,6 @@ vlc_module_set
 __vlc_mutex_destroy
 vlc_mutex_init
 vlc_mutex_init_recursive
-__vlc_object_alive
 __vlc_object_attach
 __vlc_object_create
 __vlc_object_detach
diff --git a/src/misc/objects.c b/src/misc/objects.c
index 74564e3..7e8e7ef 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -547,35 +547,6 @@ int __vlc_object_timedwait( vlc_object_t *obj, mtime_t deadline )
 
 
 /**
- * Checks whether an object has been "killed".
- * The object lock must be held.
- *
- * Typical code for an object thread could be:
- *
-   vlc_object_lock (self);
-   ...initialization...
-   while (vlc_object_alive (self))
-   {
-       ...preprocessing...
-
-       vlc_object_wait (self);
-
-       ...postprocessing...
-   }
-   ...deinitialization...
-   vlc_object_unlock (self);
- *
- *
- * @return true iff the object has not been killed yet
- */
-bool __vlc_object_alive( vlc_object_t *obj )
-{
-    vlc_assert_locked( &(vlc_internals(obj)->lock) );
-    return !obj->b_die;
-}
-
-
-/**
  * Signals an object for which the lock is held.
  * At least one thread currently sleeping in vlc_object_wait() or
  * vlc_object_timedwait() will wake up, assuming that there is at least one
@@ -613,6 +584,7 @@ void __vlc_object_kill( vlc_object_t *p_this )
     }
 
     vlc_object_signal_unlocked( p_this );
+    /* This also serves as a memory barrier toward vlc_object_alive(): */
     vlc_object_unlock( p_this );
 }
 




More information about the vlc-devel mailing list