10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ import CDispatch
14
+
13
15
public struct DispatchWorkItemFlags : OptionSet , RawRepresentable {
14
16
public let rawValue : UInt
15
17
public init ( rawValue: UInt ) { self . rawValue = rawValue }
@@ -38,14 +40,14 @@ public class DispatchWorkItem {
38
40
internal var _group : DispatchGroup ?
39
41
40
42
public init ( group: DispatchGroup ? = nil , qos: DispatchQoS = . unspecified, flags: DispatchWorkItemFlags = [ ] , block: @convention ( block) ( ) -> ( ) ) {
41
- _block = _swift_dispatch_block_create_with_qos_class ( __dispatch_block_flags_t ( flags. rawValue) ,
42
- qos. qosClass. rawValue, Int32 ( qos. relativePriority) , block)
43
+ _block = dispatch_block_create_with_qos_class ( dispatch_block_flags_t ( flags. rawValue) ,
44
+ qos. qosClass. rawValue. rawValue , Int32 ( qos. relativePriority) , block)
43
45
}
44
46
45
47
// Used by DispatchQueue.synchronously<T> to provide a @noescape path through
46
48
// dispatch_block_t, as we know the lifetime of the block in question.
47
49
internal init ( flags: DispatchWorkItemFlags = [ ] , noescapeBlock: @noescape ( ) -> ( ) ) {
48
- _block = _swift_dispatch_block_create_noescape ( __dispatch_block_flags_t ( flags. rawValue) , noescapeBlock)
50
+ _block = _swift_dispatch_block_create_noescape ( dispatch_block_flags_t ( flags. rawValue) , noescapeBlock)
49
51
}
50
52
51
53
public func perform( ) {
@@ -57,36 +59,36 @@ public class DispatchWorkItem {
57
59
}
58
60
59
61
public func wait( ) {
60
- _ = _swift_dispatch_block_wait ( _block, DispatchTime . distantFuture. rawValue)
62
+ _ = dispatch_block_wait ( _block, DispatchTime . distantFuture. rawValue)
61
63
}
62
64
63
65
public func wait( timeout: DispatchTime ) -> DispatchTimeoutResult {
64
- return _swift_dispatch_block_wait ( _block, timeout. rawValue) == 0 ? . Success : . TimedOut
66
+ return dispatch_block_wait ( _block, timeout. rawValue) == 0 ? . Success : . TimedOut
65
67
}
66
68
67
69
public func wait( wallTimeout: DispatchWallTime ) -> DispatchTimeoutResult {
68
- return _swift_dispatch_block_wait ( _block, wallTimeout. rawValue) == 0 ? . Success : . TimedOut
70
+ return dispatch_block_wait ( _block, wallTimeout. rawValue) == 0 ? . Success : . TimedOut
69
71
}
70
72
71
73
public func notify( qos: DispatchQoS = . unspecified, flags: DispatchWorkItemFlags = [ ] , queue: DispatchQueue , execute: @convention ( block) ( ) -> Void ) {
72
74
if qos != . unspecified || !flags. isEmpty {
73
75
let item = DispatchWorkItem ( qos: qos, flags: flags, block: execute)
74
- _swift_dispatch_block_notify ( _block, queue, item. _block)
76
+ dispatch_block_notify ( _block, queue. __wrapped , item. _block)
75
77
} else {
76
- _swift_dispatch_block_notify ( _block, queue, execute)
78
+ dispatch_block_notify ( _block, queue. __wrapped , execute)
77
79
}
78
80
}
79
81
80
82
public func notify( queue: DispatchQueue , execute: DispatchWorkItem ) {
81
- _swift_dispatch_block_notify ( _block, queue, execute. _block)
83
+ dispatch_block_notify ( _block, queue. __wrapped , execute. _block)
82
84
}
83
85
84
86
public func cancel( ) {
85
- _swift_dispatch_block_cancel ( _block)
87
+ dispatch_block_cancel ( _block)
86
88
}
87
89
88
90
public var isCancelled : Bool {
89
- return _swift_dispatch_block_testcancel ( _block) != 0
91
+ return dispatch_block_testcancel ( _block) != 0
90
92
}
91
93
}
92
94
@@ -96,7 +98,7 @@ public extension DispatchWorkItem {
96
98
public func wait( timeout: DispatchWallTime ) -> Int {
97
99
switch wait ( wallTimeout: timeout) {
98
100
case . Success: return 0
99
- case . TimedOut: return Int ( KERN_OPERATION_TIMED_OUT)
101
+ case . TimedOut: return DispatchTimeoutResult . KERN_OPERATION_TIMED_OUT
100
102
}
101
103
}
102
104
}
@@ -106,26 +108,7 @@ public extension DispatchWorkItem {
106
108
/// C blocks and Swift closures, which interferes with dispatch APIs that depend
107
109
/// on the referential identity of a block. Particularly, dispatch_block_create.
108
110
internal typealias _DispatchBlock = @convention ( block) ( ) -> Void
109
-
110
- /// APINotes also removes the old dispatch_block_t typedef from the Dispatch module
111
- /// completely. In doing so it causes the dispatch_block_* API to lose their
112
- /// @convention(block) attributes. As such, all of the entry points are shimmed
113
- //// through Dispatch.mm with _DispatchBlock types.
114
- @_silgen_name ( " _swift_dispatch_block_create_with_qos_class " )
115
- internal func _swift_dispatch_block_create_with_qos_class( _ flags: __dispatch_block_flags_t , _ qos: qos_class_t , _ relativePriority: Int32 , _ block: _DispatchBlock ) -> _DispatchBlock
111
+ internal typealias dispatch_block_t = @convention ( block) ( ) -> Void
116
112
117
113
@_silgen_name ( " _swift_dispatch_block_create_noescape " )
118
- internal func _swift_dispatch_block_create_noescape( _ flags: __dispatch_block_flags_t , _ block: @noescape ( ) -> ( ) ) -> _DispatchBlock
119
-
120
- @_silgen_name ( " _swift_dispatch_block_wait " )
121
- internal func _swift_dispatch_block_wait( _ block: _DispatchBlock , _ timeout: UInt64 ) -> Int
122
-
123
- @_silgen_name ( " _swift_dispatch_block_notify " )
124
- internal func _swift_dispatch_block_notify( _ block: _DispatchBlock , _ queue: DispatchQueue , _ notifier: _DispatchBlock )
125
-
126
- @_silgen_name( " _swift_dispatch_block_cancel" )
127
- internal func _swift_dispatch_block_cancel(_ block: _DispatchBlock)
128
-
129
- @_silgen_name( " _swift_dispatch_block_testcancel" )
130
- internal func _swift_dispatch_block_testcancel(_ block: _DispatchBlock) -> Int
131
-
114
+ internal func _swift_dispatch_block_create_noescape( _ flags: dispatch_block_flags_t , _ block: @noescape ( ) -> ( ) ) -> _DispatchBlock
0 commit comments