Commit 754491fc authored by Rémi Duraffort's avatar Rémi Duraffort

variables: var_IncInteger and var_DecInteger are now atomic.

parent e533549b
......@@ -124,6 +124,11 @@
* \param val Unused
*/
#define VLC_VAR_TOGGLE_BOOL 0x0010
/**
* Increment or decrement an integer of a given value
* \param val the value
*/
#define VLC_VAR_INTEGER_INCDEC 0x0020
/**@}*/
/*****************************************************************************
......@@ -443,8 +448,9 @@ static inline char *__var_GetNonEmptyString( vlc_object_t *p_obj, const char *ps
*/
static inline void __var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
{
int i_val = __var_GetInteger( p_obj, psz_name );
__var_SetInteger( p_obj, psz_name, ++i_val );
vlc_value_t val;
val.i_int = 1;
__var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_INCDEC, val );
}
#define var_IncInteger(a,b) __var_IncInteger( VLC_OBJECT(a), b )
......@@ -455,8 +461,9 @@ static inline void __var_IncInteger( vlc_object_t *p_obj, const char *psz_name )
*/
static inline void __var_DecInteger( vlc_object_t *p_obj, const char *psz_name )
{
int i_val = __var_GetInteger( p_obj, psz_name );
__var_SetInteger( p_obj, psz_name, --i_val );
vlc_value_t val;
val.i_int = -1;
__var_GetAndSet( p_obj, psz_name, VLC_VAR_INTEGER_INCDEC, val );
}
#define var_DecInteger(a,b) __var_DecInteger( VLC_OBJECT(a), b )
......
......@@ -704,6 +704,10 @@ int __var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action,
assert( ( p_var->i_type & VLC_VAR_BOOL ) == VLC_VAR_BOOL );
p_var->val.b_bool = !p_var->val.b_bool;
break;
case VLC_VAR_INTEGER_INCDEC:
assert( ( p_var->i_type & VLC_VAR_INTEGER ) == VLC_VAR_INTEGER );
p_var->val.i_int += val.i_int;
break;
default:
vlc_mutex_unlock( &p_priv->var_lock );
return VLC_EGENERIC;
......
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