]>
Commit | Line | Data |
---|---|---|
0ab74447 | 1 | /* |
517da941 | 2 | * Copyright (c) 2008-2012 Apple Inc. All rights reserved. |
0ab74447 A |
3 | * |
4 | * @APPLE_APACHE_LICENSE_HEADER_START@ | |
e85f4437 | 5 | * |
0ab74447 A |
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 | |
e85f4437 | 9 | * |
0ab74447 | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
e85f4437 | 11 | * |
0ab74447 A |
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. | |
e85f4437 | 17 | * |
0ab74447 A |
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 | ||
beb15981 A |
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 | ||
e85f4437 | 44 | #if __GNUC__ |
0ab74447 A |
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))) | |
e85f4437 | 54 | #if __clang__ && __clang_major__ < 3 |
0ab74447 A |
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__)) | |
e85f4437 | 62 | #define DISPATCH_CONST __attribute__((__const__)) |
0ab74447 A |
63 | #define DISPATCH_WARN_RESULT __attribute__((__warn_unused_result__)) |
64 | #define DISPATCH_MALLOC __attribute__((__malloc__)) | |
e85f4437 | 65 | #define DISPATCH_ALWAYS_INLINE __attribute__((__always_inline__)) |
98cf8cd2 | 66 | #define DISPATCH_UNAVAILABLE __attribute__((__unavailable__)) |
beb15981 | 67 | #define DISPATCH_UNAVAILABLE_MSG(msg) __attribute__((__unavailable__(msg))) |
0ab74447 A |
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 */ | |
e85f4437 A |
94 | #define DISPATCH_CONST |
95 | /*! @parseOnly */ | |
0ab74447 A |
96 | #define DISPATCH_WARN_RESULT |
97 | /*! @parseOnly */ | |
98 | #define DISPATCH_MALLOC | |
e85f4437 A |
99 | /*! @parseOnly */ |
100 | #define DISPATCH_ALWAYS_INLINE | |
98cf8cd2 A |
101 | /*! @parseOnly */ |
102 | #define DISPATCH_UNAVAILABLE | |
beb15981 A |
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 | |
e85f4437 A |
121 | #endif |
122 | ||
517da941 A |
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__ | |
e85f4437 A |
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)) | |
beb15981 | 146 | #define dispatch_compiler_barrier() __asm__ __volatile__("" ::: "memory") |
e85f4437 A |
147 | #else |
148 | #define DISPATCH_EXPECT(x, v) (x) | |
beb15981 A |
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 | |
0ab74447 A |
188 | #endif |
189 | ||
98cf8cd2 | 190 | #ifndef DISPATCH_RETURNS_RETAINED_BLOCK |
98cf8cd2 A |
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 | |
98cf8cd2 A |
196 | #endif |
197 | ||
98cf8cd2 | 198 | #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums) |
517da941 A |
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 | |
beb15981 | 205 | |
98cf8cd2 | 206 | #if __has_feature(enumerator_attributes) |
6b746eb4 A |
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__) | |
98cf8cd2 | 211 | #else |
6b746eb4 A |
212 | #define DISPATCH_ENUM_API_AVAILABLE(...) |
213 | #define DISPATCH_ENUM_API_DEPRECATED(...) | |
214 | #define DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT(...) | |
98cf8cd2 | 215 | #endif |
beb15981 A |
216 | |
217 | #if defined(SWIFT_SDK_OVERLAY_DISPATCH_EPOCH) && \ | |
218 | SWIFT_SDK_OVERLAY_DISPATCH_EPOCH >= 2 | |
219 | #define DISPATCH_SWIFT3_OVERLAY 1 | |
517da941 | 220 | #else |
beb15981 A |
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) | |
517da941 A |
247 | #endif |
248 | ||
6b746eb4 A |
249 | #ifndef __cplusplus |
250 | #define DISPATCH_TRANSPARENT_UNION __attribute__((__transparent_union__)) | |
251 | #else | |
252 | #define DISPATCH_TRANSPARENT_UNION | |
253 | #endif | |
254 | ||
beb15981 | 255 | typedef void (*dispatch_function_t)(void *_Nullable); |
c093abd6 | 256 | |
0ab74447 | 257 | #endif |