Commit e7f88786 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

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).
parent 7b4638dd
...@@ -111,6 +111,9 @@ struct vlc_object_internals_t ...@@ -111,6 +111,9 @@ struct vlc_object_internals_t
vlc_thread_t thread_id; vlc_thread_t thread_id;
vlc_bool_t b_thread; vlc_bool_t b_thread;
/* Objects thread synchronization */
int pipes[2];
/* Objects management */ /* Objects management */
unsigned i_refcount; unsigned i_refcount;
vlc_bool_t b_attached; vlc_bool_t b_attached;
......
...@@ -188,6 +188,7 @@ vlc_object_t *vlc_custom_create( vlc_object_t *p_this, size_t i_size, ...@@ -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_mutex_init( p_new, &p_new->object_lock );
vlc_cond_init( p_new, &p_new->object_wait ); vlc_cond_init( p_new, &p_new->object_wait );
vlc_mutex_init( p_new, &p_priv->var_lock ); vlc_mutex_init( p_new, &p_priv->var_lock );
p_priv->pipes[0] = p_priv->pipes[1] = -1;
if( i_type == VLC_OBJECT_GLOBAL ) if( i_type == VLC_OBJECT_GLOBAL )
{ {
...@@ -435,6 +436,10 @@ void __vlc_object_destroy( vlc_object_t *p_this ) ...@@ -435,6 +436,10 @@ void __vlc_object_destroy( vlc_object_t *p_this )
vlc_mutex_destroy( &p_this->object_lock ); vlc_mutex_destroy( &p_this->object_lock );
vlc_cond_destroy( &p_this->object_wait ); 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 */ /* global is not dynamically allocated by vlc_object_create */
if( p_this->i_object_type != VLC_OBJECT_GLOBAL ) if( p_this->i_object_type != VLC_OBJECT_GLOBAL )
...@@ -465,6 +470,15 @@ void __vlc_object_unlock( vlc_object_t *obj ) ...@@ -465,6 +470,15 @@ void __vlc_object_unlock( vlc_object_t *obj )
vlc_bool_t __vlc_object_wait( vlc_object_t *obj ) vlc_bool_t __vlc_object_wait( vlc_object_t *obj )
{ {
vlc_assert_locked( &obj->object_lock ); 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 ); vlc_cond_wait( &obj->object_wait, &obj->object_lock );
return obj->b_die; return obj->b_die;
} }
...@@ -498,6 +512,11 @@ int __vlc_object_timedwait( vlc_object_t *obj, mtime_t deadline ) ...@@ -498,6 +512,11 @@ int __vlc_object_timedwait( vlc_object_t *obj, mtime_t deadline )
void __vlc_object_signal_unlocked( vlc_object_t *obj ) void __vlc_object_signal_unlocked( vlc_object_t *obj )
{ {
vlc_assert_locked( &obj->object_lock ); 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 ); vlc_cond_signal( &obj->object_wait );
} }
...@@ -515,6 +534,14 @@ void __vlc_object_kill( vlc_object_t *p_this ) ...@@ -515,6 +534,14 @@ void __vlc_object_kill( vlc_object_t *p_this )
vlc_object_kill( p_this->pp_children[i] ); vlc_object_kill( p_this->pp_children[i] );
p_this->b_die = VLC_TRUE; 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_object_signal_unlocked( p_this );
vlc_mutex_unlock( &p_this->object_lock ); vlc_mutex_unlock( &p_this->object_lock );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment