]> arthur.barton.de Git - netdata.git/blobdiff - src/avl.c
apps.plugin: major new features and optimizations: now it reports system usage (all...
[netdata.git] / src / avl.c
index e1684d254fd73cbaa010b4e07ec5046c592e2902..fd4fb1420637e0668597cbe94803f48b0b4622da 100644 (file)
--- a/src/avl.c
+++ b/src/avl.c
@@ -145,19 +145,23 @@ int _avl_insert(avl_tree* t, avl* a) {
        }
 }
 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;
 }
 
@@ -243,19 +247,23 @@ int _avl_remove(avl_tree* t, avl* a) {
 }
 
 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;
 }
 
@@ -299,19 +307,23 @@ int _avl_removeroot(avl_tree* t) {
 }
 
 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;
 }
 
@@ -363,19 +375,23 @@ 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) {
+#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 ret2 = _avl_range(t, a, b, iter, ret);
 
+#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 ret2;
 }
@@ -392,7 +408,9 @@ void avl_init(avl_tree* t, int (*compar)(void* a, void* b)) {
        t->root = NULL;
        t->compar = compar;
 
+#ifndef AVL_WITHOUT_PTHREADS
        int lock;
+
 #ifdef AVL_LOCK_WITH_MUTEX
        lock = pthread_mutex_init(&t->mutex, NULL);
 #else
@@ -401,4 +419,7 @@ void avl_init(avl_tree* t, int (*compar)(void* a, void* b)) {
 
        if(lock != 0)
                fatal("Failed to initialize AVL mutex/rwlock, error: %d", lock);
+
+#endif /* AVL_WITHOUT_PTHREADS */
+
 }