[vlc-devel] commit: Have vlc_object_wait() to "return" void. ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat May 31 17:59:28 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat May 31 18:40:15 2008 +0300| [0adb6e3edef57a255a4c405fbecdce5f6f1dd03c]

Have vlc_object_wait() to "return" void.

It was a misdesign to have it return b_die, due to the race condition
mentioned earlier.

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

 include/vlc_objects.h |   12 ++++++++----
 src/misc/objects.c    |   20 +++++++++++---------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index 575e0ec..9952987 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -162,7 +162,7 @@ VLC_EXPORT( void, __vlc_object_unlock, ( vlc_object_t * ) );
 #define vlc_object_unlock( obj ) \
     __vlc_object_unlock( VLC_OBJECT( obj ) )
 
-VLC_EXPORT( bool, __vlc_object_wait, ( vlc_object_t * ) );
+VLC_EXPORT( void, __vlc_object_wait, ( vlc_object_t * ) );
 #define vlc_object_wait( obj ) \
     __vlc_object_wait( VLC_OBJECT( obj ) )
 
@@ -201,11 +201,15 @@ VLC_EXPORT( int, __vlc_object_waitpipe, ( vlc_object_t *obj ));
 static inline
 bool __vlc_object_lock_and_wait( vlc_object_t *obj )
 {
-    bool b = true;
+    bool b;
 
     vlc_object_lock( obj );
-    if( vlc_object_alive( obj ) )
-        b = vlc_object_wait( obj );
+    b = vlc_object_alive( obj );
+    if( b )
+    {
+        vlc_object_wait( obj );
+        b = vlc_object_alive( obj );
+    }
     vlc_object_unlock( obj );
     return b;
 }
diff --git a/src/misc/objects.c b/src/misc/objects.c
index d7cdff0..a108f3d 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -527,24 +527,23 @@ int __vlc_object_waitpipe( vlc_object_t *obj )
 
 /**
  * Waits for the object to be signaled (using vlc_object_signal()).
- * If the object already has a signal pending, this function will return
- * immediately. It is asserted that the caller holds the object lock.
+ * It is assumed that the caller has locked the object. This function will
+ * unlock the object, and lock it again before returning.
+ * If the object was signaled before the caller locked the object, it is
+ * undefined whether the signal will be lost or will wake the process.
  *
  * @return true if the object is dying and should terminate.
  */
-bool __vlc_object_wait( vlc_object_t *obj )
+void __vlc_object_wait( vlc_object_t *obj )
 {
     vlc_assert_locked( &obj->object_lock );
     vlc_cond_wait( &obj->object_wait, &obj->object_lock );
-    return obj->b_die;
 }
 
 
 /**
  * Waits for the object to be signaled (using vlc_object_signal()), or for
- * a timer to expire.
- * If the object already has a signal pending, this function will return
- * immediately. It is asserted that the caller holds the object lock.
+ * a timer to expire. It is asserted that the caller holds the object lock.
  *
  * @return negative if the object is dying and should terminate,
  * positive if the the object has been signaled but is not dying,
@@ -574,8 +573,7 @@ int __vlc_object_timedwait( vlc_object_t *obj, mtime_t deadline )
    {
        ...preprocessing...
 
-       if (vlc_object_wait (self))
-           continue;
+       vlc_object_wait (self);
 
        ...postprocessing...
    }
@@ -594,6 +592,10 @@ bool __vlc_object_alive( vlc_object_t *obj )
 
 /**
  * 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
+ * such thread in the first place. Otherwise, it is undefined whether the
+ * signal will be lost or will wake up one or more thread later.
  */
 void __vlc_object_signal_unlocked( vlc_object_t *obj )
 {




More information about the vlc-devel mailing list