pub struct Control<T, U>where
T: 'static,{ /* private fields */ }Expand description
Controls the collection and accumulation of thread-local variables linked to this object.
T is the type of the values sent on the channel to this object and U is the type of the accumulated value.
The thread-locals must be of type Holder<T>.
Implementations§
Source§impl<T, U> Control<T, U>
impl<T, U> Control<T, U>
Sourcepub fn new(
tl: &'static LocalKey<Holder<T>>,
acc_base: U,
op: impl Fn(T, &mut U, ThreadId) + 'static + Send + Sync,
) -> Self
pub fn new( tl: &'static LocalKey<Holder<T>>, acc_base: U, op: impl Fn(T, &mut U, ThreadId) + 'static + Send + Sync, ) -> Self
Instantiates a Control object.
tl- reference to thread-local static.acc_base- initial value for accumulation.op- operation that combines data from thread-locals with accumulated value.
Sourcepub fn acc(&self) -> impl Deref<Target = U> + '_
pub fn acc(&self) -> impl Deref<Target = U> + '_
Returns a guard object that dereferences to self’s accumulated value. A lock is held during the guard’s
lifetime.
§Panics
If self’s mutex is poisoned.
Sourcepub fn take_acc(&self, replacement: U) -> U
pub fn take_acc(&self, replacement: U) -> U
Returns self’s accumulated value, using a value of the same type to replace
the existing accumulated value.
§Panics
If self’s mutex is poisoned.
Sourcepub fn start_receiving_tls(&self) -> Result<(), MultipleReceiverThreadsError>
pub fn start_receiving_tls(&self) -> Result<(), MultipleReceiverThreadsError>
Spawns a background thread to receive thread-local values and aggregate them with this object’s
accumulated value. May be called repeatedly, provided that there are intervening calls to
Self::stop_receiving_tls or Self::drain_tls.
§Errors
Returns an error if there is already an active background receiver thread.
§Panics
If self’s mutex is poisoned.
Sourcepub fn stop_receiving_tls(&self)
pub fn stop_receiving_tls(&self)
Signals the background receiving thread to terminate itself.