| 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 | #elif defined(_MSC_VER) |
| 69 | #define DISPATCH_NORETURN __declspec(noreturn) |
| 70 | #define DISPATCH_NOTHROW __declspec(nothrow) |
| 71 | #define DISPATCH_NONNULL1 |
| 72 | #define DISPATCH_NONNULL2 |
| 73 | #define DISPATCH_NONNULL3 |
| 74 | #define DISPATCH_NONNULL4 |
| 75 | #define DISPATCH_NONNULL5 |
| 76 | #define DISPATCH_NONNULL6 |
| 77 | #define DISPATCH_NONNULL7 |
| 78 | #define DISPATCH_NONNULL_ALL |
| 79 | #define DISPATCH_SENTINEL |
| 80 | #define DISPATCH_PURE |
| 81 | #define DISPATCH_CONST |
| 82 | #if (_MSC_VER >= 1700) |
| 83 | #define DISPATCH_WARN_RESULT _Check_return_ |
| 84 | #else |
| 85 | #define DISPATCH_WARN_RESULT |
| 86 | #endif |
| 87 | #define DISPATCH_MALLOC |
| 88 | #define DISPATCH_ALWAYS_INLINE __forceinline |
| 89 | #define DISPATCH_UNAVAILABLE |
| 90 | #define DISPATCH_UNAVAILABLE_MSG(msg) |
| 91 | #else |
| 92 | /*! @parseOnly */ |
| 93 | #define DISPATCH_NORETURN |
| 94 | /*! @parseOnly */ |
| 95 | #define DISPATCH_NOTHROW |
| 96 | /*! @parseOnly */ |
| 97 | #define DISPATCH_NONNULL1 |
| 98 | /*! @parseOnly */ |
| 99 | #define DISPATCH_NONNULL2 |
| 100 | /*! @parseOnly */ |
| 101 | #define DISPATCH_NONNULL3 |
| 102 | /*! @parseOnly */ |
| 103 | #define DISPATCH_NONNULL4 |
| 104 | /*! @parseOnly */ |
| 105 | #define DISPATCH_NONNULL5 |
| 106 | /*! @parseOnly */ |
| 107 | #define DISPATCH_NONNULL6 |
| 108 | /*! @parseOnly */ |
| 109 | #define DISPATCH_NONNULL7 |
| 110 | /*! @parseOnly */ |
| 111 | #define DISPATCH_NONNULL_ALL |
| 112 | /*! @parseOnly */ |
| 113 | #define DISPATCH_SENTINEL |
| 114 | /*! @parseOnly */ |
| 115 | #define DISPATCH_PURE |
| 116 | /*! @parseOnly */ |
| 117 | #define DISPATCH_CONST |
| 118 | /*! @parseOnly */ |
| 119 | #define DISPATCH_WARN_RESULT |
| 120 | /*! @parseOnly */ |
| 121 | #define DISPATCH_MALLOC |
| 122 | /*! @parseOnly */ |
| 123 | #define DISPATCH_ALWAYS_INLINE |
| 124 | /*! @parseOnly */ |
| 125 | #define DISPATCH_UNAVAILABLE |
| 126 | /*! @parseOnly */ |
| 127 | #define DISPATCH_UNAVAILABLE_MSG(msg) |
| 128 | #endif |
| 129 | |
| 130 | #if defined(__cplusplus) |
| 131 | # if __cplusplus >= 201703L |
| 132 | # define DISPATCH_FALLTHROUGH [[fallthrough]] |
| 133 | # elif __cplusplus >= 201103L |
| 134 | # if defined(__clang__) |
| 135 | # define DISPATCH_FALLTHROUGH [[clang::fallthrough]] |
| 136 | # elif defined(__GNUC__) && __GNUC__ >= 7 |
| 137 | # define DISPATCH_FALLTHROUGH [[gnu::fallthrough]] |
| 138 | # else |
| 139 | # define DISPATCH_FALLTHROUGH |
| 140 | # endif |
| 141 | # else |
| 142 | # define DISPATCH_FALLTHROUGH |
| 143 | # endif |
| 144 | #elif defined(__GNUC__) && __GNUC__ >= 7 |
| 145 | # define DISPATCH_FALLTHROUGH __attribute__((__fallthrough__)) |
| 146 | #elif defined(__clang__) |
| 147 | # if __has_attribute(fallthrough) && __clang_major__ >= 5 |
| 148 | # define DISPATCH_FALLTHROUGH __attribute__((__fallthrough__)) |
| 149 | # else |
| 150 | # define DISPATCH_FALLTHROUGH |
| 151 | # endif |
| 152 | #else |
| 153 | # define DISPATCH_FALLTHROUGH |
| 154 | #endif |
| 155 | |
| 156 | |
| 157 | #define DISPATCH_LINUX_UNAVAILABLE() |
| 158 | |
| 159 | #ifdef __FreeBSD__ |
| 160 | #define DISPATCH_FREEBSD_UNAVAILABLE() \ |
| 161 | 		DISPATCH_UNAVAILABLE_MSG( \ |
| 162 | 		"This interface is unavailable on FreeBSD systems") |
| 163 | #else |
| 164 | #define DISPATCH_FREEBSD_UNAVAILABLE() |
| 165 | #endif |
| 166 | |
| 167 | #ifndef DISPATCH_ALIAS_V2 |
| 168 | #if TARGET_OS_MAC |
| 169 | #define DISPATCH_ALIAS_V2(sym)	 __asm__("_" #sym "$V2") |
| 170 | #else |
| 171 | #define DISPATCH_ALIAS_V2(sym) |
| 172 | #endif |
| 173 | #endif |
| 174 | |
| 175 | #if defined(_WIN32) |
| 176 | #if defined(__cplusplus) |
| 177 | #define DISPATCH_EXPORT extern "C" __declspec(dllimport) |
| 178 | #else |
| 179 | #define DISPATCH_EXPORT extern __declspec(dllimport) |
| 180 | #endif |
| 181 | #elif __GNUC__ |
| 182 | #define DISPATCH_EXPORT extern __attribute__((visibility("default"))) |
| 183 | #else |
| 184 | #define DISPATCH_EXPORT extern |
| 185 | #endif |
| 186 | |
| 187 | #if __GNUC__ |
| 188 | #define DISPATCH_INLINE static __inline__ |
| 189 | #else |
| 190 | #define DISPATCH_INLINE static inline |
| 191 | #endif |
| 192 | |
| 193 | #if __GNUC__ |
| 194 | #define DISPATCH_EXPECT(x, v) __builtin_expect((x), (v)) |
| 195 | #define dispatch_compiler_barrier() __asm__ __volatile__("" ::: "memory") |
| 196 | #else |
| 197 | #define DISPATCH_EXPECT(x, v) (x) |
| 198 | #define dispatch_compiler_barrier() do { } while (0) |
| 199 | #endif |
| 200 | |
| 201 | #if __has_attribute(not_tail_called) |
| 202 | #define DISPATCH_NOT_TAIL_CALLED __attribute__((__not_tail_called__)) |
| 203 | #else |
| 204 | #define DISPATCH_NOT_TAIL_CALLED |
| 205 | #endif |
| 206 | |
| 207 | #if __has_builtin(__builtin_assume) |
| 208 | #define DISPATCH_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr) |
| 209 | #else |
| 210 | #define DISPATCH_COMPILER_CAN_ASSUME(expr) ((void)(expr)) |
| 211 | #endif |
| 212 | |
| 213 | #if __has_attribute(noescape) |
| 214 | #define DISPATCH_NOESCAPE __attribute__((__noescape__)) |
| 215 | #else |
| 216 | #define DISPATCH_NOESCAPE |
| 217 | #endif |
| 218 | |
| 219 | #if __has_attribute(cold) |
| 220 | #define DISPATCH_COLD __attribute__((__cold__)) |
| 221 | #else |
| 222 | #define DISPATCH_COLD |
| 223 | #endif |
| 224 | |
| 225 | #if __has_attribute(no_sanitize) |
| 226 | #define DISPATCH_NO_UBSAN __attribute__((no_sanitize("undefined"))) |
| 227 | #else |
| 228 | #define DISPATCH_NO_UBSAN |
| 229 | #endif |
| 230 | |
| 231 | #if __has_feature(assume_nonnull) |
| 232 | #define DISPATCH_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") |
| 233 | #define DISPATCH_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") |
| 234 | #else |
| 235 | #define DISPATCH_ASSUME_NONNULL_BEGIN |
| 236 | #define DISPATCH_ASSUME_NONNULL_END |
| 237 | #endif |
| 238 | |
| 239 | #if __has_feature(bounds_attributes) |
| 240 | #define DISPATCH_ASSUME_ABI_SINGLE_BEGIN	_Pragma("clang abi_ptr_attr set(single)") |
| 241 | #define DISPATCH_ASSUME_ABI_SINGLE_END		_Pragma("clang abi_ptr_attr set(unsafe_indexable)") |
| 242 | #define DISPATCH_UNSAFE_INDEXABLE __attribute__((__unsafe_indexable__)) |
| 243 | #define DISPATCH_COUNTED_BY(X) __attribute__((__counted_by__(X))) |
| 244 | #define DISPATCH_SIZED_BY(X) __attribute__((__sized_by__(X))) |
| 245 | #else |
| 246 | #define DISPATCH_ASSUME_ABI_SINGLE_BEGIN |
| 247 | #define DISPATCH_ASSUME_ABI_SINGLE_END |
| 248 | #define DISPATCH_UNSAFE_INDEXABLE |
| 249 | #define DISPATCH_COUNTED_BY(X) |
| 250 | #define DISPATCH_SIZED_BY(X) |
| 251 | #endif |
| 252 | |
| 253 | #define DISPATCH_OSX_SUPPORTS_AT_LEAST(macos, ios, tvos, watchos, bridgeos, visionos) \ |
| 254 | 	 (	(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= macos) \ |
| 255 | 	||	(defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= ios) \ |
| 256 | 	||	(defined(__TV_OS_VERSION_MIN_REQUIRED) && __TV_OS_VERSION_MIN_REQUIRED >= tvos) \ |
| 257 | 	||	(defined(__WATCH_OS_VERSION_MIN_REQUIRED) && __WATCH_OS_VERSION_MIN_REQUIRED >= watchos) \ |
| 258 | 	||	(defined(__BRIDGE_OS_VERSION_MIN_REQUIRED) && __BRIDGE_OS_VERSION_MIN_REQUIRED >= bridgeos) \ |
| 259 | 	||	(defined(__VISION_OS_VERSION_MIN_REQUIRED) && __VISION_OS_VERSION_MIN_REQUIRED >= visionos) \ |
| 260 | 	) |
| 261 | |
| 262 | #if !__has_feature(nullability) |
| 263 | #ifndef _Nullable |
| 264 | #define _Nullable |
| 265 | #endif |
| 266 | #ifndef _Nonnull |
| 267 | #define _Nonnull |
| 268 | #endif |
| 269 | #ifndef _Null_unspecified |
| 270 | #define _Null_unspecified |
| 271 | #endif |
| 272 | #endif |
| 273 | |
| 274 | #ifndef DISPATCH_RETURNS_RETAINED_BLOCK |
| 275 | #if __has_attribute(ns_returns_retained) |
| 276 | #define DISPATCH_RETURNS_RETAINED_BLOCK __attribute__((__ns_returns_retained__)) |
| 277 | #else |
| 278 | #define DISPATCH_RETURNS_RETAINED_BLOCK |
| 279 | #endif |
| 280 | #endif |
| 281 | |
| 282 | #if __has_attribute(enum_extensibility) |
| 283 | #define __DISPATCH_ENUM_ATTR __attribute__((__enum_extensibility__(open))) |
| 284 | #define __DISPATCH_ENUM_ATTR_CLOSED __attribute__((__enum_extensibility__(closed))) |
| 285 | #else |
| 286 | #define __DISPATCH_ENUM_ATTR |
| 287 | #define __DISPATCH_ENUM_ATTR_CLOSED |
| 288 | #endif // __has_attribute(enum_extensibility) |
| 289 | |
| 290 | #if __has_attribute(flag_enum) |
| 291 | #define __DISPATCH_OPTIONS_ATTR __attribute__((__flag_enum__)) |
| 292 | #else |
| 293 | #define __DISPATCH_OPTIONS_ATTR |
| 294 | #endif // __has_attribute(flag_enum) |
| 295 | |
| 296 | |
| 297 | #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums) || \ |
| 298 | 		__has_extension(cxx_fixed_enum) || defined(_WIN32) |
| 299 | #define DISPATCH_ENUM(name, type, ...) \ |
| 300 | 		typedef enum : type { __VA_ARGS__ } __DISPATCH_ENUM_ATTR name##_t |
| 301 | #define DISPATCH_OPTIONS(name, type, ...) \ |
| 302 | 		typedef enum : type { __VA_ARGS__ } __DISPATCH_OPTIONS_ATTR __DISPATCH_ENUM_ATTR name##_t |
| 303 | #else |
| 304 | #define DISPATCH_ENUM(name, type, ...) \ |
| 305 | 		enum { __VA_ARGS__ } __DISPATCH_ENUM_ATTR; typedef type name##_t |
| 306 | #define DISPATCH_OPTIONS(name, type, ...) \ |
| 307 | 		enum { __VA_ARGS__ } __DISPATCH_OPTIONS_ATTR __DISPATCH_ENUM_ATTR; typedef type name##_t |
| 308 | #endif // __has_feature(objc_fixed_enum) ... |
| 309 | |
| 310 | |
| 311 | |
| 312 | #if __has_feature(enumerator_attributes) |
| 313 | #define DISPATCH_ENUM_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__) |
| 314 | #define DISPATCH_ENUM_SPI_AVAILABLE(...) API_UNAVAILABLE(__VA_ARGS__) |
| 315 | #define DISPATCH_ENUM_API_DEPRECATED(...) API_DEPRECATED(__VA_ARGS__) |
| 316 | #define DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT(...) \ |
| 317 | 		API_DEPRECATED_WITH_REPLACEMENT(__VA_ARGS__) |
| 318 | #else |
| 319 | #define DISPATCH_ENUM_API_AVAILABLE(...) |
| 320 | #define DISPATCH_ENUM_SPI_AVAILABLE(...) |
| 321 | #define DISPATCH_ENUM_API_DEPRECATED(...) |
| 322 | #define DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT(...) |
| 323 | #endif |
| 324 | |
| 325 | #ifdef __swift__ |
| 326 | #define DISPATCH_SWIFT3_OVERLAY 1 |
| 327 | #else // __swift__ |
| 328 | #define DISPATCH_SWIFT3_OVERLAY 0 |
| 329 | #endif // __swift__ |
| 330 | |
| 331 | #if __has_feature(attribute_availability_swift) |
| 332 | #define DISPATCH_SWIFT_UNAVAILABLE(_msg) \ |
| 333 | 		__attribute__((__availability__(swift, unavailable, message=_msg))) |
| 334 | #else |
| 335 | #define DISPATCH_SWIFT_UNAVAILABLE(_msg) |
| 336 | #endif |
| 337 | |
| 338 | #if DISPATCH_SWIFT3_OVERLAY |
| 339 | #define DISPATCH_SWIFT3_UNAVAILABLE(_msg) DISPATCH_SWIFT_UNAVAILABLE(_msg) |
| 340 | #else |
| 341 | #define DISPATCH_SWIFT3_UNAVAILABLE(_msg) |
| 342 | #endif |
| 343 | |
| 344 | #if __has_attribute(swift_private) |
| 345 | #define DISPATCH_REFINED_FOR_SWIFT __attribute__((__swift_private__)) |
| 346 | #else |
| 347 | #define DISPATCH_REFINED_FOR_SWIFT |
| 348 | #endif |
| 349 | |
| 350 | #if __has_attribute(swift_name) |
| 351 | #define DISPATCH_SWIFT_NAME(_name) __attribute__((__swift_name__(#_name))) |
| 352 | #else |
| 353 | #define DISPATCH_SWIFT_NAME(_name) |
| 354 | #endif |
| 355 | |
| 356 | #ifndef __cplusplus |
| 357 | #define DISPATCH_TRANSPARENT_UNION __attribute__((__transparent_union__)) |
| 358 | #else |
| 359 | #define DISPATCH_TRANSPARENT_UNION |
| 360 | #endif |
| 361 | |
| 362 | DISPATCH_ASSUME_ABI_SINGLE_BEGIN |
| 363 | |
| 364 | DISPATCH_SWIFT_UNAVAILABLE("Unavailable in Swift") |
| 365 | typedef void (*dispatch_function_t)(void *_Nullable); |
| 366 | |
| 367 | DISPATCH_ASSUME_ABI_SINGLE_END |
| 368 | |
| 369 | #endif |