]> git.saurik.com Git - apple/libdispatch.git/blob - dispatch/base.h
libdispatch-442.1.4.tar.gz
[apple/libdispatch.git] / dispatch / base.h
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 #if __GNUC__
29 #define DISPATCH_NORETURN __attribute__((__noreturn__))
30 #define DISPATCH_NOTHROW __attribute__((__nothrow__))
31 #define DISPATCH_NONNULL1 __attribute__((__nonnull__(1)))
32 #define DISPATCH_NONNULL2 __attribute__((__nonnull__(2)))
33 #define DISPATCH_NONNULL3 __attribute__((__nonnull__(3)))
34 #define DISPATCH_NONNULL4 __attribute__((__nonnull__(4)))
35 #define DISPATCH_NONNULL5 __attribute__((__nonnull__(5)))
36 #define DISPATCH_NONNULL6 __attribute__((__nonnull__(6)))
37 #define DISPATCH_NONNULL7 __attribute__((__nonnull__(7)))
38 #if __clang__ && __clang_major__ < 3
39 // rdar://problem/6857843
40 #define DISPATCH_NONNULL_ALL
41 #else
42 #define DISPATCH_NONNULL_ALL __attribute__((__nonnull__))
43 #endif
44 #define DISPATCH_SENTINEL __attribute__((__sentinel__))
45 #define DISPATCH_PURE __attribute__((__pure__))
46 #define DISPATCH_CONST __attribute__((__const__))
47 #define DISPATCH_WARN_RESULT __attribute__((__warn_unused_result__))
48 #define DISPATCH_MALLOC __attribute__((__malloc__))
49 #define DISPATCH_ALWAYS_INLINE __attribute__((__always_inline__))
50 #define DISPATCH_UNAVAILABLE __attribute__((__unavailable__))
51 #else
52 /*! @parseOnly */
53 #define DISPATCH_NORETURN
54 /*! @parseOnly */
55 #define DISPATCH_NOTHROW
56 /*! @parseOnly */
57 #define DISPATCH_NONNULL1
58 /*! @parseOnly */
59 #define DISPATCH_NONNULL2
60 /*! @parseOnly */
61 #define DISPATCH_NONNULL3
62 /*! @parseOnly */
63 #define DISPATCH_NONNULL4
64 /*! @parseOnly */
65 #define DISPATCH_NONNULL5
66 /*! @parseOnly */
67 #define DISPATCH_NONNULL6
68 /*! @parseOnly */
69 #define DISPATCH_NONNULL7
70 /*! @parseOnly */
71 #define DISPATCH_NONNULL_ALL
72 /*! @parseOnly */
73 #define DISPATCH_SENTINEL
74 /*! @parseOnly */
75 #define DISPATCH_PURE
76 /*! @parseOnly */
77 #define DISPATCH_CONST
78 /*! @parseOnly */
79 #define DISPATCH_WARN_RESULT
80 /*! @parseOnly */
81 #define DISPATCH_MALLOC
82 /*! @parseOnly */
83 #define DISPATCH_ALWAYS_INLINE
84 /*! @parseOnly */
85 #define DISPATCH_UNAVAILABLE
86 #endif
87
88 #if TARGET_OS_WIN32 && defined(__DISPATCH_BUILDING_DISPATCH__) && \
89 defined(__cplusplus)
90 #define DISPATCH_EXPORT extern "C" extern __declspec(dllexport)
91 #elif TARGET_OS_WIN32 && defined(__DISPATCH_BUILDING_DISPATCH__)
92 #define DISPATCH_EXPORT extern __declspec(dllexport)
93 #elif TARGET_OS_WIN32 && defined(__cplusplus)
94 #define DISPATCH_EXPORT extern "C" extern __declspec(dllimport)
95 #elif TARGET_OS_WIN32
96 #define DISPATCH_EXPORT extern __declspec(dllimport)
97 #elif __GNUC__
98 #define DISPATCH_EXPORT extern __attribute__((visibility("default")))
99 #else
100 #define DISPATCH_EXPORT extern
101 #endif
102
103 #if __GNUC__
104 #define DISPATCH_INLINE static __inline__
105 #else
106 #define DISPATCH_INLINE static inline
107 #endif
108
109 #if __GNUC__
110 #define DISPATCH_EXPECT(x, v) __builtin_expect((x), (v))
111 #else
112 #define DISPATCH_EXPECT(x, v) (x)
113 #endif
114
115 #ifndef DISPATCH_RETURNS_RETAINED_BLOCK
116 #if defined(__has_attribute)
117 #if __has_attribute(ns_returns_retained)
118 #define DISPATCH_RETURNS_RETAINED_BLOCK __attribute__((__ns_returns_retained__))
119 #else
120 #define DISPATCH_RETURNS_RETAINED_BLOCK
121 #endif
122 #else
123 #define DISPATCH_RETURNS_RETAINED_BLOCK
124 #endif
125 #endif
126
127 #if defined(__has_feature) && defined(__has_extension)
128 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
129 #define DISPATCH_ENUM(name, type, ...) \
130 typedef enum : type { __VA_ARGS__ } name##_t
131 #else
132 #define DISPATCH_ENUM(name, type, ...) \
133 enum { __VA_ARGS__ }; typedef type name##_t
134 #endif
135 #if __has_feature(enumerator_attributes)
136 #define DISPATCH_ENUM_AVAILABLE_STARTING __OSX_AVAILABLE_STARTING
137 #else
138 #define DISPATCH_ENUM_AVAILABLE_STARTING(...)
139 #endif
140 #else
141 #define DISPATCH_ENUM(name, type, ...) \
142 enum { __VA_ARGS__ }; typedef type name##_t
143 #define DISPATCH_ENUM_AVAILABLE_STARTING(...)
144 #endif
145
146 typedef void (*dispatch_function_t)(void *);
147
148 #endif