Skip to main content

Pow2RangeAllocator

Struct Pow2RangeAllocator 

Source
pub struct Pow2RangeAllocator { /* private fields */ }
Expand description

Pow2RangeAllocator is a small utility class which partitions a set of ranges of integers into sub-ranges which are power of 2 in length and power of 2 aligned and then manages allocating and freeing the subranges for clients. It is responsible for breaking larger sub-regions into smaller ones as needed for allocation, and for merging sub-regions into larger sub-regions as needed during free operations.

Its primary use is as a utility library for platforms who need to manage allocating blocks MSI IRQ IDs on behalf of the PCI bus driver, but could (in theory) be used for other things).

Implementations§

Source§

impl Pow2RangeAllocator

Source

pub fn project<'__pin>( self: Pin<&'__pin mut Self>, ) -> Pow2RangeAllocatorProjection<'__pin>

Pin-projects all fields of Self.

These fields are structurally pinned:

  • inner
  • lock

These fields are not structurally pinned:

Source§

impl Pow2RangeAllocator

Source

pub fn lock_lock( &self, ) -> impl PinInit<Pow2RangeAllocatorLockGuard<'_>, Infallible>

Source

pub fn lock_lock_policy<P: LockPolicy<RawMutex, AcquireArgs = ()>>( &self, ) -> impl PinInit<Pow2RangeAllocatorLockGuard<'_, P>, Infallible>

Source

pub fn lock_lock_aliased<'a, AliasClass: LockClass, M2: RawLock>( &'a self, alias: &'a KMutex<AliasClass, M2>, ) -> impl PinInit<KMutexAliasedGuard<'a, Pow2RangeAllocatorLockClass, AliasClass, RawMutex, M2>, Infallible>

Source

pub fn lock_lock_aliased_policy<'a, AliasClass: LockClass, M2: RawLock, P: LockPolicy<RawMutex, AcquireArgs = ()>>( &'a self, alias: &'a KMutex<AliasClass, M2>, ) -> impl PinInit<KMutexAliasedGuard<'a, Pow2RangeAllocatorLockClass, AliasClass, RawMutex, M2, P>, Infallible>

Source

pub fn guard_lock<'b, 'a>( &'b self, token: &'b LockToken<'a, Pow2RangeAllocatorLockClass>, ) -> Pow2RangeAllocatorLockTokenGuard<'b, 'a>

Source

pub fn guard_lock_mut<'b, 'a>( &'b self, token: &'b mut LockToken<'a, Pow2RangeAllocatorLockClass>, ) -> Pow2RangeAllocatorLockTokenGuardMut<'b, 'a>

Source§

impl Pow2RangeAllocator

Source

pub fn new() -> impl PinInit<Self, Infallible>

Creates a new, uninitialized Pow2RangeAllocator.

init must be called before any range can be added or allocated.

Source

pub fn init(&self, max_alloc_size: u32) -> Result<(), Status>

Initialize the state of a pow2 range allocator.

max_alloc_size is the maximum size of a single contiguous allocation. It must be a power of 2.

Returns a status code indicating the success or failure of the operation. Possible return values include ++ ZX_ERR_INVALID_ARGS max_alloc_size is zero or not a power of 2. ++ ZX_ERR_NO_MEMORY Not enough memory to allocate the storage for free bucket lists.

Source

pub fn free(&self)

Free all of the state associated with a previously initialized pow2 range allocator.

Source

pub fn add_range(&self, range_start: u32, range_len: u32) -> Result<(), Status>

Add a range of u32s to the pool of ranges to be allocated.

range_start is the start of the u32 range and range_len is its length.

Returns a status code indicating the success or failure of the operation. Possible return values include ++ ZX_ERR_INVALID_ARGS range_len is zero, or would cause the range to wrap the maximum range of a u32. ++ ZX_ERR_ALREADY_EXISTS the specified range overlaps with a range already added to the allocator. ++ ZX_ERR_NO_MEMORY Not enough memory to allocate the bookkeeping required for managing the range.

Source

pub fn allocate_range(&self, size: u32) -> Result<u32, Status>

Attempt to allocate a range of u32s from the available sub-ranges. The size of the allocated range must be a power of 2, and if the allocation succeeds, it is guaranteed to be aligned on a power of 2 boundary matching its size.

size is the requested size of the region. On success, the start of the allocated range is returned.

Possible error values include ++ ZX_ERR_INVALID_ARGS Multiple reasons, including… ++ size is zero. ++ size is not a power of two. ++ ZX_ERR_NO_RESOURCES No contiguous, aligned region could be found to satisfy the allocation request. ++ ZX_ERR_NO_MEMORY A region could be found, but memory required for bookkeeping could not be allocated.

Source

pub fn free_range(&self, range_start: u32, size: u32)

Free a range previously allocated using allocate_range.

range_start is the start of the previously allocated range and size is its size.

Trait Implementations§

Source§

impl HasPinData for Pow2RangeAllocator

Source§

type PinData = __ThePinData

Source§

unsafe fn __pin_data() -> Self::PinData

Auto Trait Implementations§

§

impl !Freeze for Pow2RangeAllocator

§

impl !RefUnwindSafe for Pow2RangeAllocator

§

impl !UnsafeUnpin for Pow2RangeAllocator

§

impl !UnwindSafe for Pow2RangeAllocator

§

impl Send for Pow2RangeAllocator

§

impl Sync for Pow2RangeAllocator

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Init<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), !>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

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

§

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> PinInit<T> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), !>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

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

§

type Target = T

The target type of the pointer.
§

fn to_mut_ptr(&self) -> *mut T

Casts the reference to a mutable raw pointer.
§

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

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.