diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2014-07-09 13:32:01 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2014-07-09 13:32:01 +0000 |
commit | 61e233e8b12ea608fee9fb782af219307334dfa5 (patch) | |
tree | 6021d6aac7ec30cb28b787c40fd40971cbc342d9 | |
parent | db16be9113fcacedacce719c862e50f0f8916157 (diff) |
Teach rw_status() and rrw_status() to return LK_EXCLOTHER if it's write
locked by a different thread. Teach lockstatus() to return LK_EXCLUSIVE
if an exclusive lock is held by some other thread.
ok beck@ tedu@
-rw-r--r-- | sys/kern/kern_lock.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_rwlock.c | 10 | ||||
-rw-r--r-- | sys/sys/lock.h | 5 | ||||
-rw-r--r-- | sys/sys/rwlock.h | 8 |
4 files changed, 21 insertions, 6 deletions
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index cef4c7c7664..946fd17e3b3 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_lock.c,v 1.43 2014/01/21 01:48:44 tedu Exp $ */ +/* $OpenBSD: kern_lock.c,v 1.44 2014/07/09 13:32:00 guenther Exp $ */ /* * Copyright (c) 1995 @@ -64,6 +64,8 @@ lockstatus(struct lock *lkp) switch (rrw_status(&lkp->lk_lck)) { case RW_WRITE: return (LK_EXCLUSIVE); + case RW_WRITE_OTHER: + return (LK_EXCLOTHER); case RW_READ: return (LK_SHARED); case 0: diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index a472b616400..e1def9e874d 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_rwlock.c,v 1.21 2014/01/21 01:48:44 tedu Exp $ */ +/* $OpenBSD: kern_rwlock.c,v 1.22 2014/07/09 13:32:00 guenther Exp $ */ /* * Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org> @@ -256,8 +256,12 @@ rw_exit(struct rwlock *rwl) int rw_status(struct rwlock *rwl) { - if (rwl->rwl_owner & RWLOCK_WRLOCK) - return RW_WRITE; + if (rwl->rwl_owner & RWLOCK_WRLOCK) { + if (RW_PROC(curproc) == RW_PROC(rwl->rwl_owner)) + return RW_WRITE; + else + return RW_WRITE_OTHER; + } if (rwl->rwl_owner) return RW_READ; return (0); diff --git a/sys/sys/lock.h b/sys/sys/lock.h index 0bbbdbceffe..558fd9192e5 100644 --- a/sys/sys/lock.h +++ b/sys/sys/lock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lock.h,v 1.22 2013/05/01 17:13:05 tedu Exp $ */ +/* $OpenBSD: lock.h,v 1.23 2014/07/09 13:32:00 guenther Exp $ */ /* * Copyright (c) 1995 @@ -72,6 +72,9 @@ struct lock { #define LK_RECURSEFAIL 0x40 /* fail if recursive exclusive lock */ #define LK_RETRY 0x80 /* vn_lock: retry until locked */ +/* for lockstatus() only */ +#define LK_EXCLOTHER 0x100 /* exclusive lock held by some other thread */ + void lockinit(struct lock *, int, char *, int, int); int lockmgr(struct lock *, u_int flags, void *); int lockstatus(struct lock *); diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h index 0fa11f6780f..9103a914410 100644 --- a/sys/sys/rwlock.h +++ b/sys/sys/rwlock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rwlock.h,v 1.15 2014/03/29 18:09:31 guenther Exp $ */ +/* $OpenBSD: rwlock.h,v 1.16 2014/07/09 13:32:00 guenther Exp $ */ /* * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> * @@ -109,6 +109,12 @@ int rw_status(struct rwlock *); #define RW_NOSLEEP 0x0040UL /* don't wait for the lock */ #define RW_RECURSEFAIL 0x0080UL /* Fail on recursion for RRW locks. */ +/* + * for rw_status() and rrw_status() only: exclusive lock held by + * some other thread + */ +#define RW_WRITE_OTHER 0x0100UL + #ifndef rw_cas int rw_cas(volatile unsigned long *, unsigned long, unsigned long); #endif |