]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2008-2012 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_APACHE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
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. | |
17 | * | |
18 | * @APPLE_APACHE_LICENSE_HEADER_END@ | |
19 | */ | |
20 | ||
21 | #ifndef __DISPATCH_BASE__ | |
22 | #define __DISPATCH_BASE__ | |
23 | ||
24 | #ifndef __DISPATCH_INDIRECT__ | |
25 | #error "Please #include <dispatch/dispatch.h> instead of this file directly." | |
26 | #endif | |
27 | ||
28 | #ifndef __has_builtin | |
29 | #define __has_builtin(x) 0 | |
30 | #endif | |
31 | #ifndef __has_include | |
32 | #define __has_include(x) 0 | |
33 | #endif | |
34 | #ifndef __has_feature | |
35 | #define __has_feature(x) 0 | |
36 | #endif | |
37 | #ifndef __has_attribute | |
38 | #define __has_attribute(x) 0 | |
39 | #endif | |
40 | #ifndef __has_extension | |
41 | #define __has_extension(x) 0 | |
42 | #endif | |
43 | ||
44 | #if __GNUC__ | |
45 | #define DISPATCH_NORETURN __attribute__((__noreturn__)) | |
46 | #define DISPATCH_NOTHROW __attribute__((__nothrow__)) | |
47 | #define DISPATCH_NONNULL1 __attribute__((__nonnull__(1))) | |
48 | #define DISPATCH_NONNULL2 __attribute__((__nonnull__(2))) | |
49 | #define DISPATCH_NONNULL3 __attribute__((__nonnull__(3))) | |
50 | #define DISPATCH_NONNULL4 __attribute__((__nonnull__(4))) | |
51 | #define DISPATCH_NONNULL5 __attribute__((__nonnull__(5))) | |
52 | #define DISPATCH_NONNULL6 __attribute__((__nonnull__(6))) | |
53 | #define DISPATCH_NONNULL7 __attribute__((__nonnull__(7))) | |
54 | #if __clang__ && __clang_major__ < 3 | |
55 | // rdar://problem/6857843 | |
56 | #define DISPATCH_NONNULL_ALL | |
57 | #else | |
58 | #define DISPATCH_NONNULL_ALL __attribute__((__nonnull__)) | |
59 | #endif | |
60 | #define DISPATCH_SENTINEL __attribute__((__sentinel__)) | |
61 | #define DISPATCH_PURE __attribute__((__pure__)) | |
62 | #define DISPATCH_CONST __attribute__((__const__)) | |
63 | #define DISPATCH_WARN_RESULT __attribute__((__warn_unused_result__)) | |
64 | #define DISPATCH_MALLOC __attribute__((__malloc__)) | |
65 | #define DISPATCH_ALWAYS_INLINE __attribute__((__always_inline__)) | |
66 | #define DISPATCH_UNAVAILABLE __attribute__((__unavailable__)) | |
67 | #define DISPATCH_UNAVAILABLE_MSG(msg) __attribute__((__unavailable__(msg))) | |
68 | #else | |
69 | /*! @parseOnly */ | |
70 | #define DISPATCH_NORETURN | |
71 | /*! @parseOnly */ | |
72 | #define DISPATCH_NOTHROW | |
73 | /*! @parseOnly */ | |
74 | #define DISPATCH_NONNULL1 | |
75 | /*! @parseOnly */ | |
76 | #define DISPATCH_NONNULL2 | |
77 | /*! @parseOnly */ | |
78 | #define DISPATCH_NONNULL3 | |
79 | /*! @parseOnly */ | |
80 | #define DISPATCH_NONNULL4 | |
81 | /*! @parseOnly */ | |
82 | #define DISPATCH_NONNULL5 | |
83 | /*! @parseOnly */ | |
84 | #define DISPATCH_NONNULL6 | |
85 | /*! @parseOnly */ | |
86 | #define DISPATCH_NONNULL7 | |
87 | /*! @parseOnly */ | |
88 | #define DISPATCH_NONNULL_ALL | |
89 | /*! @parseOnly */ | |
90 | #define DISPATCH_SENTINEL | |
91 | /*! @parseOnly */ | |
92 | #define DISPATCH_PURE | |
93 | /*! @parseOnly */ | |
94 | #define DISPATCH_CONST | |
95 | /*! @parseOnly */ | |
96 | #define DISPATCH_WARN_RESULT | |
97 | /*! @parseOnly */ | |
98 | #define DISPATCH_MALLOC | |
99 | /*! @parseOnly */ | |
100 | #define DISPATCH_ALWAYS_INLINE | |
101 | /*! @parseOnly */ | |
102 | #define DISPATCH_UNAVAILABLE | |
103 | /*! @parseOnly */ | |
104 | #define DISPATCH_UNAVAILABLE_MSG(msg) | |
105 | #endif | |
106 | ||
107 | #ifdef __linux__ | |
108 | #define DISPATCH_LINUX_UNAVAILABLE() \ | |
109 | DISPATCH_UNAVAILABLE_MSG( \ | |
110 | "This interface is unavailable on linux systems") | |
111 | #else | |
112 | #define DISPATCH_LINUX_UNAVAILABLE() | |
113 | #endif | |
114 | ||
115 | #ifndef DISPATCH_ALIAS_V2 | |
116 | #if TARGET_OS_MAC | |
117 | #define DISPATCH_ALIAS_V2(sym) __asm__("_" #sym "$V2") | |
118 | #else | |
119 | #define DISPATCH_ALIAS_V2(sym) | |
120 | #endif | |
121 | #endif | |
122 | ||
123 | #if TARGET_OS_WIN32 && defined(__DISPATCH_BUILDING_DISPATCH__) && \ | |
124 | defined(__cplusplus) | |
125 | #define DISPATCH_EXPORT extern "C" extern __declspec(dllexport) | |
126 | #elif TARGET_OS_WIN32 && defined(__DISPATCH_BUILDING_DISPATCH__) | |
127 | #define DISPATCH_EXPORT extern __declspec(dllexport) | |
128 | #elif TARGET_OS_WIN32 && defined(__cplusplus) | |
129 | #define DISPATCH_EXPORT extern "C" extern __declspec(dllimport) | |
130 | #elif TARGET_OS_WIN32 | |
131 | #define DISPATCH_EXPORT extern __declspec(dllimport) | |
132 | #elif __GNUC__ | |
133 | #define DISPATCH_EXPORT extern __attribute__((visibility("default"))) | |
134 | #else | |
135 | #define DISPATCH_EXPORT extern | |
136 | #endif | |
137 | ||
138 | #if __GNUC__ | |
139 | #define DISPATCH_INLINE static __inline__ | |
140 | #else | |
141 | #define DISPATCH_INLINE static inline | |
142 | #endif | |
143 | ||
144 | #if __GNUC__ | |
145 | #define DISPATCH_EXPECT(x, v) __builtin_expect((x), (v)) | |
146 | #define dispatch_compiler_barrier() __asm__ __volatile__("" ::: "memory") | |
147 | #else | |
148 | #define DISPATCH_EXPECT(x, v) (x) | |
149 | #define dispatch_compiler_barrier() do { } while (0) | |
150 | #endif | |
151 | ||
152 | #if __has_attribute(not_tail_called) | |
153 | #define DISPATCH_NOT_TAIL_CALLED __attribute__((__not_tail_called__)) | |
154 | #else | |
155 | #define DISPATCH_NOT_TAIL_CALLED | |
156 | #endif | |
157 | ||
158 | #if __has_builtin(__builtin_assume) | |
159 | #define DISPATCH_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr) | |
160 | #else | |
161 | #define DISPATCH_COMPILER_CAN_ASSUME(expr) ((void)(expr)) | |
162 | #endif | |
163 | ||
164 | #if __has_attribute(noescape) | |
165 | #define DISPATCH_NOESCAPE __attribute__((__noescape__)) | |
166 | #else | |
167 | #define DISPATCH_NOESCAPE | |
168 | #endif | |
169 | ||
170 | #if __has_feature(assume_nonnull) | |
171 | #define DISPATCH_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") | |
172 | #define DISPATCH_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") | |
173 | #else | |
174 | #define DISPATCH_ASSUME_NONNULL_BEGIN | |
175 | #define DISPATCH_ASSUME_NONNULL_END | |
176 | #endif | |
177 | ||
178 | #if !__has_feature(nullability) | |
179 | #ifndef _Nullable | |
180 | #define _Nullable | |
181 | #endif | |
182 | #ifndef _Nonnull | |
183 | #define _Nonnull | |
184 | #endif | |
185 | #ifndef _Null_unspecified | |
186 | #define _Null_unspecified | |
187 | #endif | |
188 | #endif | |
189 | ||
190 | #ifndef DISPATCH_RETURNS_RETAINED_BLOCK | |
191 | #if __has_attribute(ns_returns_retained) | |
192 | #define DISPATCH_RETURNS_RETAINED_BLOCK __attribute__((__ns_returns_retained__)) | |
193 | #else | |
194 | #define DISPATCH_RETURNS_RETAINED_BLOCK | |
195 | #endif | |
196 | #endif | |
197 | ||
198 | #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums) | |
199 | #define DISPATCH_ENUM(name, type, ...) \ | |
200 | typedef enum : type { __VA_ARGS__ } name##_t | |
201 | #else | |
202 | #define DISPATCH_ENUM(name, type, ...) \ | |
203 | enum { __VA_ARGS__ }; typedef type name##_t | |
204 | #endif | |
205 | ||
206 | #if __has_feature(enumerator_attributes) | |
207 | #define DISPATCH_ENUM_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__) | |
208 | #define DISPATCH_ENUM_API_DEPRECATED(...) API_DEPRECATED(__VA_ARGS__) | |
209 | #define DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT(...) \ | |
210 | API_DEPRECATED_WITH_REPLACEMENT(__VA_ARGS__) | |
211 | #else | |
212 | #define DISPATCH_ENUM_API_AVAILABLE(...) | |
213 | #define DISPATCH_ENUM_API_DEPRECATED(...) | |
214 | #define DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT(...) | |
215 | #endif | |
216 | ||
217 | #if defined(SWIFT_SDK_OVERLAY_DISPATCH_EPOCH) && \ | |
218 | SWIFT_SDK_OVERLAY_DISPATCH_EPOCH >= 2 | |
219 | #define DISPATCH_SWIFT3_OVERLAY 1 | |
220 | #else | |
221 | #define DISPATCH_SWIFT3_OVERLAY 0 | |
222 | #endif // SWIFT_SDK_OVERLAY_DISPATCH_EPOCH >= 2 | |
223 | ||
224 | #if __has_feature(attribute_availability_swift) | |
225 | #define DISPATCH_SWIFT_UNAVAILABLE(_msg) \ | |
226 | __attribute__((__availability__(swift, unavailable, message=_msg))) | |
227 | #else | |
228 | #define DISPATCH_SWIFT_UNAVAILABLE(_msg) | |
229 | #endif | |
230 | ||
231 | #if DISPATCH_SWIFT3_OVERLAY | |
232 | #define DISPATCH_SWIFT3_UNAVAILABLE(_msg) DISPATCH_SWIFT_UNAVAILABLE(_msg) | |
233 | #else | |
234 | #define DISPATCH_SWIFT3_UNAVAILABLE(_msg) | |
235 | #endif | |
236 | ||
237 | #if __has_attribute(swift_private) | |
238 | #define DISPATCH_REFINED_FOR_SWIFT __attribute__((__swift_private__)) | |
239 | #else | |
240 | #define DISPATCH_REFINED_FOR_SWIFT | |
241 | #endif | |
242 | ||
243 | #if __has_attribute(swift_name) | |
244 | #define DISPATCH_SWIFT_NAME(_name) __attribute__((__swift_name__(#_name))) | |
245 | #else | |
246 | #define DISPATCH_SWIFT_NAME(_name) | |
247 | #endif | |
248 | ||
249 | #ifndef __cplusplus | |
250 | #define DISPATCH_TRANSPARENT_UNION __attribute__((__transparent_union__)) | |
251 | #else | |
252 | #define DISPATCH_TRANSPARENT_UNION | |
253 | #endif | |
254 | ||
255 | typedef void (*dispatch_function_t)(void *_Nullable); | |
256 | ||
257 | #endif |