FreeBSD/Linux Kernel Cross Reference
sys/sys/simplelock.h
1 /* $NetBSD: simplelock.h,v 1.8 2008/04/28 20:24:11 martin Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000, 2006, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
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.
10 *
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Ross Harvey.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 /*
37 * Copyright (c) 1995
38 * The Regents of the University of California. All rights reserved.
39 *
40 * This code contains ideas from software contributed to Berkeley by
41 * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating
42 * System project at Carnegie-Mellon University.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 *
68 * @(#)lock.h 8.12 (Berkeley) 5/19/95
69 */
70
71 #ifndef _SYS_SIMPLELOCK_H_
72 #define _SYS_SIMPLELOCK_H_
73
74 #if defined(_KERNEL_OPT)
75 #include "opt_multiprocessor.h"
76 #include "opt_lockdebug.h"
77 #endif
78
79 #include <machine/types.h>
80 #include <machine/lock.h>
81
82 /*
83 * The simple lock. Provides a simple spinning mutex. Note the
84 * member which is used in atomic operations must be aligned in
85 * order for it to work on the widest range of processor types.
86 */
87 struct simplelock {
88 __cpu_simple_lock_t lock_data;
89 #ifdef __CPU_SIMPLE_LOCK_PAD
90 /*
91 * For binary compatibility where the lock word has been
92 * made shorter.
93 */
94 uint8_t lock_pad[3];
95 #endif
96 };
97
98 #define SIMPLELOCK_INITIALIZER { .lock_data = __SIMPLELOCK_UNLOCKED }
99
100 #ifdef _KERNEL
101
102 #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
103 #define simple_lock_init(alp) __cpu_simple_lock_init(&(alp)->lock_data)
104 #define simple_lock(alp) __cpu_simple_lock(&(alp)->lock_data)
105 #define simple_lock_held(alp) (__SIMPLELOCK_LOCKED_P(&(alp)->lock_data))
106 #define simple_lock_try(alp) __cpu_simple_lock_try(&(alp)->lock_data)
107 #define simple_unlock(alp) __cpu_simple_unlock(&(alp)->lock_data)
108 #else
109 #define simple_lock_nothing(alp) \
110 do { \
111 (void)alp; \
112 } while (0);
113 #define simple_lock_init(alp) simple_lock_nothing(alp)
114 #define simple_lock(alp) simple_lock_nothing(alp)
115 #define simple_lock_held(alp) 1
116 #define simple_lock_try(alp) 1
117 #define simple_unlock(alp) simple_lock_nothing(alp)
118 #endif
119
120 #endif /* _KERNEL */
121
122 #endif /* _SYS_SIMPLELOCK_H_ */
Cache object: 9a30f2f2f966981ef4a1c8150952688e
|