mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 13:21:29 +02:00
CLEANUP: vars: use the item API for the variables trees
The variables trees use the immediate cebtree API, better use the item one which is more expressive and safer. The "node" field was renamed to "name_node" to avoid any ambiguity.
This commit is contained in:
parent
c058cc5ddf
commit
4edff4a2cc
@ -66,8 +66,8 @@ struct var_desc {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct var {
|
struct var {
|
||||||
struct ceb_node node; /* Used for chaining vars. */
|
struct ceb_node name_node; /* indexes <name_hash> below */
|
||||||
uint64_t name_hash; /* XXH3() of the variable's name, must be just after node */
|
uint64_t name_hash; /* XXH3() of the variable's name, indexed by <name_node> */
|
||||||
uint flags; // VF_*
|
uint flags; // VF_*
|
||||||
/* 32-bit hole here */
|
/* 32-bit hole here */
|
||||||
struct sample_data data; /* data storage. */
|
struct sample_data data; /* data storage. */
|
||||||
|
@ -80,17 +80,14 @@ static inline void vars_rdunlock(struct vars *vars)
|
|||||||
*/
|
*/
|
||||||
static inline void vars_prune(struct vars *vars, struct session *sess, struct stream *strm)
|
static inline void vars_prune(struct vars *vars, struct session *sess, struct stream *strm)
|
||||||
{
|
{
|
||||||
struct ceb_node *node;
|
|
||||||
struct var *var;
|
struct var *var;
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < VAR_NAME_ROOTS; i++) {
|
for (i = 0; i < VAR_NAME_ROOTS; i++) {
|
||||||
while ((node = cebu64_imm_first(&vars->name_root[i]))) {
|
while ((var = cebu64_item_first(&vars->name_root[i], name_node, name_hash, struct var)))
|
||||||
var = container_of(node, struct var, node);
|
|
||||||
size += var_clear(vars, var, 1);
|
size += var_clear(vars, var, 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!size)
|
if (!size)
|
||||||
return;
|
return;
|
||||||
|
19
src/vars.c
19
src/vars.c
@ -190,7 +190,8 @@ unsigned int var_clear(struct vars *vars, struct var *var, int force)
|
|||||||
var->data.type = SMP_T_ANY;
|
var->data.type = SMP_T_ANY;
|
||||||
|
|
||||||
if (!(var->flags & VF_PERMANENT) || force) {
|
if (!(var->flags & VF_PERMANENT) || force) {
|
||||||
cebu64_imm_delete(&vars->name_root[var->name_hash % VAR_NAME_ROOTS], &var->node);
|
cebu64_item_delete(&vars->name_root[var->name_hash % VAR_NAME_ROOTS],
|
||||||
|
name_node, name_hash, var);
|
||||||
pool_free(var_pool, var);
|
pool_free(var_pool, var);
|
||||||
size += sizeof(struct var);
|
size += sizeof(struct var);
|
||||||
}
|
}
|
||||||
@ -202,17 +203,14 @@ unsigned int var_clear(struct vars *vars, struct var *var, int force)
|
|||||||
*/
|
*/
|
||||||
void vars_prune_per_sess(struct vars *vars)
|
void vars_prune_per_sess(struct vars *vars)
|
||||||
{
|
{
|
||||||
struct ceb_node *node;
|
|
||||||
struct var *var;
|
struct var *var;
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < VAR_NAME_ROOTS; i++) {
|
for (i = 0; i < VAR_NAME_ROOTS; i++) {
|
||||||
while ((node = cebu64_imm_first(&vars->name_root[i]))) {
|
while ((var = cebu64_item_first(&vars->name_root[i], name_node, name_hash, struct var)))
|
||||||
var = container_of(node, struct var, node);
|
|
||||||
size += var_clear(vars, var, 1);
|
size += var_clear(vars, var, 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!size)
|
if (!size)
|
||||||
return;
|
return;
|
||||||
@ -334,13 +332,8 @@ static int vars_fill_desc(const char *name, int len, struct var_desc *desc, char
|
|||||||
*/
|
*/
|
||||||
static struct var *var_get(struct vars *vars, uint64_t name_hash)
|
static struct var *var_get(struct vars *vars, uint64_t name_hash)
|
||||||
{
|
{
|
||||||
struct ceb_node *node;
|
return cebu64_item_lookup(&vars->name_root[name_hash % VAR_NAME_ROOTS],
|
||||||
|
name_node, name_hash, name_hash, struct var);
|
||||||
node = cebu64_imm_lookup(&vars->name_root[name_hash % VAR_NAME_ROOTS], name_hash);
|
|
||||||
if (node)
|
|
||||||
return container_of(node, struct var, node);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 0 if fails, else returns 1. */
|
/* Returns 0 if fails, else returns 1. */
|
||||||
@ -439,7 +432,7 @@ int var_set(const struct var_desc *desc, struct sample *smp, uint flags)
|
|||||||
var->name_hash = desc->name_hash;
|
var->name_hash = desc->name_hash;
|
||||||
var->flags = flags & VF_PERMANENT;
|
var->flags = flags & VF_PERMANENT;
|
||||||
var->data.type = SMP_T_ANY;
|
var->data.type = SMP_T_ANY;
|
||||||
cebu64_imm_insert(&vars->name_root[var->name_hash % VAR_NAME_ROOTS], &var->node);
|
cebu64_item_insert(&vars->name_root[var->name_hash % VAR_NAME_ROOTS], name_node, name_hash, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A variable of type SMP_T_ANY is considered as unset (either created
|
/* A variable of type SMP_T_ANY is considered as unset (either created
|
||||||
|
Loading…
x
Reference in New Issue
Block a user