diff options
author | Bret Lambert <blambert@cvs.openbsd.org> | 2009-08-13 21:22:30 +0000 |
---|---|---|
committer | Bret Lambert <blambert@cvs.openbsd.org> | 2009-08-13 21:22:30 +0000 |
commit | b83e46553695c561da1d069078e51075a395a217 (patch) | |
tree | 055d930216eded886444ad1556d9d584ee21425f /sys | |
parent | fe6f88cb9b76466c202050fac0fe412f7c883bd5 (diff) |
rwlock assertion functions, currently unused
ok art@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_rwlock.c | 33 | ||||
-rw-r--r-- | sys/sys/rwlock.h | 6 |
2 files changed, 37 insertions, 2 deletions
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 0df33c9008b..9802a8323b5 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_rwlock.c,v 1.13 2007/05/13 04:52:32 tedu Exp $ */ +/* $OpenBSD: kern_rwlock.c,v 1.14 2009/08/13 21:22:29 blambert Exp $ */ /* * Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org> @@ -197,6 +197,13 @@ retry: rw_enter_diag(rwl, flags); + if (((struct proc *)RW_PROC(rwl))->p_stat == SONPROC) { +printf("%p\n", (struct proc *)RW_PROC(rwl)); + while(((struct proc *)RW_PROC(rwl))->p_stat == SONPROC) + SPINLOCK_SPIN_HOOK; + goto retry; + } + if (flags & RW_NOSLEEP) return (EBUSY); @@ -248,3 +255,27 @@ rw_exit(struct rwlock *rwl) if (owner & RWLOCK_WAIT) wakeup(rwl); } + +void +rw_assert_wrlock(struct rwlock *rwl) +{ + if (!(rwl->rwl_owner & RWLOCK_WRLOCK)) + panic("%s: lock not held", rwl->rwl_name); + + if (RWLOCK_OWNER(rwl) != (struct proc *)((long)curproc & ~RWLOCK_MASK)) + panic("%s: lock not held by this process", rwl->rwl_name); +} + +void +rw_assert_rdlock(struct rwlock *rwl) +{ + if (!RWLOCK_OWNER(rwl) || (rwl->rwl_owner & RWLOCK_WRLOCK)) + panic("%s: lock not shared", rwl->rwl_name); +} + +void +rw_assert_unlocked(struct rwlock *rwl) +{ + if (rwl->rwl_owner != 0L) + panic("%s: lock held", rwl->rwl_name); +} diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h index cc227c9c2c4..ebab5875fe8 100644 --- a/sys/sys/rwlock.h +++ b/sys/sys/rwlock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rwlock.h,v 1.11 2007/05/29 00:17:32 thib Exp $ */ +/* $OpenBSD: rwlock.h,v 1.12 2009/08/13 21:22:29 blambert Exp $ */ /* * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> * All rights reserved. @@ -95,6 +95,10 @@ void rw_enter_write(struct rwlock *); void rw_exit_read(struct rwlock *); void rw_exit_write(struct rwlock *); +void rw_assert_wrlock(struct rwlock *); +void rw_assert_rdlock(struct rwlock *); +void rw_assert_unlocked(struct rwlock *); + int rw_enter(struct rwlock *, int); void rw_exit(struct rwlock *); #define RW_WRITE 0x00UL /* exclusive lock */ |