Skip to content

Commit 4ebf24f

Browse files
committed
Replace NIOLockedValueBox with Mutex
1 parent e3a3851 commit 4ebf24f

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

Diff for: Sources/AWSLambdaRuntime/LambdaRuntime.swift

+3-14
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import Logging
1616
import NIOConcurrencyHelpers
1717
import NIOCore
18-
19-
// To be re-enabled when we will be able to use Mutex on Linux
20-
// import Synchronization
18+
import Synchronization
2119

2220
#if canImport(FoundationEssentials)
2321
import FoundationEssentials
@@ -28,9 +26,7 @@ import Foundation
2826
// This is our gardian to ensure only one LambdaRuntime is initialized
2927
// We use a Mutex here to ensure thread safety
3028
// We use Bool instead of LambdaRuntime<Handler> as the type here, as we don't know the concrete type that will be used
31-
// We would love to use Mutex here, but this sadly crashes the compiler today (on Linux).
32-
// private let _singleton = Mutex<Bool>(false)
33-
private let _singleton: NIOLockedValueBox<Bool> = NIOLockedValueBox<Bool>(false)
29+
private let _singleton = Mutex<Bool>(false)
3430
public enum LambdaRuntimeError: Error {
3531
case moreThanOneLambdaRuntimeInstance
3632
}
@@ -53,14 +49,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
5349
// ) throws(LambdaRuntimeError) {
5450

5551
do {
56-
// try _singleton.withLock {
57-
// let alreadyCreated = $0
58-
// guard alreadyCreated == false else {
59-
// throw LambdaRuntimeError.moreThanOneLambdaRuntimeInstance
60-
// }
61-
// $0 = true
62-
// }
63-
try _singleton.withLockedValue {
52+
try _singleton.withLock {
6453
let alreadyCreated = $0
6554
guard alreadyCreated == false else {
6655
throw LambdaRuntimeError.moreThanOneLambdaRuntimeInstance

0 commit comments

Comments
 (0)