1 #define NETDATA_RRD_INTERNALS 1
4 // ----------------------------------------------------------------------------
7 int rrdfamily_compare(void *a, void *b) {
8 if(((RRDFAMILY *)a)->hash_family < ((RRDFAMILY *)b)->hash_family) return -1;
9 else if(((RRDFAMILY *)a)->hash_family > ((RRDFAMILY *)b)->hash_family) return 1;
10 else return strcmp(((RRDFAMILY *)a)->family, ((RRDFAMILY *)b)->family);
13 #define rrdfamily_index_add(host, rc) (RRDFAMILY *)avl_insert_lock(&((host)->rrdfamily_root_index), (avl *)(rc))
14 #define rrdfamily_index_del(host, rc) (RRDFAMILY *)avl_remove_lock(&((host)->rrdfamily_root_index), (avl *)(rc))
16 static RRDFAMILY *rrdfamily_index_find(RRDHOST *host, const char *id, uint32_t hash) {
19 tmp.hash_family = (hash)?hash:simple_hash(tmp.family);
21 return (RRDFAMILY *)avl_search_lock(&(host->rrdfamily_root_index), (avl *) &tmp);
24 RRDFAMILY *rrdfamily_create(RRDHOST *host, const char *id) {
25 RRDFAMILY *rc = rrdfamily_index_find(host, id, 0);
27 rc = callocz(1, sizeof(RRDFAMILY));
29 rc->family = strdupz(id);
30 rc->hash_family = simple_hash(rc->family);
32 // initialize the variables index
33 avl_init_lock(&rc->variables_root_index, rrdvar_compare);
35 RRDFAMILY *ret = rrdfamily_index_add(host, rc);
37 fatal("RRDFAMILY: INTERNAL ERROR: Expected to INSERT RRDFAMILY '%s' into index, but inserted '%s'.", rc->family, (ret)?ret->family:"NONE");
44 void rrdfamily_free(RRDHOST *host, RRDFAMILY *rc) {
47 RRDFAMILY *ret = rrdfamily_index_del(host, rc);
49 fatal("RRDFAMILY: INTERNAL ERROR: Expected to DELETE RRDFAMILY '%s' from index, but deleted '%s'.", rc->family, (ret)?ret->family:"NONE");
51 if(rc->variables_root_index.avl_tree.root != NULL)
52 fatal("RRDFAMILY: INTERNAL ERROR: Variables index of RRDFAMILY '%s' that is freed, is not empty.", rc->family);
54 freez((void *)rc->family);