]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/lock.h
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (C) 1998 Apple Computer
36 * Mach Operating System
37 * Copyright (c) 1991,1990 Carnegie Mellon University
38 * All Rights Reserved.
40 * Permission to use, copy, modify and distribute this software and its
41 * documentation is hereby granted, provided that both the copyright
42 * notice and this permission notice appear in all copies of the
43 * software, derivative works or modified versions, and any portions
44 * thereof, and that both notices appear in supporting documentation.
46 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
48 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
50 * Carnegie Mellon requests users of this software to return to
52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53 * School of Computer Science
54 * Carnegie Mellon University
55 * Pittsburgh PA 15213-3890
57 * any improvements or extensions that they make and grant Carnegie Mellon
58 * the rights to redistribute these changes.
65 * Machine-dependent simple locks for the i386.
72 #include <sys/appleapiopts.h>
74 #ifdef __APPLE_API_PRIVATE
76 #ifdef MACH_KERNEL_PRIVATE
78 #include <kern/macro_help.h>
79 #include <kern/assert.h>
80 #include <i386/hw_lock_types.h>
81 #include <i386/locks.h>
84 #include <mach_ldebug.h>
86 typedef lck_rw_t lock_t
;
88 extern unsigned int LockTimeOutTSC
; /* Lock timeout in TSC ticks */
89 extern unsigned int LockTimeOut
; /* Lock timeout in absolute time */
95 * General bit-lock routines.
98 #define bit_lock(bit,l) \
99 __asm__ volatile(" jmp 1f \n \
106 "r" (bit), "m" (*(volatile int *)(l)) : \
109 #define bit_unlock(bit,l) \
110 __asm__ volatile(" lock \n \
113 "r" (bit), "m" (*(volatile int *)(l)));
116 * Set or clear individual bits in a long word.
117 * The locked access is needed only to lock access
118 * to the word, not to individual bits.
121 #define i_bit_set(bit,l) \
122 __asm__ volatile(" lock \n \
125 "r" (bit), "m" (*(volatile int *)(l)));
127 #define i_bit_clear(bit,l) \
128 __asm__ volatile(" lock \n \
131 "r" (bit), "m" (*(volatile int *)(l)));
133 static inline char xchgb(volatile char * cp
, char new);
135 static inline void atomic_incl(volatile long * p
, long delta
);
136 static inline void atomic_incs(volatile short * p
, short delta
);
137 static inline void atomic_incb(volatile char * p
, char delta
);
139 static inline void atomic_decl(volatile long * p
, long delta
);
140 static inline void atomic_decs(volatile short * p
, short delta
);
141 static inline void atomic_decb(volatile char * p
, char delta
);
143 static inline long atomic_getl(const volatile long * p
);
144 static inline short atomic_gets(const volatile short * p
);
145 static inline char atomic_getb(const volatile char * p
);
147 static inline void atomic_setl(volatile long * p
, long value
);
148 static inline void atomic_sets(volatile short * p
, short value
);
149 static inline void atomic_setb(volatile char * p
, char value
);
151 static inline char xchgb(volatile char * cp
, char new)
153 register char old
= new;
155 __asm__
volatile (" xchgb %0,%2" :
157 "0" (new), "m" (*(volatile char *)cp
) : "memory");
161 static inline void atomic_incl(volatile long * p
, long delta
)
163 __asm__
volatile (" lock \n \
166 "r" (delta
), "m" (*(volatile long *)p
));
169 static inline void atomic_incs(volatile short * p
, short delta
)
171 __asm__
volatile (" lock \n \
174 "q" (delta
), "m" (*(volatile short *)p
));
177 static inline void atomic_incb(volatile char * p
, char delta
)
179 __asm__
volatile (" lock \n \
182 "q" (delta
), "m" (*(volatile char *)p
));
185 static inline void atomic_decl(volatile long * p
, long delta
)
187 __asm__
volatile (" lock \n \
190 "r" (delta
), "m" (*(volatile long *)p
));
193 static inline int atomic_decl_and_test(volatile long * p
, long delta
)
201 : "r" (delta
), "m" (*(volatile long *)p
));
205 static inline void atomic_decs(volatile short * p
, short delta
)
207 __asm__
volatile (" lock \n \
210 "q" (delta
), "m" (*(volatile short *)p
));
213 static inline void atomic_decb(volatile char * p
, char delta
)
215 __asm__
volatile (" lock \n \
218 "q" (delta
), "m" (*(volatile char *)p
));
221 static inline long atomic_getl(const volatile long * p
)
226 static inline short atomic_gets(const volatile short * p
)
231 static inline char atomic_getb(const volatile char * p
)
236 static inline void atomic_setl(volatile long * p
, long value
)
241 static inline void atomic_sets(volatile short * p
, short value
)
246 static inline void atomic_setb(volatile char * p
, char value
)
252 #else /* !defined(__GNUC__) */
254 extern void i_bit_set(
258 extern void i_bit_clear(
262 extern void bit_lock(
266 extern void bit_unlock(
271 * All other routines defined in __GNUC__ case lack
272 * definitions otherwise. - XXX
275 #endif /* !defined(__GNUC__) */
277 extern void kernel_preempt_check (void);
279 #endif /* MACH_KERNEL_PRIVATE */
281 #endif /* __APLE_API_PRIVATE */
283 #endif /* _I386_LOCK_H_ */
285 #endif /* KERNEL_PRIVATE */