@@ -326,7 +326,6 @@ open class OperationQueue: NSObject {
326
326
}
327
327
}
328
328
let queueGroup = DispatchGroup ( )
329
- var unscheduledWorkItems : [ DispatchWorkItem ] = [ ]
330
329
#endif
331
330
332
331
var _operations = _OperationList ( )
@@ -365,6 +364,9 @@ open class OperationQueue: NSObject {
365
364
}
366
365
}
367
366
let queue = DispatchQueue ( label: effectiveName, attributes: attr)
367
+ if _suspended {
368
+ queue. suspend ( )
369
+ }
368
370
__underlyingQueue = queue
369
371
lock. unlock ( )
370
372
return queue
@@ -430,13 +432,13 @@ open class OperationQueue: NSObject {
430
432
_operations. insert ( operation)
431
433
}
432
434
lock. unlock ( )
435
+ ops. forEach { ( operation: Operation ) -> Void in
433
436
#if DEPLOYMENT_ENABLE_LIBDISPATCH
434
- let items = ops. map { ( operation: Operation ) -> DispatchWorkItem in
435
437
if let group = waitGroup {
436
438
group. enter ( )
437
439
}
438
440
439
- return DispatchWorkItem ( flags: . enforceQoS) { ( ) -> Void in
441
+ let block = DispatchWorkItem ( flags: . enforceQoS) { ( ) -> Void in
440
442
if let sema = self . _concurrencyGate {
441
443
sema. wait ( )
442
444
self . _runOperation ( )
@@ -448,17 +450,10 @@ open class OperationQueue: NSObject {
448
450
group. leave ( )
449
451
}
450
452
}
453
+ _underlyingQueue. async ( group: queueGroup, execute: block)
454
+ #endif
451
455
}
452
-
453
- let queue = _underlyingQueue
454
- lock. lock ( )
455
- if _suspended {
456
- unscheduledWorkItems += items
457
- } else {
458
- items. forEach { queue. async ( group: queueGroup, execute: $0) }
459
- }
460
- lock. unlock ( )
461
-
456
+ #if DEPLOYMENT_ENABLE_LIBDISPATCH
462
457
if let group = waitGroup {
463
458
group. wait ( )
464
459
}
@@ -503,16 +498,19 @@ open class OperationQueue: NSObject {
503
498
}
504
499
set {
505
500
lock. lock ( )
506
- _suspended = newValue
507
- let items = unscheduledWorkItems
508
- unscheduledWorkItems. removeAll ( )
509
- lock. unlock ( )
510
-
511
- if !newValue {
512
- items. forEach {
513
- _underlyingQueue. async ( group: queueGroup, execute: $0)
501
+ if _suspended != newValue {
502
+ _suspended = newValue
503
+ #if DEPLOYMENT_ENABLE_LIBDISPATCH
504
+ if let queue = __underlyingQueue {
505
+ if newValue {
506
+ queue. suspend ( )
507
+ } else {
508
+ queue. resume ( )
509
+ }
514
510
}
511
+ #endif
515
512
}
513
+ lock. unlock ( )
516
514
}
517
515
}
518
516
0 commit comments