pub struct TlsCounter { /* private fields */ }Expand description
Sharded atomic counter optimized for concurrent access from multiple threads.
Uses cache-line-padded shards to prevent false sharing. Each thread is assigned a shard index, so updates from different threads typically hit different cache lines.
This design handles interleaved access to multiple counters efficiently - unlike a single-slot cache approach, there’s no “cache thrashing” when alternating between counters.
§Memory
Each counter uses NUM_SHARDS × 128 bytes = 8KB (with 64 shards). This is larger than a simple AtomicU64 but virtually eliminates contention.
Implementations§
Trait Implementations§
Source§impl Debug for TlsCounter
impl Debug for TlsCounter
Auto Trait Implementations§
impl !Freeze for TlsCounter
impl RefUnwindSafe for TlsCounter
impl Send for TlsCounter
impl Sync for TlsCounter
impl Unpin for TlsCounter
impl UnwindSafe for TlsCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request