aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/threading/rwlock.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2009-12-08 16:53:01 +0100
committerTobias Brunner <tobias@strongswan.org>2009-12-23 17:01:53 +0100
commiteba64cef41f6db11ca751a0f207d0bba052b4093 (patch)
treed0b1098f4c7eba59c86f527660fcc229177dde1d /src/libstrongswan/threading/rwlock.c
parentf36143b0baa9ecfa7930780c53a73e74c91577db (diff)
downloadstrongswan-eba64cef41f6db11ca751a0f207d0bba052b4093.tar.bz2
strongswan-eba64cef41f6db11ca751a0f207d0bba052b4093.tar.xz
Separated the public interfaces of the threading primitives.
Diffstat (limited to 'src/libstrongswan/threading/rwlock.c')
-rw-r--r--src/libstrongswan/threading/rwlock.c63
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
/**