@@ -326,7 +326,6 @@ open class OperationQueue: NSObject {
326326 }
327327 }
328328 let queueGroup = DispatchGroup ( )
329- var unscheduledWorkItems : [ DispatchWorkItem ] = [ ]
330329#endif
331330
332331 var _operations = _OperationList ( )
@@ -365,6 +364,9 @@ open class OperationQueue: NSObject {
365364 }
366365 }
367366 let queue = DispatchQueue ( label: effectiveName, attributes: attr)
367+ if _suspended {
368+ queue. suspend ( )
369+ }
368370 __underlyingQueue = queue
369371 lock. unlock ( )
370372 return queue
@@ -430,13 +432,13 @@ open class OperationQueue: NSObject {
430432 _operations. insert ( operation)
431433 }
432434 lock. unlock ( )
435+ ops. forEach { ( operation: Operation ) -> Void in
433436#if DEPLOYMENT_ENABLE_LIBDISPATCH
434- let items = ops. map { ( operation: Operation ) -> DispatchWorkItem in
435437 if let group = waitGroup {
436438 group. enter ( )
437439 }
438440
439- return DispatchWorkItem ( flags: . enforceQoS) { ( ) -> Void in
441+ let block = DispatchWorkItem ( flags: . enforceQoS) { ( ) -> Void in
440442 if let sema = self . _concurrencyGate {
441443 sema. wait ( )
442444 self . _runOperation ( )
@@ -448,17 +450,10 @@ open class OperationQueue: NSObject {
448450 group. leave ( )
449451 }
450452 }
453+ _underlyingQueue. async ( group: queueGroup, execute: block)
454+ #endif
451455 }
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
462457 if let group = waitGroup {
463458 group. wait ( )
464459 }
@@ -503,16 +498,19 @@ open class OperationQueue: NSObject {
503498 }
504499 set {
505500 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+ }
514510 }
511+ #endif
515512 }
513+ lock. unlock ( )
516514 }
517515 }
518516
0 commit comments