15
15
import Logging
16
16
import NIOConcurrencyHelpers
17
17
import NIOCore
18
-
19
- // To be re-enabled when we will be able to use Mutex on Linux
20
- // import Synchronization
18
+ import Synchronization
21
19
22
20
#if canImport(FoundationEssentials)
23
21
import FoundationEssentials
@@ -28,9 +26,7 @@ import Foundation
28
26
// This is our gardian to ensure only one LambdaRuntime is initialized
29
27
// We use a Mutex here to ensure thread safety
30
28
// 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 )
34
30
public enum LambdaRuntimeError : Error {
35
31
case moreThanOneLambdaRuntimeInstance
36
32
}
@@ -53,14 +49,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
53
49
// ) throws(LambdaRuntimeError) {
54
50
55
51
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 {
64
53
let alreadyCreated = $0
65
54
guard alreadyCreated == false else {
66
55
throw LambdaRuntimeError . moreThanOneLambdaRuntimeInstance
0 commit comments