Struct concurrent_arena::Arena
source · [−]Expand description
-
LEN- Number of elements stored per bucket. Must be less than or equal tou32::MAX, divisible byusize::BITSand it must not be0. -
BITARRAY_LEN- Number bits in the bitmap per bucket. Must be equal toLEN / usize::BITS.For best performance, try to set this to number of CPUs that are going to access
Arenaconcurrently.
Arena stores the elements in buckets to ensure that the address
for elements are stable while improving efficiency.
Every bucket is of size LEN.
The larger LEN is, the more compact the Arena will be, however it might
also waste space if it is unused.
And, allocating a large chunk of memory takes more time.
Arena internally stores the array of buckets as a triomphe::ThinArc
and use ArcSwapAny to grow the array atomically, without blocking any
reader.
Examples
If you provides Arena with invalid LEM or BITARRAY_LEN, then your
code will panic at runtime:
use concurrent_arena::*;
let arena = Arena::<u32, 1, 100>::new();To make it a compile time failure, you need to call
max_buckets:
use concurrent_arena::*;
const MAX_BUCKETS: u32 = Arena::<u32, 1, 100>::max_buckets();Implementations
Maximum buckets Arena can have.
Return Ok(arc) on success, or Err((value, len)) where value is
the input param value and len is the length of the Arena at the time
of insertion.
This function is lock-free.
Try to reserve min(new_len, Self::max_buckets()) buckets.
This function is technically lock-free.
Insert one value.
If there isn’t enough buckets, then try to reserve one bucket and restart the operation.
May enter busy loop if the slot is not fully initialized.
This function is lock free.
May enter busy loop if the slot is not fully initialized.
This function is lock free.