changeset 599:9547830b7a05

synch: pass function call context into rw lock functions Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Fri, 19 Oct 2018 12:46:42 -0400
parents 8ac6182dac33
children 76aef7949faf
files include/jeffpc/synch.h synch.c
diffstat 2 files changed, 42 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/include/jeffpc/synch.h	Fri Oct 19 13:07:36 2018 -0400
+++ b/include/jeffpc/synch.h	Fri Oct 19 12:46:42 2018 -0400
@@ -41,9 +41,9 @@
 
 struct lock_context {
 	union {
-		/* mutex */
+		/* mutex/rwlock */
 		struct {
-			const char *lockname; /* mutex */
+			const char *lockname; /* mutex or rwlock */
 		};
 	};
 	const char *file;
@@ -104,10 +104,38 @@
 				}; \
 				mxunlock(&mx_ctx, (l)); \
 			} while (0)
-#define RWINIT(l)	rwinit(l)
-#define RWDESTROY(l)	rwdestroy(l)
-#define RWLOCK(l, wr)	rwlock((l), (wr))
-#define RWUNLOCK(l)	rwunlock(l)
+#define RWINIT(l)	do { \
+				struct lock_context rw_ctx = { \
+					.lockname = #l, \
+					.file = __FILE__, \
+					.line = __LINE__, \
+				}; \
+				rwinit(&rw_ctx, (l)); \
+			} while (0)
+#define RWDESTROY(l)	do { \
+				struct lock_context rw_ctx = { \
+					.lockname = #l, \
+					.file = __FILE__, \
+					.line = __LINE__, \
+				}; \
+				rwdestroy(&rw_ctx, (l)); \
+			} while (0)
+#define RWLOCK(l, wr)	do { \
+				struct lock_context rw_ctx = { \
+					.lockname = #l, \
+					.file = __FILE__, \
+					.line = __LINE__, \
+				}; \
+				rwlock(&rw_ctx, (l), (wr)); \
+			} while (0)
+#define RWUNLOCK(l)	do { \
+				struct lock_context rw_ctx = { \
+					.lockname = #l, \
+					.file = __FILE__, \
+					.line = __LINE__, \
+				}; \
+				rwunlock(&rw_ctx, (l)); \
+			} while (0)
 #define CONDINIT(c)	condinit(c)
 #define CONDDESTROY(c)	conddestroy(c)
 #define CONDWAIT(c,m)	condwait((c),(m))
@@ -128,10 +156,10 @@
 extern void mxlock(const struct lock_context *where, struct lock *m);
 extern void mxunlock(const struct lock_context *where, struct lock *m);
 
-extern void rwinit(struct rwlock *l);
-extern void rwdestroy(struct rwlock *l);
-extern void rwlock(struct rwlock *l, bool wr);
-extern void rwunlock(struct rwlock *l);
+extern void rwinit(const struct lock_context *where, struct rwlock *l);
+extern void rwdestroy(const struct lock_context *where, struct rwlock *l);
+extern void rwlock(const struct lock_context *where, struct rwlock *l, bool wr);
+extern void rwunlock(const struct lock_context *where, struct rwlock *l);
 
 extern void condinit(struct cond *c);
 extern void conddestroy(struct cond *c);
--- a/synch.c	Fri Oct 19 13:07:36 2018 -0400
+++ b/synch.c	Fri Oct 19 12:46:42 2018 -0400
@@ -464,17 +464,17 @@
 	VERIFY0(pthread_mutex_unlock(&l->lock));
 }
 
-void rwinit(struct rwlock *l)
+void rwinit(const struct lock_context *where, struct rwlock *l)
 {
 	VERIFY0(pthread_rwlock_init(&l->lock, NULL));
 }
 
-void rwdestroy(struct rwlock *l)
+void rwdestroy(const struct lock_context *where, struct rwlock *l)
 {
 	VERIFY0(pthread_rwlock_destroy(&l->lock));
 }
 
-void rwlock(struct rwlock *l, bool wr)
+void rwlock(const struct lock_context *where, struct rwlock *l, bool wr)
 {
 	if (wr)
 		VERIFY0(pthread_rwlock_wrlock(&l->lock));
@@ -482,7 +482,7 @@
 		VERIFY0(pthread_rwlock_rdlock(&l->lock));
 }
 
-void rwunlock(struct rwlock *l)
+void rwunlock(const struct lock_context *where, struct rwlock *l)
 {
 	VERIFY0(pthread_rwlock_unlock(&l->lock));
 }