pub struct AllocationsTableWriter { /* private fields */ }
Expand description
Mediates write access to a VMO containing an hash table of allocated blocks indexed by block address.
All the updates happen atomically so that, at any time, snapshotting the VMO always results in a coherent snapshot of the table.
Hash collisions are handled by maintaining per-bucket linked lists. Specifically, an array of list heads, one for each bucket, is stored at the beginning of the VMO. The remaining part of the VMO contains the linked list nodes.
Implementations§
Source§impl AllocationsTableWriter
impl AllocationsTableWriter
Sourcepub fn new(vmo: &Vmo) -> Result<AllocationsTableWriter, Error>
pub fn new(vmo: &Vmo) -> Result<AllocationsTableWriter, Error>
Initializes a VMO as an empty table and creates an AllocationsTableWriter to write into it.
§Safety
The caller must guarantee that the vmo
is not accessed by others while the returned
instance is alive.
Sourcepub fn insert_allocation(
&mut self,
address: u64,
size: u64,
thread_info_key: ResourceKey,
stack_trace_key: ResourceKey,
timestamp: MonotonicInstant,
) -> Result<bool, Error>
pub fn insert_allocation( &mut self, address: u64, size: u64, thread_info_key: ResourceKey, stack_trace_key: ResourceKey, timestamp: MonotonicInstant, ) -> Result<bool, Error>
Inserts a new entry in the hash table.
Returns Ok(true) if it has been inserted, Ok(false) if a previous entry with the same address already existed, or an error if no free nodes are available.
Sourcepub fn erase_allocation(&mut self, address: u64) -> Option<u64>
pub fn erase_allocation(&mut self, address: u64) -> Option<u64>
Removes an entry from the hash table and returns the value of the removed entry’s size field.
Sourcepub fn replace_allocation(
&mut self,
address: u64,
size: u64,
thread_info_key: ResourceKey,
stack_trace_key: ResourceKey,
timestamp: MonotonicInstant,
) -> Result<Option<u64>, Error>
pub fn replace_allocation( &mut self, address: u64, size: u64, thread_info_key: ResourceKey, stack_trace_key: ResourceKey, timestamp: MonotonicInstant, ) -> Result<Option<u64>, Error>
Atomically updates metadata for the given address in the hash table.
Returns Ok(Some(old_size)) if it has been updated, Ok(None) if no entry with the given address exists, or an error if no free nodes are available.