summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-10-12 09:19:46 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-10-12 09:19:46 +0000
commitb477515867e7e65944261e4034d7952fec5ab513 (patch)
tree223548cd2fbb5b2d401ec17b54227932f665a9c3 /sys/kern
parented871f5e0c4abb0cd4cc968ba206117a33ff83e2 (diff)
Use a temporary variable in rw_status() to dereference only once the
volatile member of the struct. Not forcing a memory read on every access, 3 in this function, might reduce cache traffic in some cases. Micro-optimization and diff provided by Mateusz Guzik. ok visa@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_rwlock.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index e2c3caed0ab..9252413b1b3 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_rwlock.c,v 1.30 2017/08/12 23:27:44 guenther Exp $ */
+/* $OpenBSD: kern_rwlock.c,v 1.31 2017/10/12 09:19:45 mpi Exp $ */
/*
* Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org>
@@ -312,13 +312,15 @@ _rw_exit(struct rwlock *rwl LOCK_FL_VARS)
int
rw_status(struct rwlock *rwl)
{
- if (rwl->rwl_owner & RWLOCK_WRLOCK) {
- if (RW_PROC(curproc) == RW_PROC(rwl->rwl_owner))
+ unsigned long owner = rwl->rwl_owner;
+
+ if (owner & RWLOCK_WRLOCK) {
+ if (RW_PROC(curproc) == RW_PROC(owner))
return RW_WRITE;
else
return RW_WRITE_OTHER;
}
- if (rwl->rwl_owner)
+ if (owner)
return RW_READ;
return (0);
}