1 /* $NetBSD: lock.h,v 1.86 2010/07/01 13:00:57 hannken Exp $ */
4 * Copyright (c) 1999, 2000, 2006, 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, by Ross Harvey, and by Andrew Doran.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
35 * The Regents of the University of California. All rights reserved.
37 * This code contains ideas from software contributed to Berkeley by
38 * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating
39 * System project at Carnegie-Mellon University.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * @(#)lock.h 8.12 (Berkeley) 5/19/95
71 #include <sys/stdint.h>
72 #include <sys/mutex.h>
74 #include <machine/lock.h>
79 * From <machine/lock.h>.
81 #ifndef SPINLOCK_SPIN_HOOK
82 #define SPINLOCK_SPIN_HOOK
84 #ifndef SPINLOCK_BACKOFF_HOOK
85 #define SPINLOCK_BACKOFF_HOOK nullop(NULL)
87 #ifndef SPINLOCK_BACKOFF_MIN
88 #define SPINLOCK_BACKOFF_MIN 4
90 #ifndef SPINLOCK_BACKOFF_MAX
91 #define SPINLOCK_BACKOFF_MAX 128
94 #define SPINLOCK_BACKOFF(count) \
97 for (__i = (count); __i != 0; __i--) { \
98 SPINLOCK_BACKOFF_HOOK; \
100 if ((count) < SPINLOCK_BACKOFF_MAX) \
101 (count) += (count); \
102 } while (/* CONSTCOND */ 0);
104 #define SPINLOCK_RUN_HOOK(count) ((count) >= SPINLOCK_BACKOFF_MAX)
107 #define SPINLOCK_SPINOUT(spins) ((spins)++ > 0x0fffffff)
109 #define SPINLOCK_SPINOUT(spins) ((void)(spins), 0)
112 extern __cpu_simple_lock_t kernel_lock
[];
116 #endif /* _SYS_LOCK_H_ */