From b477515867e7e65944261e4034d7952fec5ab513 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Thu, 12 Oct 2017 09:19:46 +0000 Subject: 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@ --- sys/kern/kern_rwlock.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sys/kern') 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 @@ -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); } -- cgit v1.2.3