]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: vars: centralize the lock/unlock into static inlines
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:19:57 +0000 (15:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:19:57 +0000 (15:19 +0200)
The goal it to simplify the variables locking in order to later
simplify it.

include/haproxy/vars.h
src/vars.c

index bc27e37989e378377c3ad12aab84a52de373786e..30e6fe0c8841772bdd10609093078d315ad1e470 100644 (file)
@@ -41,4 +41,28 @@ int vars_unset_by_name_ifexist(const char *name, size_t len, struct sample *smp)
 int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp, const struct buffer *def);
 int vars_check_arg(struct arg *arg, char **err);
 
+/* locks the <vars> for writes */
+static inline void vars_wrlock(struct vars *vars)
+{
+       HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
+}
+
+/* unlocks the <vars> for writes */
+static inline void vars_wrunlock(struct vars *vars)
+{
+       HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
+}
+
+/* locks the <vars> for reads */
+static inline void vars_rdlock(struct vars *vars)
+{
+       HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
+}
+
+/* unlocks the <vars> for reads */
+static inline void vars_rdunlock(struct vars *vars)
+{
+       HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
+}
+
 #endif
index df76d980faa9086e4ca8eba35efe7d545902a941..0eaa4c9e91dbf37cc0f0951d666194fdc3af1bce 100644 (file)
@@ -168,11 +168,11 @@ void vars_prune(struct vars *vars, struct session *sess, struct stream *strm)
        struct var *var, *tmp;
        unsigned int size = 0;
 
-       HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrlock(vars);
        list_for_each_entry_safe(var, tmp, &vars->head, l) {
                size += var_clear(var, 1);
        }
-       HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrunlock(vars);
        var_accounting_diff(vars, sess, strm, -size);
 }
 
@@ -184,11 +184,11 @@ void vars_prune_per_sess(struct vars *vars)
        struct var *var, *tmp;
        unsigned int size = 0;
 
-       HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrlock(vars);
        list_for_each_entry_safe(var, tmp, &vars->head, l) {
                size += var_clear(var, 1);
        }
-       HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrunlock(vars);
 
        _HA_ATOMIC_SUB(&vars->size, size);
        _HA_ATOMIC_SUB(&proc_vars.size, size);
@@ -321,7 +321,7 @@ static int var_set(uint64_t name_hash, enum vars_scope scope, struct sample *smp
        if (!vars || vars->scope != scope)
                return 0;
 
-       HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrlock(vars);
 
        /* Look for existing variable name. */
        var = var_get(vars, name_hash);
@@ -422,7 +422,7 @@ static int var_set(uint64_t name_hash, enum vars_scope scope, struct sample *smp
        /* OK, now done */
        ret = 1;
  unlock:
-       HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrunlock(vars);
        return ret;
 }
 
@@ -441,13 +441,13 @@ static int var_unset(uint64_t name_hash, enum vars_scope scope, struct sample *s
                return 0;
 
        /* Look for existing variable name. */
-       HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrlock(vars);
        var = var_get(vars, name_hash);
        if (var) {
                size = var_clear(var, 0);
                var_accounting_diff(vars, smp->sess, smp->strm, -size);
        }
-       HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
+       vars_wrunlock(vars);
        return 1;
 }
 
@@ -565,11 +565,11 @@ static int var_to_smp(struct vars *vars, uint64_t name_hash, struct sample *smp,
        struct var *var;
 
        /* Get the variable entry. */
-       HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
+       vars_rdlock(vars);
        var = var_get(vars, name_hash);
        if (!var || !var->data.type) {
                if (!def) {
-                       HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
+                       vars_rdunlock(vars);
                        return 0;
                }
 
@@ -583,7 +583,7 @@ static int var_to_smp(struct vars *vars, uint64_t name_hash, struct sample *smp,
        /* Copy sample. */
        smp_dup(smp);
 
-       HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
+       vars_rdunlock(vars);
        return 1;
 }