diff options
Diffstat (limited to 'src/libstrongswan/threading/rwlock.c')
-rw-r--r-- | src/libstrongswan/threading/rwlock.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/libstrongswan/threading/rwlock.c b/src/libstrongswan/threading/rwlock.c index bf59f50f1..ee9fb10be 100644 --- a/src/libstrongswan/threading/rwlock.c +++ b/src/libstrongswan/threading/rwlock.c @@ -17,13 +17,74 @@ #define _GNU_SOURCE #include <pthread.h> -#include <threading.h> #include <library.h> #include <debug.h> #include "rwlock.h" +#include "condvar.h" +#include "mutex.h" #include "lock_profiler.h" +typedef struct private_rwlock_t private_rwlock_t; + +/** + * private data of rwlock + */ +struct private_rwlock_t { + + /** + * public functions + */ + 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 + */ + lock_profile_t profile; +}; + + #ifdef HAVE_PTHREAD_RWLOCK_INIT /** |