Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating a yield ID counter per async writer #2768

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/NIOCore/AsyncSequences/NIOAsyncWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import DequeModule
import NIOConcurrencyHelpers
import _NIODataStructures

@usableFromInline
let _asyncWriterYieldIDCounter = ManagedAtomic<UInt64>(0)

/// The delegate of the ``NIOAsyncWriter``. It is the consumer of the yielded writes to the ``NIOAsyncWriter``.
/// Furthermore, the delegate gets informed when the ``NIOAsyncWriter`` terminated.
///
Expand Down Expand Up @@ -434,14 +437,11 @@ extension NIOAsyncWriter {
}
}

@usableFromInline
/* private */ internal let _yieldIDCounter = ManagedAtomic<UInt64>(0)

@inlinable
func generateUniqueYieldID() -> YieldID {
// Using relaxed is fine here since we do not need any strict ordering just a
// unique ID for every yield.
.init(value: self._yieldIDCounter.loadThenWrappingIncrement(ordering: .relaxed))
.init(value: _asyncWriterYieldIDCounter.loadThenWrappingIncrement(ordering: .relaxed))
}
}

Expand Down