Skip to content

Commit be23249

Browse files
committed
Thread safety + implicit import Dispatch
1 parent ac81d6d commit be23249

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Foundation/NSObject.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99

1010
import CoreFoundation
11+
@_exported import Dispatch
1112

1213
/// The `NSObjectProtocol` groups methods that are fundamental to all Foundation objects.
1314
///

Foundation/URLSession/URLSession.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ open class URLSession : NSObject {
198198
/// - Note: It's a **concurrent** queue.
199199
internal let taskAttributesIsolation: DispatchQueue
200200
internal let taskRegistry = URLSession._TaskRegistry()
201+
fileprivate let identiferLock = NSLock()
201202
fileprivate let identifier: Int32
202203
fileprivate var invalidated = false
203204
fileprivate static let registerProtocols: () = {
@@ -405,14 +406,12 @@ extension URLSession._Request {
405406
}
406407

407408
fileprivate extension URLSession {
408-
static let identiferLock = NSLock()
409-
410409
func createNextTaskIdentifier() -> Int {
411-
URLSession.identiferLock.lock()
412-
let i = nextTaskIdentifier
413-
nextTaskIdentifier += 1
414-
URLSession.identiferLock.unlock()
415-
return i
410+
return identiferLock.synchronized {
411+
let i = nextTaskIdentifier
412+
nextTaskIdentifier += 1
413+
return i
414+
}
416415
}
417416
}
418417

0 commit comments

Comments
 (0)