@@ -6,87 +6,9 @@ public public enum DispatchPredicate {
66 case notOnQueue( DispatchQueue )
77}
88
9- /*__external func dispatch_assert_queue(_ queue: dispatch_queue_t)
10- __external func dispatch_assert_queue_barrier(_ queue: dispatch_queue_t)
11- __external func dispatch_assert_queue_not(_ queue: dispatch_queue_t)
12-
13- internal func _dispatchPreconditionTest(_ condition: DispatchPredicate) -> Bool {
14- switch condition {
15- case .onQueue(let q):
16- dispatch_assert_queue(q.queue)
17- case .onQueueAsBarrier(let q):
18- dispatch_assert_queue_barrier(q.queue)
19- case .notOnQueue(let q):
20- dispatch_assert_queue_not(q.queue)
21- }
22- return true
23- }
24-
25- //@available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
26- public func dispatchPrecondition(condition: @autoclosure () -> DispatchPredicate) {
27- // precondition is able to determine release-vs-debug asserts where the overlay
28- // cannot, so formulating this into a call that we can call with precondition()
29- precondition(_dispatchPreconditionTest(condition()), String("dispatchPrecondition failure"))
30- }*/
31-
32- /*class DispatchIO : DispatchObject {
33- public enum StreamType : UInt {
34- case stream
35- case random
36- typealias RawValue = UInt
37- //var hashValue: Int { return U }
38- /*public init?(rawValue: UInt) {
39- self.rawValue = rawValue
40- }
41- let rawValue: UInt*/
42- }
43- public struct CloseFlags /*: OptionSet, RawRepresentable*/ {
44- let rawValue: UInt
45- public init(rawValue: UInt) {
46- self.rawValue = rawValue
47- }
48- static let stop: DispatchIO.CloseFlags
49- typealias Element = DispatchIO.CloseFlags
50- typealias RawValue = UInt
51- }
52- public struct IntervalFlags /*: OptionSet, RawRepresentable*/ {
53- let rawValue: UInt
54- public init(rawValue: UInt) {
55- }
56- static let strictInterval: DispatchIO.IntervalFlags
57- typealias Element = DispatchIO.IntervalFlags
58- typealias RawValue = UInt
59- }
60- class func read(fileDescriptor: Int32, length: Int, queue: DispatchQueue, handler: (DispatchData, Int32) -> Void) {
61- }
62- class func write(fileDescriptor: Int32, data: DispatchData, queue: DispatchQueue, handler: (DispatchData?, Int32) -> Void) {
63- }
64- convenience public init(type: DispatchIO.StreamType, fileDescriptor: Int32, queue: DispatchQueue, cleanupHandler: (error: Int32) -> Void) {
65- }
66- convenience public init(type: DispatchIO.StreamType, path: UnsafePointer<Int8>, oflag: Int32, mode: mode_t, queue: DispatchQueue, cleanupHandler: (error: Int32) -> Void) {
67- }
68- convenience public init(type: DispatchIO.StreamType, io: DispatchIO, queue: DispatchQueue, cleanupHandler: (error: Int32) -> Void) {
69- }
70- func close(flags: DispatchIO.CloseFlags) {
71- }
72- var fileDescriptor: Int32 { get }
73- func read(offset: off_t, length: Int, queue: DispatchQueue, ioHandler io_handler: (Bool, DispatchData?, Int32) -> Void) {
74- }
75- func setHighWater(highWater high_water: Int) {
76- }
77- func setInterval(interval: UInt64, flags: DispatchIO.IntervalFlags) {
78- }
79- func setLowWater(lowWater low_water: Int) {
80- }
81- func withBarrier(barrier: () -> Void) {
82- }
83- func write(offset: off_t, data: DispatchData, queue: DispatchQueue, ioHandler io_handler: (Bool, DispatchData?, Int32) -> Void) {
84- }
85- }*/
9+ public class DispatchObject {
8610
87- public class DispatchObject /*: OS_object*/ {
88-
89- private public init ( rawValue: dispatch_object_t ) {
11+ internal init ( rawValue: dispatch_object_t ) {
9012 self . object = rawValue
9113 }
9214
@@ -127,17 +49,19 @@ public class DispatchGroup : DispatchObject {
12749 }
12850
12951
130- /*func wait(timeout: DispatchTime /*= default*/) -> Int {
131- //return dispatch_wait(group, timeout.rawValue)
52+ /*
53+ func wait(timeout: DispatchTime /*= default*/) -> Int {
54+ return dispatch_wait(group, timeout.rawValue)
13255 }
13356
13457 func wait(walltime timeout: DispatchWallTime) -> Int {
135- // return dispatch_wait(group, timeout.rawValue)
58+ return dispatch_wait(group, timeout.rawValue)
13659 }
13760
138- func notify(queue: DispatchQueue, exeute block: () -> ()) {
139- //dispatch_notify(group, queue.object, block)
140- }*/
61+ func notify(queue: DispatchQueue, execute block: () -> ()) {
62+ dispatch_notify(group, queue.object, block)
63+ }
64+ */
14165
14266 func enter( ) {
14367 dispatch_group_enter ( group)
@@ -149,8 +73,22 @@ public class DispatchGroup : DispatchObject {
14973}
15074
15175public class DispatchQueue : DispatchObject {
76+ public struct Attributes {
77+ public let rawValue : dispatch_queue_attr_t
78+ public init ( rawValue: dispatch_queue_attr_t ) {
79+ self . rawValue = rawValue
80+ }
81+ public static let serial : Attributes = Attributes ( rawValue: DISPATCH_QUEUE_SERIAL)
82+ public static let concurrent : Attributes = Attributes ( rawValue: DISPATCH_QUEUE_CONCURRENT)
83+ }
15284
153- private public init ( queue: dispatch_queue_t ) {
85+ public enum AutoreleaseFrequency {
86+ case inherit
87+ // case never
88+ // case workItem
89+ }
90+
91+ internal init ( queue: dispatch_queue_t ) {
15492 #if OLD_DEPLOYMENT_TARGET
15593 var temp : dispatch_object_t
15694 temp. _dq = queue
@@ -160,6 +98,21 @@ public class DispatchQueue : DispatchObject {
16098 #endif
16199 }
162100
101+ internal convenience init ( __label: String , attr: dispatch_queue_attr_t ? , queue: DispatchQueue ? ) {
102+ var raw : dispatch_queue_t
103+ if #defined( COCOA) {
104+ raw = dispatch_queue_create_with_target ( __label. UTF8String, attr, queue? . queue)
105+ } else if #defined( DARWIN) {
106+ let array = Encoding . UTF8. GetBytes ( __label+ " \0 " )
107+ raw = dispatch_queue_create_with_target ( ( & array[ 0 ] ) as! UnsafePointer < AnsiChar > , attr, queue? . queue)
108+ }
109+ self . init ( queue: raw)
110+ }
111+
112+ public convenience init ( label: String , target: DispatchQueue ? = nil ) {
113+ self . init ( __label: label, attr: nil , queue: target)
114+ }
115+
163116 public var queue : dispatch_queue_t {
164117 #if OLD_DEPLOYMENT_TARGET
165118 return object. _dq
@@ -168,20 +121,6 @@ public class DispatchQueue : DispatchObject {
168121 #endif
169122 }
170123
171- public enum GlobalAttributes /*: OptionSet*/ {
172- case qosUserInteractive = qos_class_t. QOS_CLASS_USER_INTERACTIVE
173- case qosUserInitiated = qos_class_t. QOS_CLASS_USER_INITIATED
174- case qosDefault = qos_class_t. QOS_CLASS_DEFAULT
175- case qosUtility = qos_class_t. QOS_CLASS_UTILITY
176- case qosBackground = qos_class_t. QOS_CLASS_BACKGROUND
177- case qosUnspecified = qos_class_t. QOS_CLASS_UNSPECIFIED
178-
179- case Background = DISPATCH_QUEUE_PRIORITY_BACKGROUND
180- case Default = DISPATCH_QUEUE_PRIORITY_DEFAULT
181- case High = DISPATCH_QUEUE_PRIORITY_HIGH
182- case Low = DISPATCH_QUEUE_PRIORITY_LOW
183- }
184-
185124 public var label : String {
186125 if #defined( COCOA) {
187126 return NSString . stringWithUTF8String ( dispatch_queue_get_label ( queue) )
@@ -196,63 +135,41 @@ public class DispatchQueue : DispatchObject {
196135
197136 public lazy class var main : DispatchQueue = DispatchQueue ( queue: dispatch_get_main_queue ( ) )
198137
199- public class func global( attributes : DispatchQueue . GlobalAttributes ) -> DispatchQueue {
200- let raw = dispatch_get_global_queue ( attributes . rawValue, 0 )
138+ public class func global( qos : DispatchQoS . QoSClass = . default ) -> DispatchQueue {
139+ let raw = dispatch_get_global_queue ( Int ( qos . rawValue) , 0 )
201140 return DispatchQueue ( queue: raw)
202141 }
203142
204- public convenience init ( label: String , attributes: DispatchQueueAttributes /*= default*/, target: DispatchQueue ? = nil ) {
205- var raw : dispatch_queue_t
206- if let target = target {
207- raw = target. queue
208- } else {
209- if #defined( COCOA) {
210- raw = dispatch_queue_create ( label. UTF8String, nil )
211- } else if #defined( DARWIN) {
212- let array = Encoding . UTF8. GetBytes ( label+ " \0 " )
213- raw = dispatch_queue_create ( ( & array[ 0 ] ) as! UnsafePointer < AnsiChar > , nil )
214- }
215- }
216- init ( queue: raw)
217- }
218-
219- public func after( when: DispatchTime , execute work: /*@convention(block)*/ ( ) -> Void ) {
220- dispatch_after ( when. rawValue, queue, work)
221- }
222- public func after( walltime when: DispatchWallTime , execute work: /*@convention(block)*/ ( ) -> Void ) {
223- dispatch_after ( when. rawValue, queue, work)
224- }
225-
226- public func apply( applier iterations: UInt64 , execute block: @noescape ( NSUInteger ) -> Void ) {
227- dispatch_apply ( iterations, queue, block)
143+ public func asyncAfter( deadline: DispatchTime , execute work: ( ) -> ( ) ) {
144+ dispatch_after ( deadline. rawValue, self . queue, work)
228145 }
229146
230- public func asynchronously( execute workItem: DispatchWorkItem ) {
231- dispatch_async ( queue) {
232- workItem. perform ( )
233- }
147+ public func asyncAfter( wallDeadline: DispatchWallTime , execute work: ( ) -> ( ) ) {
148+ dispatch_after ( wallDeadline. rawValue, self . queue, work)
234149 }
235150
236- public func asynchronously ( execute block : @ noescape ( ) -> Void ) {
237- dispatch_async ( queue, block )
151+ public func concurrentPerform ( iterations : Int , execute work : ( UInt ) -> ( ) ) {
152+ dispatch_apply ( iterations , self . queue, work )
238153 }
239154
240- public func asynchronously ( group : DispatchGroup ? /*= default*/ , qos : DispatchQoS /*= default*/ , flags : DispatchWorkItemFlags /*= default*/ , execute work: /*@convention(block)*/ ( ) -> Void ) {
241- dispatch_async ( queue, work)
155+ public func async ( execute work: ( ) -> ( ) ) {
156+ dispatch_async ( self . queue, work)
242157 }
243158
244- public func synchronously( execute block: @noescape ( ) -> Void ) {
245- dispatch_sync ( queue, block)
159+ public func async ( group: DispatchGroup ? , execute work: ( ) -> ( ) ) {
160+ if group != nil {
161+ dispatch_group_async ( group!. group, self . queue, work)
162+ } else {
163+ dispatch_async ( self . queue, work)
164+ }
246165 }
247166
248- public func synchronously( execute workItem: DispatchWorkItem ) {
249- dispatch_sync ( queue) {
250- workItem. perform ( )
251- }
167+ public func sync( execute work: ( ) -> ( ) ) {
168+ dispatch_sync ( self . queue, work)
252169 }
253170
254171 #if !ISLAND
255- public func synchronously < T> ( execute work: @ noescape ( ) throws -> T ) rethrows -> T {
172+ public func sync < T> ( execute work: ( ) throws -> T ) rethrows -> T {
256173 var result : T
257174 var e : AnyObject ?
258175 dispatch_sync ( queue) {
@@ -269,9 +186,6 @@ public class DispatchQueue : DispatchObject {
269186 }
270187 #endif
271188
272- /*func synchronously<T>(flags: DispatchWorkItemFlags, execute work: @noescape () throws -> T) rethrows -> T {
273- }*/
274-
275189 /*var qos: DispatchQoS {
276190 var priority: Int
277191 //let qos = dispatch_queue_get_qos_class(rawValue, &priority) // E486 Parameter 2 is "Int", should be "UnsafePointer<Int32>", in call to rtl.dispatch_queue_get_qos_class(_ queue: dispatch_queue_t!, _ relative_priority_ptr: UnsafePointer<Int32>) -> qos_class_t
@@ -599,15 +513,15 @@ public struct DispatchQoS /*: Equatable*/ {
599513 public let relativePriority : Int
600514 public static let background : DispatchQoS = DispatchQoS ( qosClass: QoSClass . background)
601515 public static let utility : DispatchQoS = DispatchQoS ( qosClass: QoSClass . utility)
602- public static let defaultQoS : DispatchQoS = DispatchQoS ( qosClass: QoSClass . defaultQoS )
516+ public static let `default` : DispatchQoS = DispatchQoS ( qosClass: QoSClass . default )
603517 public static let userInitiated : DispatchQoS = DispatchQoS ( qosClass: QoSClass . userInitiated)
604518 public static let userInteractive : DispatchQoS = DispatchQoS ( qosClass: QoSClass . userInteractive)
605519 public static let unspecified : DispatchQoS = DispatchQoS ( qosClass: QoSClass . unspecified)
606520
607521 public enum QoSClass {
608522 case background = qos_class_t. QOS_CLASS_BACKGROUND
609523 case utility = qos_class_t. QOS_CLASS_UTILITY
610- case defaultQoS = qos_class_t. QOS_CLASS_DEFAULT
524+ case `default` = qos_class_t. QOS_CLASS_DEFAULT
611525 case userInitiated = qos_class_t. QOS_CLASS_USER_INITIATED
612526 case userInteractive = qos_class_t. QOS_CLASS_USER_INTERACTIVE
613527 case unspecified = qos_class_t. QOS_CLASS_UNSPECIFIED
0 commit comments