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
impl Pow2RangeAllocator
pub fn lock_lock( &self, ) -> impl PinInit<Pow2RangeAllocatorLockGuard<'_>, Infallible>
pub fn lock_lock_policy<P: LockPolicy<RawMutex, AcquireArgs = ()>>( &self, ) -> impl PinInit<Pow2RangeAllocatorLockGuard<'_, P>, Infallible>
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>
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>
pub fn guard_lock<'b, 'a>( &'b self, token: &'b LockToken<'a, Pow2RangeAllocatorLockClass>, ) -> Pow2RangeAllocatorLockTokenGuard<'b, 'a>
pub fn guard_lock_mut<'b, 'a>( &'b self, token: &'b mut LockToken<'a, Pow2RangeAllocatorLockClass>, ) -> Pow2RangeAllocatorLockTokenGuardMut<'b, 'a>
Source§impl Pow2RangeAllocator
impl Pow2RangeAllocator
Sourcepub fn new() -> impl PinInit<Self, Infallible>
pub fn new() -> impl PinInit<Self, Infallible>
Creates a new, uninitialized Pow2RangeAllocator.
init must be called before any range can be added or allocated.
Sourcepub fn init(&self, max_alloc_size: u32) -> Result<(), Status>
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.
Sourcepub fn free(&self)
pub fn free(&self)
Free all of the state associated with a previously initialized pow2 range allocator.
Sourcepub fn add_range(&self, range_start: u32, range_len: u32) -> Result<(), Status>
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.
Sourcepub fn allocate_range(&self, size: u32) -> Result<u32, Status>
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.
Sourcepub fn free_range(&self, range_start: u32, size: u32)
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
impl HasPinData for Pow2RangeAllocator
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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), !>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), !>
slot. Read moreSource§fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>where
F: FnOnce(Pin<&mut T>) -> Result<(), E>,
fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>where
F: FnOnce(Pin<&mut T>) -> Result<(), E>,
self then calls the function f with the initialized
value. Read more