Mon Dec 5 07:09:04 2022 UTC ()
Simplify. Same code before and after.


(skrll)
diff -r1.100 -r1.101 src/sys/kern/kern_mutex.c

cvs diff -r1.100 -r1.101 src/sys/kern/kern_mutex.c (expand / switch to unified diff)

--- src/sys/kern/kern_mutex.c 2022/10/26 23:21:19 1.100
+++ src/sys/kern/kern_mutex.c 2022/12/05 07:09:04 1.101
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_mutex.c,v 1.100 2022/10/26 23:21:19 riastradh Exp $ */ 1/* $NetBSD: kern_mutex.c,v 1.101 2022/12/05 07:09:04 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe and Andrew Doran. 8 * by Jason R. Thorpe and Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 */ 30 */
31 31
32/* 32/*
33 * Kernel mutex implementation, modeled after those found in Solaris, 33 * Kernel mutex implementation, modeled after those found in Solaris,
34 * a description of which can be found in: 34 * a description of which can be found in:
35 * 35 *
36 * Solaris Internals: Core Kernel Architecture, Jim Mauro and 36 * Solaris Internals: Core Kernel Architecture, Jim Mauro and
37 * Richard McDougall. 37 * Richard McDougall.
38 */ 38 */
39 39
40#define __MUTEX_PRIVATE 40#define __MUTEX_PRIVATE
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.100 2022/10/26 23:21:19 riastradh Exp $"); 43__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.101 2022/12/05 07:09:04 skrll Exp $");
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/atomic.h> 46#include <sys/atomic.h>
47#include <sys/proc.h> 47#include <sys/proc.h>
48#include <sys/mutex.h> 48#include <sys/mutex.h>
49#include <sys/sched.h> 49#include <sys/sched.h>
50#include <sys/sleepq.h> 50#include <sys/sleepq.h>
51#include <sys/systm.h> 51#include <sys/systm.h>
52#include <sys/lockdebug.h> 52#include <sys/lockdebug.h>
53#include <sys/kernel.h> 53#include <sys/kernel.h>
54#include <sys/intr.h> 54#include <sys/intr.h>
55#include <sys/lock.h> 55#include <sys/lock.h>
56#include <sys/types.h> 56#include <sys/types.h>
@@ -135,40 +135,38 @@ do { \ @@ -135,40 +135,38 @@ do { \
135#endif 135#endif
136 136
137#ifndef MUTEX_INITIALIZE_SPIN_IPL 137#ifndef MUTEX_INITIALIZE_SPIN_IPL
138#define MUTEX_INITIALIZE_SPIN_IPL(mtx, ipl) \ 138#define MUTEX_INITIALIZE_SPIN_IPL(mtx, ipl) \
139 ((mtx)->mtx_ipl = makeiplcookie((ipl))) 139 ((mtx)->mtx_ipl = makeiplcookie((ipl)))
140#endif 140#endif
141 141
142/* 142/*
143 * Spin mutex SPL save / restore. 143 * Spin mutex SPL save / restore.
144 */ 144 */
145 145
146#define MUTEX_SPIN_SPLRAISE(mtx) \ 146#define MUTEX_SPIN_SPLRAISE(mtx) \
147do { \ 147do { \
148 struct cpu_info *x__ci; \ 148 const int s = splraiseipl(MUTEX_SPIN_IPL(mtx)); \
149 int x__cnt, s; \ 149 struct cpu_info * const x__ci = curcpu(); \
150 s = splraiseipl(MUTEX_SPIN_IPL(mtx)); \ 150 const int x__cnt = x__ci->ci_mtx_count--; \
151 x__ci = curcpu(); \ 
152 x__cnt = x__ci->ci_mtx_count--; \ 
153 __insn_barrier(); \ 151 __insn_barrier(); \
154 if (x__cnt == 0) \ 152 if (x__cnt == 0) \
155 x__ci->ci_mtx_oldspl = (s); \ 153 x__ci->ci_mtx_oldspl = s; \
156} while (/* CONSTCOND */ 0) 154} while (/* CONSTCOND */ 0)
157 155
158#define MUTEX_SPIN_SPLRESTORE(mtx) \ 156#define MUTEX_SPIN_SPLRESTORE(mtx) \
159do { \ 157do { \
160 struct cpu_info *x__ci = curcpu(); \ 158 struct cpu_info * const x__ci = curcpu(); \
161 int s = x__ci->ci_mtx_oldspl; \ 159 const int s = x__ci->ci_mtx_oldspl; \
162 __insn_barrier(); \ 160 __insn_barrier(); \
163 if (++(x__ci->ci_mtx_count) == 0) \ 161 if (++(x__ci->ci_mtx_count) == 0) \
164 splx(s); \ 162 splx(s); \
165} while (/* CONSTCOND */ 0) 163} while (/* CONSTCOND */ 0)
166 164
167/* 165/*
168 * Memory barriers. 166 * Memory barriers.
169 */ 167 */
170#ifdef __HAVE_ATOMIC_AS_MEMBAR 168#ifdef __HAVE_ATOMIC_AS_MEMBAR
171#define MUTEX_MEMBAR_ENTER() 169#define MUTEX_MEMBAR_ENTER()
172#define MUTEX_MEMBAR_ACQUIRE() 170#define MUTEX_MEMBAR_ACQUIRE()
173#define MUTEX_MEMBAR_RELEASE() 171#define MUTEX_MEMBAR_RELEASE()
174#else 172#else