-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid using
NSLock.withLock
because Linux doesn't support it before…
… Swift 6.0 (#93)
- Loading branch information
1 parent
a255bbd
commit 0510d91
Showing
4 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 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 Swift project authors | ||
|
||
import Foundation | ||
|
||
/// A wrapper around NSLock. | ||
/// | ||
/// This type exist to offer an alternative to `NSLock.withLock` on Linux before Swift 6.0. | ||
struct Lock { | ||
private let innerLock = NSLock() | ||
|
||
func withLock<Result>(_ body: () throws -> Result) rethrows -> Result { | ||
// Use `lock()` and `unlock()` because Linux doesn't support `NSLock.withLock` before Swift 6.0 | ||
innerLock.lock() | ||
defer { innerLock.unlock() } | ||
|
||
return try body() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters