From f81055e0020166dc7d8205bdef79a0cf945d439a Mon Sep 17 00:00:00 2001 From: Fabian Fett Date: Thu, 27 Feb 2025 14:22:25 +0100 Subject: [PATCH 1/2] Replace usage of `NIOLockedValueBox` with `Mutex` --- Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index 317ee7ea..4ba271f0 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// +import Synchronization import Logging -import NIOConcurrencyHelpers import NIOCore #if canImport(FoundationEssentials) @@ -26,8 +26,7 @@ import Foundation // We don't want to use `NIOLockedValueBox` here anyway. We would love to use Mutex here, but this // sadly crashes the compiler today. public final class LambdaRuntime: @unchecked Sendable where Handler: StreamingLambdaHandler { - // TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore - let handlerMutex: NIOLockedValueBox + let handlerMutex: Mutex let logger: Logger let eventLoop: EventLoop @@ -36,7 +35,7 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St eventLoop: EventLoop = Lambda.defaultEventLoop, logger: Logger = Logger(label: "LambdaRuntime") ) { - self.handlerMutex = NIOLockedValueBox(handler) + self.handlerMutex = Mutex(handler) self.eventLoop = eventLoop // by setting the log level here, we understand it can not be changed dynamically at runtime @@ -49,7 +48,7 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St } public func run() async throws { - let handler = self.handlerMutex.withLockedValue { handler in + let handler = self.handlerMutex.withLock { handler in let result = handler handler = nil return result From 38356a5bae59e9a8caa644517e8ac66b77f09e13 Mon Sep 17 00:00:00 2001 From: Fabian Fett Date: Thu, 27 Feb 2025 15:21:39 +0100 Subject: [PATCH 2/2] Format fix --- Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index 4ba271f0..4b89dbc0 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -12,9 +12,9 @@ // //===----------------------------------------------------------------------===// -import Synchronization import Logging import NIOCore +import Synchronization #if canImport(FoundationEssentials) import FoundationEssentials