@@ -125,7 +125,7 @@ open class Operation : NSObject {
125
125
internal var _queue : OperationQueue ? {
126
126
_lock ( )
127
127
defer { _unlock ( ) }
128
- return __queue? . takeRetainedValue ( )
128
+ return __queue? . takeUnretainedValue ( )
129
129
}
130
130
131
131
internal func _adopt( queue: OperationQueue , schedule: DispatchWorkItem ) {
@@ -230,7 +230,7 @@ open class Operation : NSObject {
230
230
let kind : Transition ?
231
231
if keyPath == _NSOperationIsFinished || keyPath == _NSOperationIsFinishedAlternate {
232
232
kind = . toFinished
233
- } else if keyPath == _NSOperationIsExecuting || keyPath == _NSOperationIsReadyAlternate {
233
+ } else if keyPath == _NSOperationIsExecuting || keyPath == _NSOperationIsExecutingAlternate {
234
234
kind = . toExecuting
235
235
} else if keyPath == _NSOperationIsReady || keyPath == _NSOperationIsReadyAlternate {
236
236
kind = . toReady
@@ -474,7 +474,7 @@ open class Operation : NSObject {
474
474
475
475
internal func changePriority( _ newPri: Operation . QueuePriority . RawValue ) {
476
476
_lock ( )
477
- guard let oq = __queue? . takeRetainedValue ( ) else {
477
+ guard let oq = __queue? . takeUnretainedValue ( ) else {
478
478
__priorityValue = newPri
479
479
_unlock ( )
480
480
return
@@ -963,6 +963,11 @@ open class OperationQueue : NSObject, ProgressReporting {
963
963
OperationQueue . _currentQueue. set ( self )
964
964
op. start ( )
965
965
OperationQueue . _currentQueue. clear ( )
966
+ // We've just cleared _currentQueue storage.
967
+ // NSThreadSpecific doesn't release stored value on clear.
968
+ // This means `self` will leak if we don't release manually.
969
+ Unmanaged . passUnretained ( self ) . release ( )
970
+
966
971
// unset current tsd
967
972
if op. isFinished && op. _state. rawValue < Operation . __NSOperationState. finishing. rawValue {
968
973
Operation . observeValue ( forKeyPath: _NSOperationIsFinished, ofObject: op)
@@ -1086,7 +1091,7 @@ open class OperationQueue : NSObject, ProgressReporting {
1086
1091
defer { _unlock ( ) }
1087
1092
var op = __firstOperation
1088
1093
var cnt = 0
1089
- if let operation = op? . takeUnretainedValue ( ) {
1094
+ while let operation = op? . takeUnretainedValue ( ) {
1090
1095
if !( operation is _BarrierOperation ) {
1091
1096
cnt += 1
1092
1097
}
@@ -1100,7 +1105,7 @@ open class OperationQueue : NSObject, ProgressReporting {
1100
1105
defer { _unlock ( ) }
1101
1106
var operations = [ Operation] ( )
1102
1107
var op = __firstOperation
1103
- if let operation = op? . takeUnretainedValue ( ) {
1108
+ while let operation = op? . takeUnretainedValue ( ) {
1104
1109
if includingBarriers || !( operation is _BarrierOperation ) {
1105
1110
operations. append ( operation)
1106
1111
}
0 commit comments