pub struct LocatorHeader {
pub this_address: Unaligned<*mut LocatorHeader>,
pub next_locator_ptr: Unaligned<*mut LocatorHeader>,
pub is_locked: AtomicI32,
pub flags: u8,
pub num_items: u8,
/* private fields */
}Expand description
Represents the header of an individual memory locator.
Fields§
§this_address: Unaligned<*mut LocatorHeader>§next_locator_ptr: Unaligned<*mut LocatorHeader>§is_locked: AtomicI32§flags: u8§num_items: u8Implementations§
Source§impl LocatorHeader
impl LocatorHeader
Sourcepub fn set_version(&mut self, value: u8)
pub fn set_version(&mut self, value: u8)
Sets the version represented by the first 3 bits of flags.
Sourcepub fn has_next_locator(&self) -> bool
pub fn has_next_locator(&self) -> bool
Returns true if next locator is present.
Sourcepub fn try_lock(&mut self) -> bool
pub fn try_lock(&mut self) -> bool
Tries to acquire the lock.
Returns: True if the lock was successfully acquired, false otherwise.
Sourcepub fn unlock(&mut self)
pub fn unlock(&mut self)
Unlocks the object in a thread-safe manner.
§Panics
If the buffer is already unlocked, this error is thrown. It is only thrown in debug mode.
Sourcepub fn get_first_item(&self) -> *mut LocatorItem
pub fn get_first_item(&self) -> *mut LocatorItem
Gets the first item.
Sourcepub fn get_item(&self, index: usize) -> *mut LocatorItem
pub fn get_item(&self, index: usize) -> *mut LocatorItem
Gets the item at a specific index.
index: Index to get item at.
Sourcepub unsafe fn get_first_available_item_locked(
&self,
size: u32,
min_address: usize,
max_address: usize,
) -> Option<SafeLocatorItem>
pub unsafe fn get_first_available_item_locked( &self, size: u32, min_address: usize, max_address: usize, ) -> Option<SafeLocatorItem>
Gets the first available item with a lock.
§Arguments
size- Required size of the buffer.min_address- Minimum address for the allocation.max_address- Maximum address for the allocation.
§Safety
Uses raw pointers, thus is technically unsafe.
§Returns
Returns a locked locator item. Make sure to properly dispose of it using the appropriate method, as disposing will release the lock.
Sourcepub fn try_allocate_item(
&mut self,
size: u32,
min_address: usize,
max_address: usize,
) -> Result<SafeLocatorItem, ItemAllocationError>
pub fn try_allocate_item( &mut self, size: u32, min_address: usize, max_address: usize, ) -> Result<SafeLocatorItem, ItemAllocationError>
Tries to allocate an additional item in the header, if possible.
§Arguments
size- Required size of buffer.min_address- Minimum address for the allocation.max_address- Maximum address for the allocation.
§Returns
Returns the successfully allocated buffer (locked) wrapped in an Option.
§Remarks
If an item can’t be allocated, there are simply no slots left.
§Errors
If the memory cannot be allocated within the needed constraints, this function will return Err(MemoryBufferAllocationException).
§Safety
This function is unsafe as it requires the caller to ensure that calls are properly synchronized. Concurrent access without synchronization can lead to undefined behavior.
Sourcepub fn get_next_locator(&mut self) -> Result<*mut LocatorHeader, &'static str>
pub fn get_next_locator(&mut self) -> Result<*mut LocatorHeader, &'static str>
Gets the next header in the chain, allocating it if necessary.
§Returns
Result with the address of next header, or error string.