[−][src]Struct metrics_util::AtomicBucket
A lock-free bucket with snapshot capabilities.
This bucket is implemented as a singly-linked list of blocks, where each block is a small buffer that can hold a handful of elements. There is no limit to how many elements can be in the bucket at a time. Blocks are dynamically allocated as elements are pushed into the bucket.
Unlike a queue, buckets cannot be drained element by element: callers must iterate the whole structure. Reading the bucket happens in a quasi-reverse fashion, to allow writers to make forward progress without affecting the iteration of the previously written values.
For example, in a scenario where an internal block can hold 4 elements, and the caller has written 10 elements to the bucket, you would expect to see the values in this order when iterating:
[6 7 8 9] [2 3 4 5] [0 1]
Block sizes are dependent on the target architecture, where each block can hold N items, and N is the number of bits in the target architecture's pointer width.
Implementations
impl<T> AtomicBucket<T>
[src]
pub fn new() -> Self
[src]
Creates a new, empty bucket.
pub fn is_empty(&self) -> bool
[src]
Checks whether or not this bucket is empty.
pub fn push(&self, value: T)
[src]
Pushes an element into the bucket.
pub fn data(&self) -> Vec<T> where
T: Clone,
[src]
T: Clone,
Collects all of the elements written to the bucket.
This operation can be slow as it involves allocating enough space to hold all of the
elements within the bucket. Consider data_with
to incrementally iterate
the internal blocks within the bucket.
Elements are in partial reverse order: blocks are iterated in reverse order, but the elements within them will appear in their original order.
pub fn data_with<F>(&self, mut f: F) where
F: FnMut(&[T]),
[src]
F: FnMut(&[T]),
Iterates all of the elements written to the bucket, invoking f
for each block.
Elements are in partial reverse order: blocks are iterated in reverse order, but the elements within them will appear in their original order.
pub fn clear(&self)
[src]
Clears the bucket.
Deallocation of the internal blocks happens only when all readers have finished, and so will not necessarily occur during or immediately preceding this method.
Note
This method will not affect reads that are already in progress.
pub fn clear_with<F>(&self, mut f: F) where
F: FnMut(&[T]),
[src]
F: FnMut(&[T]),
Clears the bucket, invoking f
for every block that will be cleared.
Deallocation of the internal blocks happens only when all readers have finished, and so will not necessarily occur during or immediately preceding this method.
This method is useful for accumulating values and then observing them, in a way that allows the caller to avoid visiting the same values again the next time.
This method allows a pattern of observing values before they're cleared, with a clear demarcation. A similar pattern used in the wild would be to have some data structure, like a vector, which is continuously filled, and then eventually swapped out with a new, empty vector, allowing the caller to read all of the old values while new values are being written, over and over again.
Note
This method will not affect reads that are already in progress.
Trait Implementations
impl<T: Debug> Debug for AtomicBucket<T>
[src]
impl<T> Default for AtomicBucket<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for AtomicBucket<T>
[src]
impl<T> Send for AtomicBucket<T>
[src]
impl<T> Sync for AtomicBucket<T>
[src]
impl<T> Unpin for AtomicBucket<T>
[src]
impl<T> !UnwindSafe for AtomicBucket<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,