Skip to main content

LocatorHeader

Struct LocatorHeader 

Source
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: u8

Implementations§

Source§

impl LocatorHeader

Source

pub fn version(&self) -> u8

Returns the version represented by the first 3 bits of flags.

Source

pub fn set_version(&mut self, value: u8)

Sets the version represented by the first 3 bits of flags.

Source

pub fn has_next_locator(&self) -> bool

Returns true if next locator is present.

Source

pub fn is_full(&self) -> bool

Returns true if this buffer is full.

Source

pub fn try_lock(&mut self) -> bool

Tries to acquire the lock.

Returns: True if the lock was successfully acquired, false otherwise.

Source

pub fn lock(&mut self)

Acquires the lock, blocking until it can do so.

Source

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.

Source

pub fn get_first_item(&self) -> *mut LocatorItem

Gets the first item.

Source

pub fn get_item(&self, index: usize) -> *mut LocatorItem

Gets the item at a specific index.

index: Index to get item at.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.