19 #undef RBT_NODE_ROOT_T
20 #define RBT_NODE_ROOT_T RBT_TOKEN_2_W(RBT_NODE_H_PREFIX_, node_root_t)
80 root.
mutex = PTHREAD_MUTEX_INITIALIZER;
81 root.
cond = PTHREAD_COND_INITIALIZER;
112 #undef RBT_NODE_ROOT_READ
113 #define RBT_NODE_ROOT_READ(root, func, ...) \
114 pthread_mutex_lock(&(root.mutex)); \
115 while (root.writers) \
117 pthread_cond_wait(&(root.cond), &(root.mutex)); \
120 pthread_mutex_unlock(&(root.mutex)); \
121 func(root.node, ##__VA_ARGS__); \
122 pthread_mutex_lock(&(root.mutex)); \
124 if (! root.readers) \
126 pthread_cond_signal(&(root.cond)); \
128 pthread_mutex_unlock(&(root.mutex))
156 #undef RBT_NODE_ROOT_WRITE
157 #define RBT_NODE_ROOT_WRITE(root, func, ...) \
158 pthread_mutex_lock(&(root.mutex)); \
160 while (root.readers) \
162 pthread_cond_wait(&(root.cond), &(root.mutex)); \
164 func(root.node, ##__VA_ARGS__); \
166 pthread_cond_signal(&(root.cond)); \
167 pthread_mutex_unlock(&(root.mutex))
171 #ifdef RBT_NODE_CACHE_SIZE
175 #undef RBT_NODE_CACHE_MUTEX
176 #define RBT_NODE_CACHE_MUTEX RBT_TOKEN_2_W(RBT_NODE_H_PREFIX_, node_cache_mutex)
184 pthread_mutex_t RBT_NODE_CACHE_MUTEX = PTHREAD_MUTEX_INITIALIZER;
189 #undef RBT_NODE_CACHE_LOCK
190 #define RBT_NODE_CACHE_LOCK pthread_mutex_lock(&RBT_NODE_CACHE_MUTEX)
195 #undef RBT_NODE_CACHE_UNLOCK
196 #define RBT_NODE_CACHE_UNLOCK pthread_mutex_unlock(&RBT_NODE_CACHE_MUTEX)
198 #endif //RBT_NODE_CACHE_SIZE
RBT_NODE_ROOT_T RBT_NODE_NEW()
Create a new root node.
Definition: node_pthread.h:76
Definition: node_pthread.h:28
RBT_NODE_T * node
The root node.
Definition: node_pthread.h:35
unsigned int readers
The number of concurrent read operations.
Definition: node_pthread.h:41
unsigned int writers
The number of queued write operations.
Definition: node_pthread.h:47
pthread_mutex_t mutex
The mutex that protects this root node.
Definition: node_pthread.h:53
RBT_NODE_T * RBT_NODE_CREATE(RBT_PIN_T *key, RBT_KEY_SIZE_T bits, RBT_VALUE_T value, RBT_NODE_T *left, RBT_NODE_T *right)
Create a node.
Definition: node.h:1082
Rabbit Tree node type.
Definition: node.h:418
struct RBT_NODE_ROOT_T RBT_NODE_ROOT_T
pthread_cond_t cond
The condition variable used to signal waiting threads.
Definition: node_pthread.h:59