From 5af9ca0793f9afa526b8101bf11812513338e769 Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Tue, 23 Aug 2022 08:17:20 -0700 Subject: [PATCH] Remove use of deprecated STSC 'Lock' - SwiftScan use of it seems not needed anymore - ArgsResolver use can use 'NSLock' directly --- Sources/SwiftDriver/Execution/ArgsResolver.swift | 13 ++++++++++++- Sources/SwiftDriver/SwiftScan/SwiftScan.swift | 3 --- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftDriver/Execution/ArgsResolver.swift b/Sources/SwiftDriver/Execution/ArgsResolver.swift index 811c2ec96..6a48267ec 100644 --- a/Sources/SwiftDriver/Execution/ArgsResolver.swift +++ b/Sources/SwiftDriver/Execution/ArgsResolver.swift @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +import class Foundation.NSLock import TSCBasic @_implementationOnly import Yams @@ -25,7 +26,7 @@ public final class ArgsResolver { // FIXME: We probably need a dedicated type for this... private let temporaryDirectory: VirtualPath - private let lock = Lock() + private let lock = NSLock() public init(fileSystem: FileSystem, temporaryDirectory: VirtualPath? = nil) throws { self.pathMapping = [:] @@ -202,3 +203,13 @@ public final class ArgsResolver { } } } + +fileprivate extension NSLock { + /// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift' + /// Execute the given block while holding the lock. + func withLock (_ body: () throws -> T) rethrows -> T { + lock() + defer { unlock() } + return try body() + } +} diff --git a/Sources/SwiftDriver/SwiftScan/SwiftScan.swift b/Sources/SwiftDriver/SwiftScan/SwiftScan.swift index 2df4682f1..8effb9aa0 100644 --- a/Sources/SwiftDriver/SwiftScan/SwiftScan.swift +++ b/Sources/SwiftDriver/SwiftScan/SwiftScan.swift @@ -63,9 +63,6 @@ internal final class SwiftScan { /// The handle to the dylib. let dylib: Loader.Handle - /// Lock protecting private state. - let lock: Lock = Lock() - /// libSwiftScan API functions. let api: swiftscan_functions_t;