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
));
55 // Replicate the SWIFT_CC(swift) calling convention macro from
56 // swift/include/swift/Runtime/Config.h because it is
57 // quite awkward to include Config.h and its recursive includes
58 // in dispatch. This define must be manually kept in synch
59 #define SWIFT_CC(CC) SWIFT_CC_##CC
60 #if SWIFT_USE_SWIFTCALL
61 #define SWIFT_CC_swift __attribute__((swiftcall))
63 #define SWIFT_CC_swift
66 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
67 extern "C" dispatch_queue_attr_t
68 _swift_dispatch_queue_concurrent(void) {
69 return DISPATCH_QUEUE_CONCURRENT
;
72 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
74 _swift_dispatch_apply_current(size_t iterations
, __attribute__((__noescape__
)) void (^block
)(size_t)) {
75 dispatch_apply(iterations
, (dispatch_queue_t _Nonnull
)0, block
);
78 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
79 extern "C" dispatch_queue_t
80 _swift_dispatch_get_main_queue(void) {
81 return dispatch_get_main_queue();
84 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
85 extern "C" dispatch_data_t
86 _swift_dispatch_data_empty(void) {
87 return dispatch_data_empty
;
90 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
91 extern "C" dispatch_block_t
92 _swift_dispatch_data_destructor_default(void) {
93 return DISPATCH_DATA_DESTRUCTOR_DEFAULT
;
96 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
97 extern "C" dispatch_block_t
98 _swift_dispatch_data_destructor_free(void) {
99 return _dispatch_data_destructor_free
;
102 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
103 extern "C" dispatch_block_t
104 _swift_dispatch_data_destructor_munmap(void) {
105 return _dispatch_data_destructor_munmap
;
108 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
109 extern "C" dispatch_block_t
110 _swift_dispatch_block_create_with_qos_class(dispatch_block_flags_t flags
, dispatch_qos_class_t qos
, int relative_priority
, dispatch_block_t block
) {
111 return dispatch_block_create_with_qos_class(flags
, qos
, relative_priority
, block
);
114 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
115 extern "C" dispatch_block_t
116 _swift_dispatch_block_create_noescape(dispatch_block_flags_t flags
, dispatch_block_t block
) {
117 return dispatch_block_create(flags
, block
);
120 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
122 _swift_dispatch_block_cancel(dispatch_block_t block
) {
123 dispatch_block_cancel(block
);
126 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
128 _swift_dispatch_block_wait(dispatch_block_t block
, dispatch_time_t timeout
) {
129 return dispatch_block_wait(block
, timeout
);
132 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
134 _swift_dispatch_block_notify(dispatch_block_t block
, dispatch_queue_t queue
, dispatch_block_t notification_block
) {
135 dispatch_block_notify(block
, queue
, notification_block
);
138 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
140 _swift_dispatch_block_testcancel(dispatch_block_t block
) {
141 return dispatch_block_testcancel(block
);
144 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
146 _swift_dispatch_data_apply(dispatch_data_t data
, bool (^applier
)(dispatch_data_t
, size_t, const void *, size_t)) {
147 return dispatch_data_apply(data
, applier
);
150 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
152 _swift_dispatch_async(dispatch_queue_t queue
, dispatch_block_t block
) {
153 dispatch_async(queue
, block
);
156 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
158 _swift_dispatch_group_async(dispatch_group_t group
, dispatch_queue_t queue
, dispatch_block_t block
) {
159 dispatch_group_async(group
, queue
, block
);
162 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
164 _swift_dispatch_sync(dispatch_queue_t queue
, dispatch_block_t block
) {
165 dispatch_sync(queue
, block
);
168 SWIFT_CC(swift
) DISPATCH_RUNTIME_STDLIB_INTERFACE
170 _swift_dispatch_release(dispatch_object_t obj
) {
171 dispatch_release(obj
);
174 // DISPATCH_RUNTIME_STDLIB_INTERFACE
175 // extern "C" dispatch_queue_t
176 // _swift_apply_current_root_queue() {
177 // return DISPATCH_APPLY_CURRENT_ROOT_QUEUE;
182 DISPATCH_RUNTIME_STDLIB_INTERFACE extern "C" dispatch_source_type_t \
183 _swift_dispatch_source_type_##t(void) { \
184 return DISPATCH_SOURCE_TYPE_##t; \
192 SOURCE(MEMORYPRESSURE
)
205 // See comment in CFFuntime.c explaining why objc_retainAutoreleasedReturnValue is needed.
206 extern "C" void swift_release(void *);
207 extern "C" void * objc_retainAutoreleasedReturnValue(void *obj
) {