2 * Copyright (c) 2003-2009 Apple, 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 #include <sys/appleapiopts.h>
30 #include <machine/cpu_capabilities.h>
32 #include <mach/i386/syscall_sw.h>
35 PLATFUNC_FUNCTION_START(OSSpinLockTry, up, 32, 4)
36 PLATFUNC_FUNCTION_START(_spin_lock_try, up, 32, 4)
44 PLATFUNC_DESCRIPTOR(OSSpinLockTry,up,kUP,0)
45 PLATFUNC_DESCRIPTOR(_spin_lock_try,up,kUP,0)
47 PLATFUNC_FUNCTION_START_GENERIC(OSSpinLockTry, mp, 32, 4)
48 PLATFUNC_FUNCTION_START_GENERIC(_spin_lock_try, mp, 32, 4)
57 PLATFUNC_DESCRIPTOR(OSSpinLockTry,mp,0,kUP)
58 PLATFUNC_DESCRIPTOR(_spin_lock_try,mp,0,kUP)
61 PLATFUNC_FUNCTION_START(spin_lock, up, 32, 4)
62 PLATFUNC_FUNCTION_START(OSSpinLockLock, up, 32, 4)
63 PLATFUNC_FUNCTION_START(_spin_lock, up, 32, 4)
72 /* failed to get lock so relinquish the processor immediately on UP */
74 pushl $1 /* SWITCH_OPTION_DEPRESS */
75 pushl $0 /* THREAD_NULL */
76 pushl $0 /* push dummy stack ret addr */
77 movl $-61,%eax /* SYSCALL_THREAD_SWITCH */
79 addl $16, %esp /* adjust stack*/
81 PLATFUNC_DESCRIPTOR(spin_lock,up,kUP,0)
82 PLATFUNC_DESCRIPTOR(OSSpinLockLock,up,kUP,0)
83 PLATFUNC_DESCRIPTOR(_spin_lock,up,kUP,0)
85 PLATFUNC_FUNCTION_START_GENERIC(spin_lock, mp, 32, 4)
86 PLATFUNC_FUNCTION_START_GENERIC(OSSpinLockLock, mp, 32, 4)
87 PLATFUNC_FUNCTION_START_GENERIC(_spin_lock, mp, 32, 4)
99 movl $(MP_SPIN_TRIES), %edx
103 jz 0b /* favor success and slow down spin loop */
106 /* failed to get lock after spinning so relinquish */
108 pushl $1 /* SWITCH_OPTION_DEPRESS */
109 pushl $0 /* THREAD_NULL */
110 pushl $0 /* push dummy stack ret addr */
111 movl $-61,%eax /* SYSCALL_THREAD_SWITCH */
113 addl $16, %esp /* adjust stack*/
115 PLATFUNC_DESCRIPTOR(spin_lock,mp,0,kUP)
116 PLATFUNC_DESCRIPTOR(OSSpinLockLock,mp,0,kUP)
117 PLATFUNC_DESCRIPTOR(_spin_lock,mp,0,kUP)
120 .globl _OSSpinLockUnlock