1515import Logging
1616import NIOConcurrencyHelpers
1717import 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)
2321import 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 )
3430public 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