Compare commits

..

9 Commits

4 changed files with 32 additions and 6 deletions

View File

@ -67,15 +67,9 @@ $(TARGETS_TEST): test-%: %
$(TARGETS_MEM_TEST): test-mem-%: %
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes --leak-check=full ./$^
test-mem: build-test
@ $(foreach bin,$(BINS_TEST),valgrind --tool=memcheck --error-exitcode=1 \
--track-origins=yes --leak-check=full ./$(bin);)
.PHONY: build-test
build-test: $(BINS_TEST)
# For simplicity, we link every object file to each of the test files. This
# might be changed later if this starts to become too slow.
$(BINS_TEST): %: %.c.o $(LIB)
$(CC) \
$^ -o $@

View File

@ -67,4 +67,22 @@ void vieter_tree_iterator_free(vieter_tree_iterator **ptp);
vieter_tree_error vieter_tree_iterator_next(void **out,
vieter_tree_iterator *iter);
/*
* Acquire a read lock on the tree. Return value is the result of
* pthread_rwlock_rdlock.
*/
int vieter_tree_rlock(vieter_tree *tree);
/*
* Acquire a write lock on the tree. Return value is the result of
* pthread_rwlock_wrlock.
*/
int vieter_tree_wlock(vieter_tree *tree);
/*
* Unlock the lock after having acquired it. Return value is the result of
* pthread_rwlock_unlock.
*/
int vieter_tree_unlock(vieter_tree *tree);
#endif

View File

@ -114,3 +114,15 @@ bool vieter_tree_validate(vieter_tree *tree) {
return vieter_tree_node_get(tree->root, vieter_tree_node_black) &&
vieter_tree_node_validate(tree->root, 0, expected_black_nodes);
}
int vieter_tree_rlock(vieter_tree *tree) {
return pthread_rwlock_rdlock(&tree->lock);
}
int vieter_tree_wlock(vieter_tree *tree) {
return pthread_rwlock_wrlock(&tree->lock);
}
int vieter_tree_unlock(vieter_tree *tree) {
return pthread_rwlock_unlock(&tree->lock);
}

View File

@ -1,11 +1,13 @@
#include "vieter_tree.h"
#include "vieter_tree_node.h"
#include <pthread.h>
#include <stdbool.h>
struct vieter_tree {
uint64_t size;
vieter_tree_node *root;
pthread_rwlock_t lock;
};
/*