summaryrefslogtreecommitdiff
path: root/src/libstrongswan/utils/mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/utils/mutex.h')
-rw-r--r--src/libstrongswan/utils/mutex.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/mutex.h b/src/libstrongswan/utils/mutex.h
index cf557c35c..a0a198024 100644
--- a/src/libstrongswan/utils/mutex.h
+++ b/src/libstrongswan/utils/mutex.h
@@ -23,8 +23,10 @@
typedef struct mutex_t mutex_t;
typedef struct condvar_t condvar_t;
+typedef struct rwlock_t rwlock_t;
typedef enum mutex_type_t mutex_type_t;
typedef enum condvar_type_t condvar_type_t;
+typedef enum rwlock_type_t rwlock_type_t;
#include <library.h>
@@ -47,6 +49,14 @@ enum condvar_type_t {
};
/**
+ * Type of read-write lock.
+ */
+enum rwlock_type_t {
+ /** default condvar */
+ RWLOCK_DEFAULT = 0,
+};
+
+/**
* Mutex wrapper implements simple, portable and advanced mutex functions.
*/
struct mutex_t {
@@ -105,6 +115,41 @@ struct condvar_t {
};
/**
+ * Read-Write lock wrapper.
+ */
+struct rwlock_t {
+
+ /**
+ * Acquire the read lock.
+ */
+ void (*read_lock)(rwlock_t *this);
+
+ /**
+ * Acquire the write lock.
+ */
+ void (*write_lock)(rwlock_t *this);
+
+ /**
+ * Try to acquire the write lock.
+ *
+ * Never blocks, but returns FALSE if the lock was already occupied.
+ *
+ * @return TRUE if lock acquired
+ */
+ bool (*try_write_lock)(rwlock_t *this);
+
+ /**
+ * Release any acquired lock.
+ */
+ void (*unlock)(rwlock_t *this);
+
+ /**
+ * Destroy the read-write lock.
+ */
+ void (*destroy)(rwlock_t *this);
+};
+
+/**
* Create a mutex instance.
*
* @param type type of mutex to create
@@ -120,4 +165,12 @@ mutex_t *mutex_create(mutex_type_t type);
*/
condvar_t *condvar_create(condvar_type_t type);
+/**
+ * Create a read-write lock instance.
+ *
+ * @param type type of rwlock to create
+ * @return unlocked rwlock instance
+ */
+rwlock_t *rwlock_create(rwlock_type_t type);
+
#endif /* MUTEX_H_ @}*/