Mercurial > libjeffpc
changeset 755:607f480900f2
synch: move magic into a common synchronization primitive struct
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 25 Jul 2019 10:59:16 -0400 |
parents | 389216c34b53 |
children | 81a940d03dcd |
files | include/jeffpc/synch.h synch.c |
diffstat | 2 files changed, 19 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/include/jeffpc/synch.h Thu Jul 25 10:55:43 2019 -0400 +++ b/include/jeffpc/synch.h Thu Jul 25 10:59:16 2019 -0400 @@ -53,9 +53,13 @@ int line; }; +struct lock_info { + uintptr_t magic; +}; + struct lock { + struct lock_info info; pthread_mutex_t lock; - uintptr_t magic; #ifdef JEFFPC_LOCK_TRACKING struct lock_class *lc; const char *name; @@ -63,13 +67,13 @@ }; struct rwlock { + struct lock_info info; pthread_rwlock_t lock; - uintptr_t magic; }; struct cond { + struct lock_info info; pthread_cond_t cond; - uintptr_t magic; }; struct barrier {
--- a/synch.c Thu Jul 25 10:55:43 2019 -0400 +++ b/synch.c Thu Jul 25 10:59:16 2019 -0400 @@ -104,11 +104,11 @@ } #define GENERATE_LOCK_MASK_ARGS(l) \ - ((l)->magic != (uintptr_t) (l)) ? 'M' : '.' + ((l)->info.magic != (uintptr_t) (l)) ? 'M' : '.' #define GENERATE_RW_MASK_ARGS(l) \ - ((l)->magic != (uintptr_t) (l)) ? 'M' : '.' + ((l)->info.magic != (uintptr_t) (l)) ? 'M' : '.' #define GENERATE_COND_MASK_ARGS(c) \ - ((c)->magic != (uintptr_t) (c)) ? 'M' : '.' + ((c)->info.magic != (uintptr_t) (c)) ? 'M' : '.' static void print_lock(struct lock *lock, const struct lock_context *where) { @@ -387,7 +387,7 @@ static void check_lock_magic(struct lock *lock, const char *op, const struct lock_context *where) { - if (lock->magic == (uintptr_t) lock) + if (lock->info.magic == (uintptr_t) lock) return; cmn_err(CE_CRIT, "lockdep: thread trying to %s lock with bad magic", op); @@ -402,7 +402,7 @@ static void check_rw_magic(struct rwlock *lock, const char *op, const struct lock_context *where) { - if (lock->magic == (uintptr_t) lock) + if (lock->info.magic == (uintptr_t) lock) return; cmn_err(CE_CRIT, "lockdep: thread trying to %s rwlock with bad magic", op); @@ -413,7 +413,7 @@ static void check_cond_magic(struct cond *cond, const char *op, const struct lock_context *where) { - if (cond->magic == (uintptr_t) cond) + if (cond->info.magic == (uintptr_t) cond) return; cmn_err(CE_CRIT, "lockdep: thread trying to %s cond with bad magic", op); @@ -427,7 +427,7 @@ if (!l || !lc) print_invalid_call("MXINIT", where); - l->magic = (uintptr_t) l; + l->info.magic = (uintptr_t) l; #ifdef JEFFPC_LOCK_TRACKING l->lc = lc; @@ -455,7 +455,7 @@ } #endif - l->magic = DESTROYED_MAGIC; + l->info.magic = DESTROYED_MAGIC; } static void verify_lock_lock(const struct lock_context *where, struct lock *l) @@ -531,7 +531,7 @@ if (!l) print_invalid_call("RWINIT", where); - l->magic = (uintptr_t) l; + l->info.magic = (uintptr_t) l; } static void verify_rw_destroy(const struct lock_context *where, struct rwlock *l) @@ -541,7 +541,7 @@ check_rw_magic(l, "destroy", where); - l->magic = DESTROYED_MAGIC; + l->info.magic = DESTROYED_MAGIC; } static void verify_rw_lock(const struct lock_context *where, struct rwlock *l, @@ -566,7 +566,7 @@ if (!c) print_invalid_call("CONDINIT", where); - c->magic = (uintptr_t) c; + c->info.magic = (uintptr_t) c; } static void verify_cond_destroy(const struct lock_context *where, struct cond *c) @@ -576,7 +576,7 @@ check_cond_magic(c, "destroy", where); - c->magic = DESTROYED_MAGIC; + c->info.magic = DESTROYED_MAGIC; } static void verify_cond_wait(const struct lock_context *where, struct cond *c,