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

puzzle: use atomic variables and flag instead of lock

parent 2db07444
......@@ -96,13 +96,12 @@ struct filter_sys_t
bool b_finished;
/* */
vlc_mutex_t lock;
bool b_change;
struct
{
int i_cols;
int i_rows;
bool b_blackslot;
atomic_flag b_uptodate;
atomic_bool b_blackslot;
atomic_uint i_cols;
atomic_uint i_rows;
} change;
};
......@@ -151,14 +150,13 @@ static int Open( vlc_object_t *p_this )
p_sys->pi_order = NULL;
vlc_mutex_init( &p_sys->lock );
p_sys->change.i_rows =
var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "rows" );
p_sys->change.i_cols =
var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "cols" );
p_sys->change.b_blackslot =
var_CreateGetBoolCommand( p_filter, CFG_PREFIX "black-slot" );
p_sys->b_change = true;
atomic_init( &p_sys->change.i_rows,
var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "rows" ) );
atomic_init( &p_sys->change.i_cols,
var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "cols" ) );
atomic_init( &p_sys->change.b_blackslot,
var_CreateGetBoolCommand( p_filter, CFG_PREFIX "black-slot" ) );
p_sys->change.b_uptodate = ATOMIC_FLAG_INIT;
var_AddCallback( p_filter, CFG_PREFIX "rows", PuzzleCallback, p_sys );
var_AddCallback( p_filter, CFG_PREFIX "cols", PuzzleCallback, p_sys );
......@@ -182,7 +180,6 @@ static void Close( vlc_object_t *p_this )
var_DelCallback( p_filter, CFG_PREFIX "cols", PuzzleCallback, p_sys );
var_DelCallback( p_filter, CFG_PREFIX "black-slot", PuzzleCallback, p_sys );
vlc_mutex_destroy( &p_sys->lock );
free( p_sys->pi_order );
free( p_sys );
......@@ -203,17 +200,13 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
}
/* */
vlc_mutex_lock( &p_sys->lock );
if( p_sys->b_change )
if( !atomic_flag_test_and_set( &p_sys->change.b_uptodate ) )
{
p_sys->i_rows = p_sys->change.i_rows;
p_sys->i_cols = p_sys->change.i_cols;
p_sys->b_blackslot = p_sys->change.b_blackslot;
p_sys->b_change = false;
p_sys->i_rows = atomic_load( &p_sys->change.i_rows );
p_sys->i_cols = atomic_load( &p_sys->change.i_cols );
p_sys->b_blackslot = atomic_load( &p_sys->change.b_blackslot );
Shuffle( p_sys );
}
vlc_mutex_unlock( &p_sys->lock );
/* */
const int i_rows = p_sys->i_rows;
......@@ -309,7 +302,7 @@ static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse,
if( b_clicked &&
p_new->i_x < SHUFFLE_WIDTH && p_new->i_y < SHUFFLE_HEIGHT )
{
p_sys->b_change = true;
atomic_flag_clear( &p_sys->change.b_uptodate );
return VLC_EGENERIC;
}
else
......@@ -359,23 +352,15 @@ static int PuzzleCallback( vlc_object_t *p_this, char const *psz_var,
void *p_data )
{
VLC_UNUSED(p_this); VLC_UNUSED(oldval);
filter_sys_t *p_sys = (filter_sys_t *)p_data;
filter_sys_t *p_sys = p_data;
vlc_mutex_lock( &p_sys->lock );
if( !strcmp( psz_var, CFG_PREFIX "rows" ) )
{
p_sys->change.i_rows = __MAX( 1, newval.i_int );
}
atomic_store( &p_sys->change.i_rows, __MAX( 1, newval.i_int ) );
else if( !strcmp( psz_var, CFG_PREFIX "cols" ) )
{
p_sys->change.i_cols = __MAX( 1, newval.i_int );
}
atomic_store( &p_sys->change.i_cols, __MAX( 1, newval.i_int ) );
else if( !strcmp( psz_var, CFG_PREFIX "black-slot" ) )
{
p_sys->change.b_blackslot = newval.b_bool;
}
p_sys->b_change = true;
vlc_mutex_unlock( &p_sys->lock );
atomic_store( &p_sys->change.b_blackslot, newval.b_bool );
atomic_flag_clear( &p_sys->change.b_uptodate );
return VLC_SUCCESS;
}
......
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