vlc_mutex_init( &p_priv->lock );
vlc_cond_init( &p_priv->wait );
vlc_mutex_init( &p_priv->var_lock );
+ vlc_cond_init( &p_priv->var_wait );
vlc_spin_init( &p_priv->spin );
p_priv->pipes[0] = p_priv->pipes[1] = -1;
}
free( p_priv->p_vars );
+ vlc_cond_destroy( &p_priv->var_wait );
vlc_mutex_destroy( &p_priv->var_lock );
free( p_this->psz_header );
p_var = &p_priv->p_vars[i_var];
p_var->b_incallback = false;
+ vlc_cond_broadcast( &p_priv->var_wait );
}
/* Free data if needed */
p_var = &p_priv->p_vars[i_var];
p_var->b_incallback = false;
+ vlc_cond_broadcast( &p_priv->var_wait );
}
vlc_mutex_unlock( &p_priv->var_lock );
/* Following functions are local */
/*****************************************************************************
- * GetUnused: find an unused variable from its name
+ * GetUnused: find an unused (not in callback) variable from its name
*****************************************************************************
* We do i_tries tries before giving up, just in case the variable is being
* modified and called from a callback.
*****************************************************************************/
static int GetUnused( vlc_object_t *p_this, const char *psz_name )
{
- int i_var, i_tries = 0;
vlc_object_internals_t *p_priv = vlc_internals( p_this );
while( true )
{
+ int i_var;
+
i_var = Lookup( p_priv->p_vars, p_priv->i_vars, psz_name );
if( i_var < 0 )
{
return i_var;
}
- if( i_tries++ > 100 )
- {
- msg_Err( p_this, "caught in a callback deadlock? ('%s')", psz_name );
- return VLC_ETIMEOUT;
- }
-
- vlc_mutex_unlock( &p_priv->var_lock );
- msleep( THREAD_SLEEP );
- vlc_mutex_lock( &p_priv->var_lock );
+ mutex_cleanup_push( &p_priv->var_lock );
+ vlc_cond_wait( &p_priv->var_wait, &p_priv->var_lock );
+ vlc_cleanup_pop( );
}
}