[vlc-devel] [PATCH 1/3] variables: add VLC_VAR_COMPARE_EXCHANGE

Rémi Denis-Courmont remi at remlab.net
Wed Jun 14 15:41:34 CEST 2017


On June 14, 2017 3:34:23 PM GMT+03:00, "Hugo Beauzée-Luyssen" <hugo at beauzee.fr> wrote:
>From: Thomas Guillem <thomas at gllm.fr>
>
>Behaves like atomic_compare_exchange but with vlc variables.
>---
> include/vlc_variables.h | 2 ++
> src/misc/variables.c    | 8 ++++++++
> 2 files changed, 10 insertions(+)
>
>diff --git a/include/vlc_variables.h b/include/vlc_variables.h
>index 83752b171f..15f5e7e803 100644
>--- a/include/vlc_variables.h
>+++ b/include/vlc_variables.h
>@@ -101,6 +101,8 @@
> #define VLC_VAR_CHOICESCOUNT        0x0026
> #define VLC_VAR_SETMINMAX           0x0027
> 
>+#define VLC_VAR_COMPARE_EXCHANGE    0x0028
>+
> /**@}*/
> 
> /** \defgroup var_GetAndSet Variable actions
>diff --git a/src/misc/variables.c b/src/misc/variables.c
>index 121ef5ea70..47131587e2 100644
>--- a/src/misc/variables.c
>+++ b/src/misc/variables.c
>@@ -559,6 +559,14 @@ int var_Change( vlc_object_t *p_this, const char
>*psz_name,
>             p_var->choices_text.p_values = NULL;
>TriggerListCallback(p_this, p_var, psz_name, VLC_VAR_CLEARCHOICES,
>NULL);
>             break;
>+        case VLC_VAR_COMPARE_EXCHANGE:
>+            if( p_var->ops->pf_cmp( p_var->val, *p_val ) != 0 )
>+            {
>+                ret = VLC_EBADVAR;
>+                break;
>+            }
>+            p_val = p_val2;
>+            /* Fall through */
>         case VLC_VAR_SETVALUE:
>             /* Duplicate data if needed */
>             newval = *p_val;
>-- 
>2.11.0
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

I have not checked the surrounding code, but I doubt that this works correctly if the data is a string or other non-scalar.
-- 
Rémi Denis-Courmont


More information about the vlc-devel mailing list