From 0adb6e3edef57a255a4c405fbecdce5f6f1dd03c Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 31 May 2008 18:40:15 +0300 Subject: [PATCH] Have vlc_object_wait() to "return" void. It was a misdesign to have it return b_die, due to the race condition mentioned earlier. --- 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 575e0ecad9..9952987d43 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 d7cdff0fc7..a108f3d42c 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 ) { -- 2.39.2