forked from vieter-v/libvieter
feat(tree): add rwlock
parent
83b3198a49
commit
1c563d8421
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue