char *name;
struct config_value *values;
- avl_tree values_index;
+ avl_tree_lock values_index;
struct config *next;
else return strcmp(((struct config_value *)a)->name, ((struct config_value *)b)->name);
}
-#define config_value_index_add(co, cv) avl_insert(&((co)->values_index), (avl *)(cv))
-#define config_value_index_del(co, cv) avl_remove(&((co)->values_index), (avl *)(cv))
+#define config_value_index_add(co, cv) avl_insert_lock(&((co)->values_index), (avl *)(cv))
+#define config_value_index_del(co, cv) avl_remove_lock(&((co)->values_index), (avl *)(cv))
static struct config_value *config_value_index_find(struct config *co, const char *name, uint32_t hash) {
struct config_value *result = NULL, tmp;
tmp.hash = (hash)?hash:simple_hash(name);
tmp.name = (char *)name;
- avl_search(&(co->values_index), (avl *)&tmp, config_value_iterator, (avl **)&result);
+ avl_search_lock(&(co->values_index), (avl *) &tmp, config_value_iterator, (avl **) &result);
return result;
}
else return strcmp(((struct config *)a)->name, ((struct config *)b)->name);
}
-avl_tree config_root_index = {
- NULL,
- config_compare,
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- PTHREAD_MUTEX_INITIALIZER
-#else
- PTHREAD_RWLOCK_INITIALIZER
-#endif
-#endif
+avl_tree_lock config_root_index = {
+ { NULL, config_compare },
+ AVL_LOCK_INITIALIZER
};
-#define config_index_add(cfg) avl_insert(&config_root_index, (avl *)(cfg))
-#define config_index_del(cfg) avl_remove(&config_root_index, (avl *)(cfg))
+#define config_index_add(cfg) avl_insert_lock(&config_root_index, (avl *)(cfg))
+#define config_index_del(cfg) avl_remove_lock(&config_root_index, (avl *)(cfg))
static struct config *config_index_find(const char *name, uint32_t hash) {
struct config *result = NULL, tmp;
tmp.hash = (hash)?hash:simple_hash(name);
tmp.name = (char *)name;
- avl_search(&config_root_index, (avl *)&tmp, config_iterator, (avl **)&result);
+ avl_search_lock(&config_root_index, (avl *) &tmp, config_iterator, (avl **) &result);
return result;
}
co->hash = simple_hash(co->name);
pthread_rwlock_init(&co->rwlock, NULL);
- avl_init(&co->values_index, config_value_compare);
+ avl_init_lock(&co->values_index, config_value_compare);
config_index_add(co);
avl_tree all_files_index = {
NULL,
- file_descriptor_compare,
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- PTHREAD_MUTEX_INITIALIZER
-#else
- PTHREAD_RWLOCK_INITIALIZER
-#endif
-#endif /* AVL_WITHOUT_PTHREADS */
+ file_descriptor_compare
};
static struct file_descriptor *file_descriptor_find(const char *name, uint32_t hash) {
tmp.magic = 0x0BADCAFE;
#endif /* NETDATA_INTERNAL_CHECKS */
- avl_search(&all_files_index, (avl *)&tmp, file_descriptor_iterator, (avl **)&result);
+ avl_search(&all_files_index, (avl *) &tmp, file_descriptor_iterator, (avl **) &result);
return result;
}
#include "avl.h"
#include "log.h"
-/* Private methods */
-int _avl_removeroot(avl_tree* t);
-
/* Swing to the left
* Warning: no balance maintainance
*/
* returns 1 if the depth of the tree has grown
* Warning: do not insert elements already present
*/
-int _avl_insert(avl_tree* t, avl* a) {
+int avl_insert(avl_tree* t, avl* a) {
/* initialize */
a->left = 0;
a->right = 0;
avl_tree left_subtree;
left_subtree.root = t->root->left;
left_subtree.compar = t->compar;
- if (_avl_insert(&left_subtree, a)) {
+ if (avl_insert(&left_subtree, a)) {
switch (t->root->balance--) {
case 1:
return 0;
avl_tree right_subtree;
right_subtree.root = t->root->right;
right_subtree.compar = t->compar;
- if (_avl_insert(&right_subtree, a)) {
+ if (avl_insert(&right_subtree, a)) {
switch (t->root->balance++) {
case -1:
return 0;
}
}
}
-int avl_insert(avl_tree* t, avl* a) {
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- pthread_mutex_lock(&t->mutex);
-#else
- pthread_rwlock_wrlock(&t->rwlock);
-#endif
-#endif /* AVL_WITHOUT_PTHREADS */
-
- int ret = _avl_insert(t, a);
-
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- pthread_mutex_unlock(&t->mutex);
-#else
- pthread_rwlock_unlock(&t->rwlock);
-#endif
-#endif /* AVL_WITHOUT_PTHREADS */
- return ret;
-}
/* Remove an element a from the AVL tree t
* returns -1 if the depth of the tree has shrunk
* Warning: if the element is not present in the tree,
* returns 0 as if it had been removed succesfully.
*/
-int _avl_remove(avl_tree* t, avl* a) {
+int avl_remove(avl_tree* t, avl* a) {
int b;
if (t->root == a)
- return _avl_removeroot(t);
+ return avl_removeroot(t);
b = t->compar(t->root, a);
if (b >= 0) {
/* remove from the left subtree */
avl_tree left_subtree;
if ((left_subtree.root = t->root->left)) {
left_subtree.compar = t->compar;
- ch = _avl_remove(&left_subtree, a);
+ ch = avl_remove(&left_subtree, a);
t->root->left = left_subtree.root;
if (ch) {
switch (t->root->balance++) {
avl_tree right_subtree;
if ((right_subtree.root = t->root->right)) {
right_subtree.compar = t->compar;
- ch = _avl_remove(&right_subtree, a);
+ ch = avl_remove(&right_subtree, a);
t->root->right = right_subtree.root;
if (ch) {
switch (t->root->balance--) {
return 0;
}
-int avl_remove(avl_tree* t, avl* a) {
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- pthread_mutex_lock(&t->mutex);
-#else
- pthread_rwlock_wrlock(&t->rwlock);
-#endif
-#endif /* AVL_WITHOUT_PTHREADS */
-
- int ret = _avl_remove(t, a);
-
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- pthread_mutex_unlock(&t->mutex);
-#else
- pthread_rwlock_unlock(&t->rwlock);
-#endif
-#endif /* AVL_WITHOUT_PTHREADS */
- return ret;
-}
-
/* Remove the root of the AVL tree t
* Warning: dumps core if t is empty
*/
-int _avl_removeroot(avl_tree* t) {
+int avl_removeroot(avl_tree* t) {
int ch;
avl* a;
if (!t->root->left) {
while (a->left)
a = a->left;
}
- ch = _avl_remove(t, a);
+ ch = avl_remove(t, a);
a->left = t->root->left;
a->right = t->root->right;
a->balance = t->root->balance;
return 0;
}
-int avl_removeroot(avl_tree* t) {
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- pthread_mutex_lock(&t->mutex);
-#else
- pthread_rwlock_wrlock(&t->rwlock);
-#endif
-#endif /* AVL_WITHOUT_PTHREADS */
-
- int ret = _avl_removeroot(t);
-
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- pthread_mutex_unlock(&t->mutex);
-#else
- pthread_rwlock_unlock(&t->rwlock);
-#endif
-#endif /* AVL_WITHOUT_PTHREADS */
- return ret;
-}
-
/* Iterate through elements in t from a range between a and b (inclusive)
* for each element calls iter(a) until it returns 0
* returns the last value returned by iterator or 0 if there were no calls
* Warning: a<=b must hold
*/
-int _avl_range(avl_tree* t, avl* a, avl* b, int (*iter)(avl*), avl** ret) {
+int avl_range(avl_tree* t, avl* a, avl* b, int (*iter)(avl*), avl** ret) {
int x, c = 0;
if (!t->root)
return 0;
avl_tree left_subtree;
if ((left_subtree.root = t->root->left)) {
left_subtree.compar = t->compar;
- if (!(c = _avl_range(&left_subtree, a, b, iter, ret)))
+ if (!(c = avl_range(&left_subtree, a, b, iter, ret)))
if (x > 0)
return 0;
}
avl_tree right_subtree;
if ((right_subtree.root = t->root->right)) {
right_subtree.compar = t->compar;
- if (!(c = _avl_range(&right_subtree, a, b, iter, ret)))
+ if (!(c = avl_range(&right_subtree, a, b, iter, ret)))
if (x < 0)
return 0;
}
return c;
}
-int avl_range(avl_tree* t, avl* a, avl* b, int (*iter)(avl*), avl** ret) {
+void avl_init(avl_tree *t, int (*compar)(void *a, void *b)) {
+ t->root = NULL;
+ t->compar = compar;
+}
+
+/* ------------------------------------------------------------------------- */
+
+void avl_lock(avl_tree_lock *t) {
#ifndef AVL_WITHOUT_PTHREADS
#ifdef AVL_LOCK_WITH_MUTEX
pthread_mutex_lock(&t->mutex);
pthread_rwlock_wrlock(&t->rwlock);
#endif
#endif /* AVL_WITHOUT_PTHREADS */
+}
- int ret2 = _avl_range(t, a, b, iter, ret);
-
+void avl_unlock(avl_tree_lock *t) {
#ifndef AVL_WITHOUT_PTHREADS
#ifdef AVL_LOCK_WITH_MUTEX
pthread_mutex_unlock(&t->mutex);
pthread_rwlock_unlock(&t->rwlock);
#endif
#endif /* AVL_WITHOUT_PTHREADS */
-
- return ret2;
}
-/* Iterate through elements in t equal to a
- * for each element calls iter(a) until it returns 0
- * returns the last value returned by iterator or 0 if there were no calls
- */
-int avl_search(avl_tree* t, avl* a, int (*iter)(avl* a), avl** ret) {
- return avl_range(t, a, a, iter, ret);
-}
+/* ------------------------------------------------------------------------- */
-void avl_init(avl_tree* t, int (*compar)(void* a, void* b)) {
- t->root = NULL;
- t->compar = compar;
+void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b)) {
+ avl_init(&t->avl_tree, compar);
#ifndef AVL_WITHOUT_PTHREADS
int lock;
fatal("Failed to initialize AVL mutex/rwlock, error: %d", lock);
#endif /* AVL_WITHOUT_PTHREADS */
+}
+
+int avl_range_lock(avl_tree_lock *t, avl *a, avl *b, int (*iter)(avl *), avl **ret) {
+ avl_lock(t);
+ int ret2 = avl_range(&t->avl_tree, a, b, iter, ret);
+ avl_unlock(t);
+ return ret2;
+}
+int avl_removeroot_lock(avl_tree_lock *t) {
+ avl_lock(t);
+ int ret = avl_removeroot(&t->avl_tree);
+ avl_unlock(t);
+ return ret;
+}
+
+int avl_remove_lock(avl_tree_lock *t, avl *a) {
+ avl_lock(t);
+ int ret = avl_remove(&t->avl_tree, a);
+ avl_unlock(t);
+ return ret;
+}
+
+int avl_insert_lock(avl_tree_lock *t, avl *a) {
+ avl_lock(t);
+ int ret = avl_insert(&t->avl_tree, a);
+ avl_lock(t);
+ return ret;
}
#ifndef AVL_WITHOUT_PTHREADS
#include <pthread.h>
-#endif /* AVL_WITHOUT_PTHREADS */
// #define AVL_LOCK_WITH_MUTEX 1
+#ifdef AVL_LOCK_WITH_MUTEX
+#define AVL_LOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#else /* AVL_LOCK_WITH_MUTEX */
+#define AVL_LOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
+#endif /* AVL_LOCK_WITH_MUTEX */
+
+#else /* AVL_WITHOUT_PTHREADS */
+#define AVL_LOCK_INITIALIZER
+#endif /* AVL_WITHOUT_PTHREADS */
+
/* Data structures */
/* One element of the AVL tree */
/* An AVL tree */
typedef struct avl_tree {
- avl* root;
- int (*compar)(void* a, void* b);
+ avl *root;
+
+ int (*compar)(void *a, void *b);
+} avl_tree;
+
+typedef struct avl_tree_lock {
+ avl_tree avl_tree;
#ifndef AVL_WITHOUT_PTHREADS
#ifdef AVL_LOCK_WITH_MUTEX
pthread_rwlock_t rwlock;
#endif /* AVL_LOCK_WITH_MUTEX */
#endif /* AVL_WITHOUT_PTHREADS */
-} avl_tree;
+} avl_tree_lock;
/* Public methods */
* returns 1 if the depth of the tree has grown
* Warning: do not insert elements already present
*/
-int avl_insert(avl_tree* t, avl* a);
+int avl_insert_lock(avl_tree_lock *t, avl *a);
+int avl_insert(avl_tree *t, avl *a);
/* Remove an element a from the AVL tree t
* returns -1 if the depth of the tree has shrunk
* Warning: if the element is not present in the tree,
* returns 0 as if it had been removed succesfully.
*/
-int avl_remove(avl_tree* t, avl* a);
+int avl_remove_lock(avl_tree_lock *t, avl *a);
+int avl_remove(avl_tree *t, avl *a);
/* Remove the root of the AVL tree t
* Warning: dumps core if t is empty
*/
-int avl_removeroot(avl_tree* t);
+int avl_removeroot_lock(avl_tree_lock *t);
+int avl_removeroot(avl_tree *t);
/* Iterate through elements in t from a range between a and b (inclusive)
* for each element calls iter(a) until it returns 0
* returns the last value returned by iterator or 0 if there were no calls
* Warning: a<=b must hold
*/
-int avl_range(avl_tree* t, avl* a, avl* b, int (*iter)(avl*), avl** ret);
+int avl_range_lock(avl_tree_lock *t, avl *a, avl *b, int (*iter)(avl *), avl **ret);
+int avl_range(avl_tree *t, avl *a, avl *b, int (*iter)(avl *), avl **ret);
/* Iterate through elements in t equal to a
* for each element calls iter(a) until it returns 0
* returns the last value returned by iterator or 0 if there were no calls
*/
-int avl_search(avl_tree* t, avl* a, int (*iter)(avl*), avl** ret);
+#define avl_search_lock(t, a, iter, ret) avl_range_lock(t, a, a, iter, ret)
+#define avl_search(t, a, iter, ret) avl_range(t, a, a, iter, ret)
-/* Initialize the avl_tree
+/* Initialize the avl_tree_lock
*/
-void avl_init(avl_tree* t, int (*compar)(void* a, void* b));
+void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b));
+void avl_init(avl_tree *t, int (*compar)(void *a, void *b));
#endif /* avl.h */
// ----------------------------------------------------------------------------
// dictionary locks
-static inline void dictionary_atomic_updates_lock(DICTIONARY *dict) {
- if(likely(!(dict->flags & DICTIONARY_FLAG_SINGLE_THREADED))) {
- // debug(D_DICTIONARY, "Dictionary ATOMIC lock");
- pthread_mutex_lock(&dict->atomic_mutex);
- }
-}
-
-static inline void dictionary_atomic_updates_unlock(DICTIONARY *dict) {
- if(likely(!(dict->flags & DICTIONARY_FLAG_SINGLE_THREADED))) {
- // debug(D_DICTIONARY, "Dictionary ATOMIC unlock");
- pthread_mutex_unlock(&dict->atomic_mutex);
- }
-}
-
static inline void dictionary_read_lock(DICTIONARY *dict) {
if(likely(!(dict->flags & DICTIONARY_FLAG_SINGLE_THREADED))) {
// debug(D_DICTIONARY, "Dictionary READ lock");
tmp.name = (char *)name;
dict->searches++;
- avl_search(&(dict->values_index), (avl *)&tmp, name_value_iterator, (avl **)&result);
+ avl_search(&(dict->values_index), (avl *) &tmp, name_value_iterator, (avl **) &result);
return result;
}
avl_init(&dict->values_index, name_value_compare);
pthread_rwlock_init(&dict->rwlock, NULL);
- pthread_mutex_init(&dict->atomic_mutex, NULL);
dict->flags = flags;
void dictionary_destroy(DICTIONARY *dict) {
debug(D_DICTIONARY, "Destroying dictionary.");
- dictionary_atomic_updates_lock(dict);
-
dictionary_write_lock(dict);
while(dict->values_index.root)
dictionary_unlock(dict);
- dictionary_atomic_updates_unlock(dict);
-
free(dict);
}
uint32_t hash = simple_hash(name);
- dictionary_atomic_updates_lock(dict);
+ dictionary_write_lock(dict);
- dictionary_read_lock(dict);
NAME_VALUE *nv = dictionary_name_value_index_find_nolock(dict, name, hash);
- dictionary_unlock(dict);
-
if(unlikely(!nv)) {
debug(D_DICTIONARY, "Dictionary entry with name '%s' not found. Creating a new one.", name);
- dictionary_write_lock(dict);
nv = dictionary_name_value_create_nolock(dict, name, value, value_len, hash);
- dictionary_unlock(dict);
-
if(unlikely(!nv))
fatal("Cannot create name_value.");
}
}
}
- dictionary_atomic_updates_unlock(dict);
+ dictionary_unlock(dict);
return nv->value;
}
debug(D_DICTIONARY, "DEL dictionary entry with name '%s'.", name);
- dictionary_atomic_updates_lock(dict);
+ dictionary_write_lock(dict);
- dictionary_read_lock(dict);
NAME_VALUE *nv = dictionary_name_value_index_find_nolock(dict, name, 0);
- dictionary_unlock(dict);
-
if(unlikely(!nv)) {
debug(D_DICTIONARY, "Not found dictionary entry with name '%s'.", name);
ret = -1;
}
else {
debug(D_DICTIONARY, "Found dictionary entry with name '%s'.", name);
- dictionary_write_lock(dict);
dictionary_name_value_destroy_nolock(dict, nv);
- dictionary_unlock(dict);
ret = 0;
}
- dictionary_atomic_updates_unlock(dict);
+ dictionary_unlock(dict);
return ret;
}
} NAME_VALUE;
typedef struct dictionary {
- uint32_t flags;
+ avl_tree values_index;
+
+ uint8_t flags;
unsigned long long inserts;
unsigned long long deletes;
unsigned long long searches;
unsigned long long entries;
- avl_tree values_index;
pthread_rwlock_t rwlock;
- pthread_mutex_t atomic_mutex;
} DICTIONARY;
#define DICTIONARY_FLAG_DEFAULT 0x00000000
avl_tree tc_device_root_index = {
NULL,
- tc_device_compare,
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- PTHREAD_MUTEX_INITIALIZER
-#else
- PTHREAD_RWLOCK_INITIALIZER
-#endif
-#endif
+ tc_device_compare
};
#define tc_device_index_add(st) avl_insert(&tc_device_root_index, (avl *)(st))
#define tc_device_index_del(st) avl_remove(&tc_device_root_index, (avl *)(st))
-static struct tc_device *tc_device_index_find(const char *id, uint32_t hash) {
+static inline struct tc_device *tc_device_index_find(const char *id, uint32_t hash) {
struct tc_device *result = NULL, tmp;
tmp.id = (char *)id;
tmp.hash = (hash)?hash:simple_hash(tmp.id);
- avl_search(&(tc_device_root_index), (avl *)&tmp, tc_device_iterator, (avl **)&result);
+ avl_search(&(tc_device_root_index), (avl *) &tmp, tc_device_iterator, (avl **) &result);
return result;
}
#define tc_class_index_add(st, rd) avl_insert(&((st)->classes_index), (avl *)(rd))
#define tc_class_index_del(st, rd) avl_remove(&((st)->classes_index), (avl *)(rd))
-static struct tc_class *tc_class_index_find(struct tc_device *st, const char *id, uint32_t hash) {
+static inline struct tc_class *tc_class_index_find(struct tc_device *st, const char *id, uint32_t hash) {
struct tc_class *result = NULL, tmp;
tmp.id = (char *)id;
tmp.hash = (hash)?hash:simple_hash(tmp.id);
- avl_search(&(st->classes_index), (avl *)&tmp, tc_class_iterator, (avl **)&result);
+ avl_search(&(st->classes_index), (avl *) &tmp, tc_class_iterator, (avl **) &result);
return result;
}
// ----------------------------------------------------------------------------
-static void tc_class_free(struct tc_device *n, struct tc_class *c) {
+static inline void tc_class_free(struct tc_device *n, struct tc_class *c) {
debug(D_TC_LOOP, "Removing from device '%s' class '%s', parentid '%s', leafid '%s', seen=%d", n->id, c->id, c->parentid?c->parentid:"", c->leafid?c->leafid:"", c->seen);
if(c->next) c->next->prev = c->prev;
free(c);
}
-static void tc_device_classes_cleanup(struct tc_device *d) {
+static inline void tc_device_classes_cleanup(struct tc_device *d) {
static int cleanup_every = 999;
if(cleanup_every > 0) {
}
}
-static void tc_device_commit(struct tc_device *d)
+static inline void tc_device_commit(struct tc_device *d)
{
static int enable_new_interfaces = -1;
tc_device_classes_cleanup(d);
}
-static void tc_device_set_class_name(struct tc_device *d, char *id, char *name)
+static inline void tc_device_set_class_name(struct tc_device *d, char *id, char *name)
{
struct tc_class *c = tc_class_index_find(d, id, 0);
if(c) {
}
}
-static void tc_device_set_device_name(struct tc_device *d, char *name) {
+static inline void tc_device_set_device_name(struct tc_device *d, char *name) {
if(d->name) free(d->name);
d->name = NULL;
}
}
-static void tc_device_set_device_family(struct tc_device *d, char *family) {
+static inline void tc_device_set_device_family(struct tc_device *d, char *family) {
if(d->family) free(d->family);
d->family = NULL;
// no need for null termination - it is already null
}
-static struct tc_device *tc_device_create(char *id)
+static inline struct tc_device *tc_device_create(char *id)
{
struct tc_device *d = tc_device_index_find(id, 0);
d->id = strdup(id);
d->hash = simple_hash(d->id);
- d->classes_index.root = NULL;
- d->classes_index.compar = tc_class_compare;
-
- int lock;
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- lock = pthread_mutex_init(&d->classes_index.mutex, NULL);
-#else
- lock = pthread_rwlock_init(&d->classes_index.rwlock, NULL);
-#endif
-#endif
- if(lock != 0)
- fatal("Failed to initialize plugin_tc mutex/rwlock, return code %d.", lock);
-
+ avl_init(&d->classes_index, tc_class_compare);
tc_device_index_add(d);
if(!tc_device_root) {
return(d);
}
-static struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid, char *leafid)
+static inline struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid, char *leafid)
{
struct tc_class *c = tc_class_index_find(n, id, 0);
return(c);
}
-static void tc_device_free(struct tc_device *n)
+static inline void tc_device_free(struct tc_device *n)
{
if(n->next) n->next->prev = n->prev;
if(n->prev) n->prev->next = n->next;
free(n);
}
-static void tc_device_free_all()
+static inline void tc_device_free_all()
{
while(tc_device_root)
tc_device_free(tc_device_root);
}
}
-static void tc_split_words(char *str, char **words, int max_words) {
+static inline void tc_split_words(char *str, char **words, int max_words) {
char *s = str;
int i = 0;
else return strcmp(((RRDSET *)a)->id, ((RRDSET *)b)->id);
}
-avl_tree rrdset_root_index = {
- NULL,
- rrdset_compare,
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- PTHREAD_MUTEX_INITIALIZER
-#else
- PTHREAD_RWLOCK_INITIALIZER
-#endif
-#endif
+avl_tree_lock rrdset_root_index = {
+ { NULL, rrdset_compare },
+ AVL_LOCK_INITIALIZER
};
-#define rrdset_index_add(st) avl_insert(&rrdset_root_index, (avl *)(st))
-#define rrdset_index_del(st) avl_remove(&rrdset_root_index, (avl *)(st))
+#define rrdset_index_add(st) avl_insert_lock(&rrdset_root_index, (avl *)(st))
+#define rrdset_index_del(st) avl_remove_lock(&rrdset_root_index, (avl *)(st))
static RRDSET *rrdset_index_find(const char *id, uint32_t hash) {
RRDSET *result = NULL, tmp;
tmp.id[RRD_ID_LENGTH_MAX] = '\0';
tmp.hash = (hash)?hash:simple_hash(tmp.id);
- avl_search(&(rrdset_root_index), (avl *)&tmp, rrdset_iterator, (avl **)&result);
+ avl_search_lock(&(rrdset_root_index), (avl *) &tmp, rrdset_iterator, (avl **) &result);
return result;
}
else return strcmp(A->name, B->name);
}
-avl_tree rrdset_root_index_name = {
- NULL,
- rrdset_compare_name,
-#ifndef AVL_WITHOUT_PTHREADS
-#ifdef AVL_LOCK_WITH_MUTEX
- PTHREAD_MUTEX_INITIALIZER
-#else
- PTHREAD_RWLOCK_INITIALIZER
-#endif
-#endif
+avl_tree_lock rrdset_root_index_name = {
+ { NULL, rrdset_compare_name },
+ AVL_LOCK_INITIALIZER
};
int rrdset_index_add_name(RRDSET *st) {
// fprintf(stderr, "ADDING: %s (name: %s)\n", st->id, st->name);
- return avl_insert(&rrdset_root_index_name, (avl *)(&st->avlname));
+ return avl_insert_lock(&rrdset_root_index_name, (avl *) (&st->avlname));
}
-#define rrdset_index_del_name(st) avl_remove(&rrdset_root_index_name, (avl *)(&st->avlname))
+#define rrdset_index_del_name(st) avl_remove_lock(&rrdset_root_index_name, (avl *)(&st->avlname))
static RRDSET *rrdset_index_find_name(const char *name, uint32_t hash) {
void *result = NULL;
tmp.hash_name = (hash)?hash:simple_hash(tmp.name);
// fprintf(stderr, "SEARCHING: %s\n", name);
- avl_search(&(rrdset_root_index_name), (avl *)(&(tmp.avlname)), rrdset_iterator_name, (avl **)&result);
+ avl_search_lock(&(rrdset_root_index_name), (avl *) (&(tmp.avlname)), rrdset_iterator_name, (avl **) &result);
if(result) {
RRDSET *st = rrdset_from_avlname(result);
if(strcmp(st->magic, RRDSET_MAGIC))
else return strcmp(((RRDDIM *)a)->id, ((RRDDIM *)b)->id);
}
-#define rrddim_index_add(st, rd) avl_insert(&((st)->dimensions_index), (avl *)(rd))
-#define rrddim_index_del(st,rd ) avl_remove(&((st)->dimensions_index), (avl *)(rd))
+#define rrddim_index_add(st, rd) avl_insert_lock(&((st)->dimensions_index), (avl *)(rd))
+#define rrddim_index_del(st,rd ) avl_remove_lock(&((st)->dimensions_index), (avl *)(rd))
static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, uint32_t hash) {
RRDDIM *result = NULL, tmp;
tmp.id[RRD_ID_LENGTH_MAX] = '\0';
tmp.hash = (hash)?hash:simple_hash(tmp.id);
- avl_search(&(st->dimensions_index), (avl *)&tmp, rrddim_iterator, (avl **)&result);
+ avl_search_lock(&(st->dimensions_index), (avl *) &tmp, rrddim_iterator, (avl **) &result);
return result;
}
st->gap_when_lost_iterations_above = (int) (
config_get_number(st->id, "gap when lost iterations above", RRD_DEFAULT_GAP_INTERPOLATIONS) + 2);
- avl_init(&st->dimensions_index, rrddim_compare);
+ avl_init_lock(&st->dimensions_index, rrddim_compare);
pthread_rwlock_init(&st->rwlock, NULL);
pthread_rwlock_wrlock(&rrdset_root_rwlock);
// ------------------------------------------------------------------------
// the dimensions
- avl_tree dimensions_index; // the root of the dimensions index
+ avl_tree_lock dimensions_index; // the root of the dimensions index
RRDDIM *dimensions; // the actual data for every dimension
};
typedef struct rrdset RRDSET;