From e7f887862f7d4b942d014d97b9bfe58aac298728 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 30 Sep 2007 19:31:08 +0000 Subject: [PATCH] Partial unfinished pipes conditional fallback for condition variables. This would be necessary to rid the networking code of arbitrary timers (but it does not work yet). --- src/libvlc.h | 3 +++ src/misc/objects.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/libvlc.h b/src/libvlc.h index 3e98a79b48..7ae84def8e 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -111,6 +111,9 @@ struct vlc_object_internals_t vlc_thread_t thread_id; vlc_bool_t b_thread; + /* Objects thread synchronization */ + int pipes[2]; + /* Objects management */ unsigned i_refcount; vlc_bool_t b_attached; diff --git a/src/misc/objects.c b/src/misc/objects.c index 92f82f991c..1a15295b89 100644 --- a/src/misc/objects.c +++ b/src/misc/objects.c @@ -188,6 +188,7 @@ vlc_object_t *vlc_custom_create( vlc_object_t *p_this, size_t i_size, vlc_mutex_init( p_new, &p_new->object_lock ); vlc_cond_init( p_new, &p_new->object_wait ); vlc_mutex_init( p_new, &p_priv->var_lock ); + p_priv->pipes[0] = p_priv->pipes[1] = -1; if( i_type == VLC_OBJECT_GLOBAL ) { @@ -435,6 +436,10 @@ void __vlc_object_destroy( vlc_object_t *p_this ) vlc_mutex_destroy( &p_this->object_lock ); vlc_cond_destroy( &p_this->object_wait ); + if( p_priv->pipes[0] != -1 ) + close( p_priv->pipes[0] ); + if( p_priv->pipes[1] != -1 ) + close( p_priv->pipes[1] ); /* global is not dynamically allocated by vlc_object_create */ if( p_this->i_object_type != VLC_OBJECT_GLOBAL ) @@ -465,6 +470,15 @@ void __vlc_object_unlock( vlc_object_t *obj ) vlc_bool_t __vlc_object_wait( vlc_object_t *obj ) { vlc_assert_locked( &obj->object_lock ); + + int fd = obj->p_internals->pipes[0]; + if( ( fd != -1 ) + && ( read( fd, &(char){ 0 }, 1 ) == 0 ) ) + { + close( fd ); + obj->p_internals->pipes[1] = -1; + } + vlc_cond_wait( &obj->object_wait, &obj->object_lock ); return obj->b_die; } @@ -498,6 +512,11 @@ int __vlc_object_timedwait( vlc_object_t *obj, mtime_t deadline ) void __vlc_object_signal_unlocked( vlc_object_t *obj ) { vlc_assert_locked( &obj->object_lock ); + + int fd = obj->p_internals->pipes[1]; + if( fd != -1 ) + while( write( fd, &(char){ 0 }, 1 ) < 0 ); + vlc_cond_signal( &obj->object_wait ); } @@ -515,6 +534,14 @@ void __vlc_object_kill( vlc_object_t *p_this ) vlc_object_kill( p_this->pp_children[i] ); p_this->b_die = VLC_TRUE; + + int fd = p_this->p_internals->pipes[1]; + if( fd != -1 ) + { + close( fd ); + p_this->p_internals->pipes[1] = -1; + } + vlc_object_signal_unlocked( p_this ); vlc_mutex_unlock( &p_this->object_lock ); } -- 2.39.2