Mercurial > libjeffpc
changeset 780:12a0b515e84e
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 <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sun, 11 Aug 2019 12:05:50 -0400 |
parents | 5afe57ee2dea |
children | bc8880710efd |
files | include/jeffpc/synch.h synch.c |
diffstat | 2 files changed, 15 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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)