]>
git.saurik.com Git - apple/libdispatch.git/blob - dispatch/base.h
2 * Copyright (c) 2008-2012 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@
21 #ifndef __DISPATCH_BASE__
22 #define __DISPATCH_BASE__
24 #ifndef __DISPATCH_INDIRECT__
25 #error "Please #include <dispatch/dispatch.h> instead of this file directly."
29 #define __has_builtin(x) 0
32 #define __has_include(x) 0
35 #define __has_feature(x) 0
37 #ifndef __has_attribute
38 #define __has_attribute(x) 0
40 #ifndef __has_extension
41 #define __has_extension(x) 0
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
58 #define DISPATCH_NONNULL_ALL __attribute__((__nonnull__))
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)))
70 #define DISPATCH_NORETURN
72 #define DISPATCH_NOTHROW
74 #define DISPATCH_NONNULL1
76 #define DISPATCH_NONNULL2
78 #define DISPATCH_NONNULL3
80 #define DISPATCH_NONNULL4
82 #define DISPATCH_NONNULL5
84 #define DISPATCH_NONNULL6
86 #define DISPATCH_NONNULL7
88 #define DISPATCH_NONNULL_ALL
90 #define DISPATCH_SENTINEL
94 #define DISPATCH_CONST
96 #define DISPATCH_WARN_RESULT
98 #define DISPATCH_MALLOC
100 #define DISPATCH_ALWAYS_INLINE
102 #define DISPATCH_UNAVAILABLE
104 #define DISPATCH_UNAVAILABLE_MSG(msg)
108 #define DISPATCH_LINUX_UNAVAILABLE() \
109 DISPATCH_UNAVAILABLE_MSG( \
110 "This interface is unavailable on linux systems")
112 #define DISPATCH_LINUX_UNAVAILABLE()
115 #ifndef DISPATCH_ALIAS_V2
117 #define DISPATCH_ALIAS_V2(sym) __asm__("_" #sym "$V2")
119 #define DISPATCH_ALIAS_V2(sym)
123 #if TARGET_OS_WIN32 && defined(__DISPATCH_BUILDING_DISPATCH__) && \
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)
133 #define DISPATCH_EXPORT extern __attribute__((visibility("default")))
135 #define DISPATCH_EXPORT extern
139 #define DISPATCH_INLINE static __inline__
141 #define DISPATCH_INLINE static inline
145 #define DISPATCH_EXPECT(x, v) __builtin_expect((x), (v))
146 #define dispatch_compiler_barrier() __asm__ __volatile__("" ::: "memory")
148 #define DISPATCH_EXPECT(x, v) (x)
149 #define dispatch_compiler_barrier() do { } while (0)
152 #if __has_attribute(not_tail_called)
153 #define DISPATCH_NOT_TAIL_CALLED __attribute__((__not_tail_called__))
155 #define DISPATCH_NOT_TAIL_CALLED
158 #if __has_builtin(__builtin_assume)
159 #define DISPATCH_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr)
161 #define DISPATCH_COMPILER_CAN_ASSUME(expr) ((void)(expr))
164 #if __has_attribute(noescape)
165 #define DISPATCH_NOESCAPE __attribute__((__noescape__))
167 #define DISPATCH_NOESCAPE
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")
174 #define DISPATCH_ASSUME_NONNULL_BEGIN
175 #define DISPATCH_ASSUME_NONNULL_END
178 #if !__has_feature(nullability)
185 #ifndef _Null_unspecified
186 #define _Null_unspecified
190 #ifndef DISPATCH_RETURNS_RETAINED_BLOCK
191 #if __has_attribute(ns_returns_retained)
192 #define DISPATCH_RETURNS_RETAINED_BLOCK __attribute__((__ns_returns_retained__))
194 #define DISPATCH_RETURNS_RETAINED_BLOCK
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
202 #define DISPATCH_ENUM(name, type, ...) \
203 enum { __VA_ARGS__ }; typedef type name##_t
206 #if __has_feature(enumerator_attributes)
207 #define DISPATCH_ENUM_AVAILABLE_STARTING __OSX_AVAILABLE_STARTING
208 #define DISPATCH_ENUM_AVAILABLE(os, version) __##os##_AVAILABLE(version)
210 #define DISPATCH_ENUM_AVAILABLE_STARTING(...)
211 #define DISPATCH_ENUM_AVAILABLE(...)
214 #if defined(SWIFT_SDK_OVERLAY_DISPATCH_EPOCH) && \
215 SWIFT_SDK_OVERLAY_DISPATCH_EPOCH >= 2
216 #define DISPATCH_SWIFT3_OVERLAY 1
218 #define DISPATCH_SWIFT3_OVERLAY 0
219 #endif // SWIFT_SDK_OVERLAY_DISPATCH_EPOCH >= 2
221 #if __has_feature(attribute_availability_swift)
222 #define DISPATCH_SWIFT_UNAVAILABLE(_msg) \
223 __attribute__((__availability__(swift, unavailable, message=_msg)))
225 #define DISPATCH_SWIFT_UNAVAILABLE(_msg)
228 #if DISPATCH_SWIFT3_OVERLAY
229 #define DISPATCH_SWIFT3_UNAVAILABLE(_msg) DISPATCH_SWIFT_UNAVAILABLE(_msg)
231 #define DISPATCH_SWIFT3_UNAVAILABLE(_msg)
234 #if __has_attribute(swift_private)
235 #define DISPATCH_REFINED_FOR_SWIFT __attribute__((__swift_private__))
237 #define DISPATCH_REFINED_FOR_SWIFT
240 #if __has_attribute(swift_name)
241 #define DISPATCH_SWIFT_NAME(_name) __attribute__((__swift_name__(#_name)))
243 #define DISPATCH_SWIFT_NAME(_name)
246 typedef void (*dispatch_function_t
)(void *_Nullable
);