Implemented a read-write lock using only mutex_t and condvar_t (in case the pthread_rwlock_* group of functions is not available).

This commit is contained in:
Tobias Brunner
2009-12-23 17:01:30 +01:00
parent b1f35d0695
commit f36143b0ba
3 changed files with 188 additions and 1 deletions
+36
View File
@@ -31,11 +31,47 @@ struct private_rwlock_t {
*/
rwlock_t public;
#ifdef HAVE_PTHREAD_RWLOCK_INIT
/**
* wrapped pthread rwlock
*/
pthread_rwlock_t rwlock;
#else
/**
* mutex to emulate a native rwlock
*/
mutex_t *mutex;
/**
* condvar to handle writers
*/
condvar_t *writers;
/**
* condvar to handle readers
*/
condvar_t *readers;
/**
* number of waiting writers
*/
u_int waiting_writers;
/**
* number of readers holding the lock
*/
u_int reader_count;
/**
* current writer thread, if any
*/
pthread_t writer;
#endif /* HAVE_PTHREAD_RWLOCK_INIT */
/**
* profiling info, if enabled
*/