1 //===----------------------------------------------------------------------===//
3 // This source file is part of the Swift.org open source project
5 // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6 // Licensed under Apache License v2.0 with Runtime Library Exception
8 // See http://swift.org/LICENSE.txt for license information
9 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11 //===----------------------------------------------------------------------===//
13 #include <dispatch/dispatch.h>
16 #define DISPATCH_RUNTIME_STDLIB_INTERFACE __attribute__((__visibility__("default")))
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
;
32 // #include <dispatch/private.h>
33 __attribute__((constructor
))
34 static void _dispatch_overlay_constructor() {
35 Class source
= objc_lookUpClass("OS_dispatch_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
));
54 #if 0 /* FIXME -- adding directory to include path may need build-script plumbing to do properly... */
55 #include "swift/Runtime/Config.h"
57 #define SWIFT_CC(x) /* FIXME!! */
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
;
66 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
68 _swift_dispatch_apply_current(size_t iterations
, __attribute__((__noescape__
)) void (^block
)(size_t)) {
69 dispatch_apply(iterations
, (dispatch_queue_t _Nonnull
)0, block
);
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();
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
;
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
;
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
;
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
;
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
);
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
);
114 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
116 _swift_dispatch_block_cancel(dispatch_block_t block
) {
117 dispatch_block_cancel(block
);
120 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
122 _swift_dispatch_block_wait(dispatch_block_t block
, dispatch_time_t timeout
) {
123 return dispatch_block_wait(block
, timeout
);
126 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
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
);
132 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
134 _swift_dispatch_block_testcancel(dispatch_block_t block
) {
135 return dispatch_block_testcancel(block
);
138 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
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
);
144 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
146 _swift_dispatch_async(dispatch_queue_t queue
, dispatch_block_t block
) {
147 dispatch_async(queue
, block
);
150 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
152 _swift_dispatch_group_async(dispatch_group_t group
, dispatch_queue_t queue
, dispatch_block_t block
) {
153 dispatch_group_async(group
, queue
, block
);
156 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
158 _swift_dispatch_sync(dispatch_queue_t queue
, dispatch_block_t block
) {
159 dispatch_sync(queue
, block
);
162 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
164 _swift_dispatch_release(dispatch_object_t obj
) {
165 dispatch_release(obj
);
168 // DISPATCH_RUNTIME_STDLIB_INTERFACE
169 // extern "C" dispatch_queue_t
170 // _swift_apply_current_root_queue() {
171 // return DISPATCH_APPLY_CURRENT_ROOT_QUEUE;
176 DISPATCH_RUNTIME_STDLIB_INTERFACE extern "C" dispatch_source_type_t \
177 _swift_dispatch_source_type_##t(void) { \
178 return DISPATCH_SOURCE_TYPE_##t; \
186 SOURCE(MEMORYPRESSURE
)
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
) {