[vlc-devel] commit: variables: var_IncInteger and var_DecInteger are now atomic. ( Rémi Duraffort )

git version control git at videolan.org
Thu Jul 30 14:34:04 CEST 2009


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Thu Jul 30 08:58:20 2009 +0200| [754491fcf0a7b389fae8d07210d8c8cd903bafb4] | committer: Rémi Duraffort 

variables: var_IncInteger and var_DecInteger are now atomic.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=754491fcf0a7b389fae8d07210d8c8cd903bafb4
---

 include/vlc_variables.h |   15 +++++++++++----
 src/misc/variables.c    |    4 ++++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index aaada0d..0c3767c 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -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 )
 
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 8042f98..485b9f5 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -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;




More information about the vlc-devel mailing list