Skip to content

Commit 5f19a23

Browse files
authored
Tweak _SwiftDispatchOverlayShims for use by swift-corelibs-libdispatch. (#14805)
(cherry picked from commit 6a1161b)
1 parent c60fae4 commit 5f19a23

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

stdlib/public/SDK/Dispatch/Queue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public extension DispatchQueue {
112112
}
113113

114114
public class func concurrentPerform(iterations: Int, execute work: (Int) -> Void) {
115-
_swift_dispatch_apply_current(UInt32(iterations), work)
115+
_swift_dispatch_apply_current(iterations, work)
116116
}
117117

118118
public class var main: DispatchQueue {

stdlib/public/SwiftShims/DispatchOverlayShims.h

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
//
13+
// Note that this file is used by both swift-corelibs-libdispatch and the
14+
// Dispatch overlay for Darwin in swift/stdlib/public/SDK/Dispatch/.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
1218

1319
#ifndef SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H
1420
#define SWIFT_STDLIB_SHIMS_DISPATCHSHIMS_H
1521

16-
@import Dispatch;
22+
#include <dispatch/dispatch.h>
1723

24+
#ifdef __OBJC__
1825
#define SWIFT_DISPATCH_RETURNS_RETAINED __attribute__((__ns_returns_retained__))
26+
#else
27+
#define SWIFT_DISPATCH_RETURNS_RETAINED
28+
#endif
29+
1930
#define SWIFT_DISPATCH_NOESCAPE __attribute__((__noescape__))
2031

2132
#pragma clang assume_nonnull begin
@@ -25,7 +36,12 @@ namespace swift { extern "C" {
2536
#endif
2637

2738
typedef void (^__swift_shims_dispatch_block_t)(void);
39+
40+
#ifdef __OBJC__
2841
typedef id __swift_shims_dispatch_data_t;
42+
#else
43+
typedef void *__swift_shims_dispatch_data_t;
44+
#endif
2945

3046

3147
static inline dispatch_queue_attr_t
@@ -66,21 +82,24 @@ _swift_dispatch_data_destructor_munmap(void) {
6682
SWIFT_DISPATCH_SOURCE_TYPE(DATA_ADD)
6783
SWIFT_DISPATCH_SOURCE_TYPE(DATA_OR)
6884
SWIFT_DISPATCH_SOURCE_TYPE(DATA_REPLACE)
85+
SWIFT_DISPATCH_SOURCE_TYPE(READ)
86+
SWIFT_DISPATCH_SOURCE_TYPE(SIGNAL)
87+
SWIFT_DISPATCH_SOURCE_TYPE(TIMER)
88+
SWIFT_DISPATCH_SOURCE_TYPE(WRITE)
89+
90+
#if __APPLE__
6991
SWIFT_DISPATCH_SOURCE_TYPE(MACH_SEND)
7092
SWIFT_DISPATCH_SOURCE_TYPE(MACH_RECV)
7193
SWIFT_DISPATCH_SOURCE_TYPE(MEMORYPRESSURE)
7294
SWIFT_DISPATCH_SOURCE_TYPE(PROC)
73-
SWIFT_DISPATCH_SOURCE_TYPE(READ)
74-
SWIFT_DISPATCH_SOURCE_TYPE(SIGNAL)
75-
SWIFT_DISPATCH_SOURCE_TYPE(TIMER)
7695
SWIFT_DISPATCH_SOURCE_TYPE(VNODE)
77-
SWIFT_DISPATCH_SOURCE_TYPE(WRITE)
96+
#endif
7897

7998

8099
static inline __swift_shims_dispatch_block_t
81100
_swift_dispatch_block_create_with_qos_class(
82101
dispatch_block_flags_t flags,
83-
qos_class_t qos,
102+
dispatch_qos_class_t qos,
84103
int relative_priority,
85104
__swift_shims_dispatch_block_t _Nonnull block) {
86105
return dispatch_block_create_with_qos_class(
@@ -158,7 +177,7 @@ static inline void _swift_dispatch_after(
158177

159178

160179
static inline void _swift_dispatch_apply_current(
161-
unsigned int iterations,
180+
size_t iterations,
162181
void SWIFT_DISPATCH_NOESCAPE (^block)(long)) {
163182
dispatch_apply(iterations, (dispatch_queue_t _Nonnull)0, ^(size_t i){
164183
block((long)i);
@@ -204,6 +223,18 @@ static inline void _swift_dispatch_source_set_registration_handler(
204223
dispatch_source_set_registration_handler(source, block);
205224
}
206225

226+
#if defined(__ANDROID__)
227+
extern void _dispatch_install_thread_detach_callback(dispatch_function_t cb);
228+
#endif
229+
230+
static inline void _swift_dispatch_retain(dispatch_object_t object) {
231+
dispatch_retain(object);
232+
}
233+
234+
static inline void _swift_dispatch_release(dispatch_object_t object) {
235+
dispatch_release(object);
236+
}
237+
207238
#ifdef __cplusplus
208239
}} // extern "C", namespace swift
209240
#endif

0 commit comments

Comments
 (0)