3 int rrdvar_compare(void* a, void* b) {
4 if(((RRDVAR *)a)->hash < ((RRDVAR *)b)->hash) return -1;
5 else if(((RRDVAR *)a)->hash > ((RRDVAR *)b)->hash) return 1;
6 else return strcmp(((RRDVAR *)a)->name, ((RRDVAR *)b)->name);
9 #define rrdvar_index_add(tree, rv) (RRDVAR *)avl_insert_lock(tree, (avl *)(rv))
10 #define rrdvar_index_del(tree, rv) (RRDVAR *)avl_remove_lock(tree, (avl *)(rv))
12 static RRDVAR *rrdvar_index_find(avl_tree_lock *tree, const char *name, uint32_t hash) {
14 tmp.name = (char *)name;
15 tmp.hash = (hash)?hash:simple_hash(tmp.name);
17 return (RRDVAR *)avl_search_lock(tree, (avl *)&tmp);
21 RRDVAR *rrdvar_get(RRDHOST *host, RRDCONTEXT *co, RRDSET *st, const char *name) {
22 uint32_t hash = simple_hash(name);
25 RRDVAR *rv = rrdvar_index_find(&st->variables_root_index, name, hash);
27 rv = calloc(1, sizeof(RRDVAR));
28 if(!rv) fatal("Cannot allocate memory for RRDVAR");
30 rv->name = strdup(name);
31 if(!rv->name) fatal("Cannot allocate memory for RRDVAR name");
35 ret = rrdvar_index_add(&st->variables_root_index, rv);
37 error("Duplicate RRDVAR '%s' found on chart '%s'", name, st->id);
43 ret = rrdvar_index_add(&co->variables_root_index, rv);
45 debug(D_VARIABLES, "Variable '%s' in context '%s' does not come from chart '%s'", name, co->id, st->id);
47 ret = rrdvar_index_add(&host->variables_root_index, rv);
49 debug(D_VARIABLES, "Variable '%s' in host '%s' does not come from chart '%s'", name, host->hostname, st->id);