}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
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
if(lock != 0)
fatal("Failed to initialize AVL mutex/rwlock, error: %d", lock);
+
+#endif /* AVL_WITHOUT_PTHREADS */
+
}