changeset 65:a37c1adce732

common: add wrappers around pthread rwlocks Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Tue, 07 Jul 2015 21:41:30 -0400
parents 2433660749c6
children 568b4fd9ef61
files src/common/include/nomad/mutex.h src/common/mutex.c
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/common/include/nomad/mutex.h	Tue Jul 07 21:40:21 2015 -0400
+++ b/src/common/include/nomad/mutex.h	Tue Jul 07 21:41:30 2015 -0400
@@ -23,6 +23,7 @@
 #ifndef __NOMAD_MUTEX_H
 #define __NOMAD_MUTEX_H
 
+#include <stdbool.h>
 #include <pthread.h>
 
 extern void mxinit(pthread_mutex_t *m);
@@ -30,6 +31,11 @@
 extern void mxlock(pthread_mutex_t *m);
 extern void mxunlock(pthread_mutex_t *m);
 
+extern void rwinit(pthread_rwlock_t *l);
+extern void rwdestroy(pthread_rwlock_t *l);
+extern void rwlock(pthread_rwlock_t *l, bool wr);
+extern void rwunlock(pthread_rwlock_t *l);
+
 extern void condinit(pthread_cond_t *c);
 extern void conddestroy(pthread_cond_t *c);
 extern void condwait(pthread_cond_t *c, pthread_mutex_t *m);
--- a/src/common/mutex.c	Tue Jul 07 21:40:21 2015 -0400
+++ b/src/common/mutex.c	Tue Jul 07 21:41:30 2015 -0400
@@ -46,6 +46,29 @@
 	VERIFY0(pthread_mutex_unlock(m));
 }
 
+void rwinit(pthread_rwlock_t *l)
+{
+	VERIFY0(pthread_rwlock_init(l, NULL));
+}
+
+void rwdestroy(pthread_rwlock_t *l)
+{
+	VERIFY0(pthread_rwlock_destroy(l));
+}
+
+void rwlock(pthread_rwlock_t *l, bool wr)
+{
+	if (wr)
+		VERIFY0(pthread_rwlock_wrlock(l));
+	else
+		VERIFY0(pthread_rwlock_rdlock(l));
+}
+
+void rwunlock(pthread_rwlock_t *l)
+{
+	VERIFY0(pthread_rwlock_unlock(l));
+}
+
 void condinit(pthread_cond_t *c)
 {
 	VERIFY0(pthread_cond_init(c, NULL));