]> git.saurik.com Git - apple/libdispatch.git/blob - src/swift/DispatchStubs.cc
libdispatch-703.1.4.tar.gz
[apple/libdispatch.git] / src / swift / DispatchStubs.cc
1 //===----------------------------------------------------------------------===//
2 //
3 // This source file is part of the Swift.org open source project
4 //
5 // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 // Licensed under Apache License v2.0 with Runtime Library Exception
7 //
8 // See http://swift.org/LICENSE.txt for license information
9 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include <dispatch/dispatch.h>
14 #include <stdio.h>
15
16 #define DISPATCH_RUNTIME_STDLIB_INTERFACE __attribute__((__visibility__("default")))
17
18 #if USE_OBJC
19 @protocol OS_dispatch_source;
20 @protocol OS_dispatch_source_mach_send;
21 @protocol OS_dispatch_source_mach_recv;
22 @protocol OS_dispatch_source_memorypressure;
23 @protocol OS_dispatch_source_proc;
24 @protocol OS_dispatch_source_read;
25 @protocol OS_dispatch_source_signal;
26 @protocol OS_dispatch_source_timer;
27 @protocol OS_dispatch_source_data_add;
28 @protocol OS_dispatch_source_data_or;
29 @protocol OS_dispatch_source_vnode;
30 @protocol OS_dispatch_source_write;
31
32 // #include <dispatch/private.h>
33 __attribute__((constructor))
34 static void _dispatch_overlay_constructor() {
35 Class source = objc_lookUpClass("OS_dispatch_source");
36 if (source) {
37 class_addProtocol(source, @protocol(OS_dispatch_source));
38 class_addProtocol(source, @protocol(OS_dispatch_source_mach_send));
39 class_addProtocol(source, @protocol(OS_dispatch_source_mach_recv));
40 class_addProtocol(source, @protocol(OS_dispatch_source_memorypressure));
41 class_addProtocol(source, @protocol(OS_dispatch_source_proc));
42 class_addProtocol(source, @protocol(OS_dispatch_source_read));
43 class_addProtocol(source, @protocol(OS_dispatch_source_signal));
44 class_addProtocol(source, @protocol(OS_dispatch_source_timer));
45 class_addProtocol(source, @protocol(OS_dispatch_source_data_add));
46 class_addProtocol(source, @protocol(OS_dispatch_source_data_or));
47 class_addProtocol(source, @protocol(OS_dispatch_source_vnode));
48 class_addProtocol(source, @protocol(OS_dispatch_source_write));
49 }
50 }
51
52 #endif /* USE_OBJC */
53
54 #if 0 /* FIXME -- adding directory to include path may need build-script plumbing to do properly... */
55 #include "swift/Runtime/Config.h"
56 #else
57 #define SWIFT_CC(x) /* FIXME!! */
58 #endif
59
60 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
61 extern "C" dispatch_queue_attr_t
62 _swift_dispatch_queue_concurrent(void) {
63 return DISPATCH_QUEUE_CONCURRENT;
64 }
65
66 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
67 extern "C" void
68 _swift_dispatch_apply_current(size_t iterations, __attribute__((__noescape__)) void (^block)(size_t)) {
69 dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, block);
70 }
71
72 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
73 extern "C" dispatch_queue_t
74 _swift_dispatch_get_main_queue(void) {
75 return dispatch_get_main_queue();
76 }
77
78 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
79 extern "C" dispatch_data_t
80 _swift_dispatch_data_empty(void) {
81 return dispatch_data_empty;
82 }
83
84 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
85 extern "C" dispatch_block_t
86 _swift_dispatch_data_destructor_default(void) {
87 return DISPATCH_DATA_DESTRUCTOR_DEFAULT;
88 }
89
90 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
91 extern "C" dispatch_block_t
92 _swift_dispatch_data_destructor_free(void) {
93 return _dispatch_data_destructor_free;
94 }
95
96 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
97 extern "C" dispatch_block_t
98 _swift_dispatch_data_destructor_munmap(void) {
99 return _dispatch_data_destructor_munmap;
100 }
101
102 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
103 extern "C" dispatch_block_t
104 _swift_dispatch_block_create_with_qos_class(dispatch_block_flags_t flags, dispatch_qos_class_t qos, int relative_priority, dispatch_block_t block) {
105 return dispatch_block_create_with_qos_class(flags, qos, relative_priority, block);
106 }
107
108 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
109 extern "C" dispatch_block_t
110 _swift_dispatch_block_create_noescape(dispatch_block_flags_t flags, dispatch_block_t block) {
111 return dispatch_block_create(flags, block);
112 }
113
114 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
115 extern "C" void
116 _swift_dispatch_block_cancel(dispatch_block_t block) {
117 dispatch_block_cancel(block);
118 }
119
120 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
121 extern "C" long
122 _swift_dispatch_block_wait(dispatch_block_t block, dispatch_time_t timeout) {
123 return dispatch_block_wait(block, timeout);
124 }
125
126 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
127 extern "C" void
128 _swift_dispatch_block_notify(dispatch_block_t block, dispatch_queue_t queue, dispatch_block_t notification_block) {
129 dispatch_block_notify(block, queue, notification_block);
130 }
131
132 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
133 extern "C" long
134 _swift_dispatch_block_testcancel(dispatch_block_t block) {
135 return dispatch_block_testcancel(block);
136 }
137
138 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
139 extern "C" bool
140 _swift_dispatch_data_apply(dispatch_data_t data, bool (^applier)(dispatch_data_t, size_t, const void *, size_t)) {
141 return dispatch_data_apply(data, applier);
142 }
143
144 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
145 extern "C" void
146 _swift_dispatch_async(dispatch_queue_t queue, dispatch_block_t block) {
147 dispatch_async(queue, block);
148 }
149
150 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
151 extern "C" void
152 _swift_dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block) {
153 dispatch_group_async(group, queue, block);
154 }
155
156 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
157 extern "C" void
158 _swift_dispatch_sync(dispatch_queue_t queue, dispatch_block_t block) {
159 dispatch_sync(queue, block);
160 }
161
162 SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
163 extern "C" void
164 _swift_dispatch_release(dispatch_object_t obj) {
165 dispatch_release(obj);
166 }
167
168 // DISPATCH_RUNTIME_STDLIB_INTERFACE
169 // extern "C" dispatch_queue_t
170 // _swift_apply_current_root_queue() {
171 // return DISPATCH_APPLY_CURRENT_ROOT_QUEUE;
172 // }
173
174 #define SOURCE(t) \
175 SWIFT_CC(swift) \
176 DISPATCH_RUNTIME_STDLIB_INTERFACE extern "C" dispatch_source_type_t \
177 _swift_dispatch_source_type_##t(void) { \
178 return DISPATCH_SOURCE_TYPE_##t; \
179 }
180
181 SOURCE(DATA_ADD)
182 SOURCE(DATA_OR)
183 #if HAVE_MACH
184 SOURCE(MACH_SEND)
185 SOURCE(MACH_RECV)
186 SOURCE(MEMORYPRESSURE)
187 #endif
188 #ifndef __linux__
189 SOURCE(PROC)
190 #endif
191 SOURCE(READ)
192 SOURCE(SIGNAL)
193 SOURCE(TIMER)
194 #ifndef __linux__
195 SOURCE(VNODE)
196 #endif
197 SOURCE(WRITE)
198
199 // See comment in CFFuntime.c explaining why objc_retainAutoreleasedReturnValue is needed.
200 extern "C" void swift_release(void *);
201 extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) {
202 if (obj) {
203 swift_release(obj);
204 return obj;
205 }
206 else return NULL;
207 }