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