Skip to content

Unify withLock implementations #1417

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
Jun 4, 2024
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
9 changes: 0 additions & 9 deletions Sources/SourceKitD/SourceKitDRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ import Foundation

import struct TSCBasic.AbsolutePath

extension NSLock {
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
internal func withLock<T>(_ body: () throws -> T) rethrows -> T {
lock()
defer { unlock() }
return try body()
}
}

/// The set of known SourceKitD instances, uniqued by path.
///
/// It is not generally safe to have two instances of SourceKitD for the same libsourcekitd, so
Expand Down
9 changes: 0 additions & 9 deletions Sources/SourceKitLSP/Clang/ClangLanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ import struct TSCBasic.AbsolutePath
import WinSDK
#endif

extension NSLock {
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
fileprivate func withLock<T>(_ body: () throws -> T) rethrows -> T {
lock()
defer { unlock() }
return try body()
}
}

/// A thin wrapper over a connection to a clangd server providing build setting handling.
///
/// In addition, it also intercepts notifications and replies from clangd in order to do things
Expand Down
9 changes: 0 additions & 9 deletions Sources/SwiftExtensions/AsyncQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ extension Task: AnyTask {
}
}

fileprivate extension NSLock {
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
func withLock<T>(_ body: () throws -> T) rethrows -> T {
lock()
defer { unlock() }
return try body()
}
}

/// A type that is able to track dependencies between tasks.
public protocol DependencyTracker: Sendable {
/// Whether the task described by `self` needs to finish executing before
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_library(SwiftExtensions STATIC
AsyncUtils.swift
Collection+Only.swift
Collection+PartitionIntoBatches.swift
NSLock+WithLock.swift
Sequence+AsyncMap.swift
Task+WithPriorityChangedHandler.swift
ThreadSafeBox.swift
Expand Down
21 changes: 21 additions & 0 deletions Sources/SwiftExtensions/NSLock+WithLock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation

extension NSLock {
func withLock<T>(_ body: () throws -> T) rethrows -> T {
lock()
defer { unlock() }
return try body()
}
}
9 changes: 0 additions & 9 deletions Sources/SwiftExtensions/ThreadSafeBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@

import Foundation

extension NSLock {
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
fileprivate func withLock<T>(_ body: () throws -> T) rethrows -> T {
lock()
defer { unlock() }
return try body()
}
}

/// A thread safe container that contains a value of type `T`.
///
/// - Note: Unchecked sendable conformance because value is guarded by a lock.
Expand Down