Skip to content

Commit 3e11cd6

Browse files
committed
Unify withLock implementations
Turns out that also most of the `withLock` definitions were never used.
1 parent 9c13dbb commit 3e11cd6

File tree

6 files changed

+22
-36
lines changed

6 files changed

+22
-36
lines changed

Sources/SourceKitD/SourceKitDRegistry.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ import Foundation
1414

1515
import struct TSCBasic.AbsolutePath
1616

17-
extension NSLock {
18-
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
19-
internal func withLock<T>(_ body: () throws -> T) rethrows -> T {
20-
lock()
21-
defer { unlock() }
22-
return try body()
23-
}
24-
}
25-
2617
/// The set of known SourceKitD instances, uniqued by path.
2718
///
2819
/// It is not generally safe to have two instances of SourceKitD for the same libsourcekitd, so

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ import struct TSCBasic.AbsolutePath
2424
import WinSDK
2525
#endif
2626

27-
extension NSLock {
28-
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
29-
fileprivate func withLock<T>(_ body: () throws -> T) rethrows -> T {
30-
lock()
31-
defer { unlock() }
32-
return try body()
33-
}
34-
}
35-
3627
/// A thin wrapper over a connection to a clangd server providing build setting handling.
3728
///
3829
/// In addition, it also intercepts notifications and replies from clangd in order to do things

Sources/SwiftExtensions/AsyncQueue.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ extension Task: AnyTask {
2626
}
2727
}
2828

29-
fileprivate extension NSLock {
30-
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
31-
func withLock<T>(_ body: () throws -> T) rethrows -> T {
32-
lock()
33-
defer { unlock() }
34-
return try body()
35-
}
36-
}
37-
3829
/// A type that is able to track dependencies between tasks.
3930
public protocol DependencyTracker: Sendable {
4031
/// Whether the task described by `self` needs to finish executing before

Sources/SwiftExtensions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_library(SwiftExtensions STATIC
44
AsyncUtils.swift
55
Collection+Only.swift
66
Collection+PartitionIntoBatches.swift
7+
NSLock+WithLock.swift
78
Sequence+AsyncMap.swift
89
Task+WithPriorityChangedHandler.swift
910
ThreadSafeBox.swift
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Foundation
14+
15+
extension NSLock {
16+
func withLock<T>(_ body: () throws -> T) rethrows -> T {
17+
lock()
18+
defer { unlock() }
19+
return try body()
20+
}
21+
}

Sources/SwiftExtensions/ThreadSafeBox.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212

1313
import Foundation
1414

15-
extension NSLock {
16-
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
17-
fileprivate func withLock<T>(_ body: () throws -> T) rethrows -> T {
18-
lock()
19-
defer { unlock() }
20-
return try body()
21-
}
22-
}
23-
2415
/// A thread safe container that contains a value of type `T`.
2516
///
2617
/// - Note: Unchecked sendable conformance because value is guarded by a lock.

0 commit comments

Comments
 (0)