diff options
Diffstat (limited to '')
-rw-r--r--[-rwxr-xr-x] | src/avl.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/avl.c b/src/avl.c index 4eb0ce0e..fd4fb142 100755..100644 --- a/src/avl.c +++ b/src/avl.c @@ -17,6 +17,7 @@ #include <config.h> #endif #include "avl.h" +#include "log.h" /* Private methods */ int _avl_removeroot(avl_tree* t); @@ -144,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; } @@ -242,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; } @@ -298,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; } @@ -362,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; } @@ -390,9 +407,19 @@ int avl_search(avl_tree* t, avl* a, int (*iter)(avl* a), avl** ret) { 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 - pthread_mutex_init(&t->mutex, NULL); + lock = pthread_mutex_init(&t->mutex, NULL); #else - pthread_rwlock_init(&t->rwlock, NULL); + lock = pthread_rwlock_init(&t->rwlock, NULL); #endif + + if(lock != 0) + fatal("Failed to initialize AVL mutex/rwlock, error: %d", lock); + +#endif /* AVL_WITHOUT_PTHREADS */ + } |