Skip to content

Remove use of deprecated STSC 'Lock' #1160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Sources/SwiftDriver/Execution/ArgsResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

import class Foundation.NSLock
import TSCBasic
@_implementationOnly import Yams

Expand All @@ -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 = [:]
Expand Down Expand Up @@ -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<T> (_ body: () throws -> T) rethrows -> T {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a note to keep this in sync with SPM?

lock()
defer { unlock() }
return try body()
}
}
3 changes: 0 additions & 3 deletions Sources/SwiftDriver/SwiftScan/SwiftScan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down