lock.h revision 1.14.16.1 1 /* $NetBSD: lock.h,v 1.14.16.1 2008/06/02 13:22:38 mjf Exp $ */
2
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gregory McGarry.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Machine-dependent spin lock operations.
34 */
35
36 #ifndef _SH3_LOCK_H_
37 #define _SH3_LOCK_H_
38
39 static __inline void __cpu_simple_lock_init(__cpu_simple_lock_t *)
40 __attribute__((__unused__));
41 static __inline void __cpu_simple_lock(__cpu_simple_lock_t *)
42 __attribute__((__unused__));
43 static __inline int __cpu_simple_lock_try(__cpu_simple_lock_t *)
44 __attribute__((__unused__));
45 static __inline void __cpu_simple_unlock(__cpu_simple_lock_t *)
46 __attribute__((__unused__));
47
48 static __inline int
49 __SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t *__ptr)
50 {
51 return *__ptr == __SIMPLELOCK_LOCKED;
52 }
53
54 static __inline int
55 __SIMPLELOCK_UNLOCKED_P(__cpu_simple_lock_t *__ptr)
56 {
57 return *__ptr == __SIMPLELOCK_UNLOCKED;
58 }
59
60 static __inline void
61 __cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr)
62 {
63 *__ptr = __SIMPLELOCK_UNLOCKED;
64 }
65
66 static __inline void
67 __cpu_simple_lock_set(__cpu_simple_lock_t *__ptr)
68 {
69 *__ptr = __SIMPLELOCK_LOCKED;
70 }
71
72 static __inline void
73 __cpu_simple_lock_init(__cpu_simple_lock_t *alp)
74 {
75
76 *alp = __SIMPLELOCK_UNLOCKED;
77 }
78
79 static __inline void
80 __cpu_simple_lock(__cpu_simple_lock_t *alp)
81 {
82
83 __asm volatile(
84 "1: tas.b %0 \n"
85 " bf 1b \n"
86 : "=m" (*alp)
87 : /* no inputs */
88 : "cc");
89 }
90
91 static __inline int
92 __cpu_simple_lock_try(__cpu_simple_lock_t *alp)
93 {
94 int __rv;
95
96 __asm volatile(
97 " tas.b %0 \n"
98 " movt %1 \n"
99 : "=m" (*alp), "=r" (__rv)
100 : /* no inputs */
101 : "cc");
102
103 return (__rv);
104 }
105
106 static __inline void
107 __cpu_simple_unlock(__cpu_simple_lock_t *alp)
108 {
109
110 *alp = __SIMPLELOCK_UNLOCKED;
111 }
112
113 static __inline void
114 mb_read(void)
115 {
116 __asm volatile("" : : : "memory");
117 }
118
119 static __inline void
120 mb_write(void)
121 {
122 __asm volatile("" : : : "memory");
123 }
124
125 static __inline void
126 mb_memory(void)
127 {
128 __asm volatile("" : : : "memory");
129 }
130
131 #endif /* !_SH3_LOCK_H_ */
132