# HG changeset patch # User Josef 'Jeff' Sipek # Date 1565539550 14400 # Node ID 12a0b515e84e8e0a19e95fdb25311a3be929f609 # Parent 5afe57ee2deae5ac02e56b1b383d6af43c875caa synch: rwlocks should belong to a lock class This will allow us to track dependencies between mutexes and rwlocks. Signed-off-by: Josef 'Jeff' Sipek diff -r 5afe57ee2dea -r 12a0b515e84e include/jeffpc/synch.h --- a/include/jeffpc/synch.h Sun Aug 11 13:13:57 2019 -0400 +++ b/include/jeffpc/synch.h Sun Aug 11 12:05:50 2019 -0400 @@ -114,13 +114,13 @@ }; \ mxunlock(&mx_ctx, (l)); \ } while (0) -#define RWINIT(l) do { \ +#define RWINIT(l, lc) do { \ struct lock_context rw_ctx = { \ .lockname = #l, \ .file = __FILE__, \ .line = __LINE__, \ }; \ - rwinit(&rw_ctx, (l)); \ + rwinit(&rw_ctx, (l), (lc)); \ } while (0) #define RWDESTROY(l) do { \ struct lock_context rw_ctx = { \ @@ -247,7 +247,8 @@ 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(const struct lock_context *where, struct rwlock *l); +extern void rwinit(const struct lock_context *where, struct rwlock *l, + struct lock_class *lc); 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); diff -r 5afe57ee2dea -r 12a0b515e84e synch.c --- a/synch.c Sun Aug 11 13:13:57 2019 -0400 +++ b/synch.c Sun Aug 11 12:05:50 2019 -0400 @@ -588,13 +588,19 @@ check_held_for_unlock(&l->info, where); } -static void verify_rw_init(const struct lock_context *where, struct rwlock *l) +static void verify_rw_init(const struct lock_context *where, struct rwlock *l, + struct lock_class *lc) { - if (!l) + if (!l || !lc) print_invalid_call("RWINIT", where); l->info.magic = (uintptr_t) &l->info; l->info.type = SYNCH_TYPE_RW; + +#ifdef JEFFPC_LOCK_TRACKING + l->info.lc = lc; + l->info.name = where->lockname; +#endif } static void verify_rw_destroy(const struct lock_context *where, struct rwlock *l) @@ -776,11 +782,12 @@ where->file, where->line, strerror(ret)); } -void rwinit(const struct lock_context *where, struct rwlock *l) +void rwinit(const struct lock_context *where, struct rwlock *l, + struct lock_class *lc) { int ret; - verify_rw_init(where, l); + verify_rw_init(where, l, lc); ret = pthread_rwlock_init(&l->lock, NULL); if (ret)