Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / sh3 / include / lock.h
blobad28b3c7e00b4c3f71e2c8483503ad647cb85734
1 /* $NetBSD: lock.h,v 1.15 2008/04/28 20:23:35 martin Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gregory McGarry.
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.
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.
33 * Machine-dependent spin lock operations.
36 #ifndef _SH3_LOCK_H_
37 #define _SH3_LOCK_H_
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__));
48 static __inline int
49 __SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t *__ptr)
51 return *__ptr == __SIMPLELOCK_LOCKED;
54 static __inline int
55 __SIMPLELOCK_UNLOCKED_P(__cpu_simple_lock_t *__ptr)
57 return *__ptr == __SIMPLELOCK_UNLOCKED;
60 static __inline void
61 __cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr)
63 *__ptr = __SIMPLELOCK_UNLOCKED;
66 static __inline void
67 __cpu_simple_lock_set(__cpu_simple_lock_t *__ptr)
69 *__ptr = __SIMPLELOCK_LOCKED;
72 static __inline void
73 __cpu_simple_lock_init(__cpu_simple_lock_t *alp)
76 *alp = __SIMPLELOCK_UNLOCKED;
79 static __inline void
80 __cpu_simple_lock(__cpu_simple_lock_t *alp)
83 __asm volatile(
84 "1: tas.b @%0 \n"
85 " bf 1b \n"
86 : /* no outputs */
87 : "r" (alp)
88 : "cc", "memory");
91 static __inline int
92 __cpu_simple_lock_try(__cpu_simple_lock_t *alp)
94 int __rv;
96 __asm volatile(
97 " tas.b @%1 \n"
98 " movt %0 \n"
99 : "=r" (__rv)
100 : "r" (alp)
101 : "cc", "memory");
103 return (__rv);
106 static __inline void
107 __cpu_simple_unlock(__cpu_simple_lock_t *alp)
110 *alp = __SIMPLELOCK_UNLOCKED;
113 static __inline void
114 mb_read(void)
116 __asm volatile("" : : : "memory");
119 static __inline void
120 mb_write(void)
122 __asm volatile("" : : : "memory");
125 static __inline void
126 mb_memory(void)
128 __asm volatile("" : : : "memory");
131 #endif /* !_SH3_LOCK_H_ */