Skip to content

Commit 5115e4f

Browse files
committed
Removed unnecessary locks.
1 parent 3c91d3c commit 5115e4f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Sources/AWSLambdaRuntimeCore/HTTPClient.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal final class HTTPClient {
2525
private let targetHost: String
2626

2727
private var state = State.disconnected
28-
private let executing = NIOAtomic.makeAtomic(value: false)
28+
private var executing = false
2929

3030
init(eventLoop: EventLoop, configuration: Lambda.Configuration.RuntimeEngine) {
3131
self.eventLoop = eventLoop
@@ -50,7 +50,7 @@ internal final class HTTPClient {
5050

5151
/// cancels the current request if there is one
5252
func cancel() {
53-
guard self.executing.exchange(with: true) else {
53+
guard self.executing else {
5454
// there is no request running. nothing to cancel
5555
return
5656
}
@@ -64,7 +64,10 @@ internal final class HTTPClient {
6464

6565
// TODO: cap reconnect attempt
6666
private func execute(_ request: Request, validate: Bool = true) -> EventLoopFuture<Response> {
67-
precondition(!validate || self.executing.compareAndExchange(expected: false, desired: true), "expecting single request at a time")
67+
if validate {
68+
precondition(self.executing == false)
69+
self.executing = true
70+
}
6871

6972
switch self.state {
7073
case .disconnected:
@@ -80,7 +83,8 @@ internal final class HTTPClient {
8083

8184
let promise = channel.eventLoop.makePromise(of: Response.self)
8285
promise.futureResult.whenComplete { _ in
83-
precondition(self.executing.compareAndExchange(expected: true, desired: false), "invalid execution state")
86+
precondition(self.executing == true)
87+
self.executing = false
8488
}
8589
let wrapper = HTTPRequestWrapper(request: request, promise: promise)
8690
channel.writeAndFlush(wrapper).cascadeFailure(to: promise)

Sources/AWSLambdaRuntimeCore/LambdaLifecycle.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import NIOConcurrencyHelpers
1818

1919
extension Lambda {
2020
/// `Lifecycle` manages the Lambda process lifecycle.
21+
///
22+
/// - note: It is intended to be used within a single `EventLoop`. For this reason this class is not thread safe.
2123
public final class Lifecycle {
2224
private let eventLoop: EventLoop
2325
private let shutdownPromise: EventLoopPromise<Int>
@@ -82,8 +84,7 @@ extension Lambda {
8284
// MARK: - Private
8385

8486
#if DEBUG
85-
/// Begin the `Lifecycle` shutdown.
86-
/// Only needed for debugging purposes.
87+
/// Begin the `Lifecycle` shutdown. Only needed for debugging purposes, hence behind a `DEBUG` flag.
8788
public func shutdown() {
8889
// make this method thread safe by dispatching onto the eventloop
8990
self.eventLoop.execute {

0 commit comments

Comments
 (0)