]>
git.saurik.com Git - apple/libplatform.git/blob - internal/os/yield.h
2 * Copyright (c) 2013 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
22 * IMPORTANT: This header file describes INTERNAL interfaces to libplatform
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
30 #include <TargetConditionals.h>
33 #pragma mark _os_wait_until
36 #define _os_wait_until(c) do { \
38 while (unlikely(!(c))) { \
40 _os_preemption_yield(_spins); \
42 #elif TARGET_OS_EMBEDDED
43 // <rdar://problem/15508918>
45 #define OS_WAIT_SPINS 1024
47 #define _os_wait_until(c) do { \
48 int _spins = -(OS_WAIT_SPINS); \
49 while (unlikely(!(c))) { \
50 if (unlikely(_spins++ >= 0)) { \
51 _os_preemption_yield(_spins); \
53 os_hardware_pause(); \
57 #define _os_wait_until(c) do { \
59 os_hardware_pause(); \
64 #pragma mark os_hardware_pause
66 #if defined(__x86_64__) || defined(__i386__)
67 #define os_hardware_pause() __asm__("pause")
68 #elif (defined(__arm__) && defined(_ARM_ARCH_7) && defined(__thumb__)) || \
70 #define os_hardware_pause() __asm__("yield")
71 #define os_hardware_wfe() __asm__("wfe")
73 #define os_hardware_pause() __asm__("")
77 #pragma mark _os_preemption_yield
79 #if defined(SWITCH_OPTION_OSLOCK_DEPRESS) && !(TARGET_IPHONE_SIMULATOR && \
80 IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1090)
81 #define OS_YIELD_THREAD_SWITCH_OPTION SWITCH_OPTION_OSLOCK_DEPRESS
83 #define OS_YIELD_THREAD_SWITCH_OPTION SWITCH_OPTION_DEPRESS
85 #define _os_preemption_yield(n) thread_switch(MACH_PORT_NULL, \
86 OS_YIELD_THREAD_SWITCH_OPTION, (mach_msg_timeout_t)(n))
88 #endif // __OS_YIELD__