pub struct LockedHeap(/* private fields */);
Expand description
A re-export of slab_allocator_rs::LockedHeap
for ease-of-use reasons.
Implementations§
Source§impl LockedHeap
impl LockedHeap
pub const fn empty() -> LockedHeap
Sourcepub unsafe fn init(&self, heap_start_addr: usize, size: usize)
pub unsafe fn init(&self, heap_start_addr: usize, size: usize)
§Safety
This function is unsafe because it can cause undefined behavior if the given address is invalid.
Sourcepub unsafe fn new(heap_start_addr: usize, heap_size: usize) -> LockedHeap
pub unsafe fn new(heap_start_addr: usize, heap_size: usize) -> LockedHeap
Creates a new heap with the given heap_start_addr
and heap_size
. The start address must be valid
and the memory in the [heap_start_addr, heap_bottom + heap_size)
range must not be used for
anything else.
§Safety
This function is unsafe because it can cause undefined behavior if the given address is invalid.
Methods from Deref<Target = Mutex<Option<Heap>>>§
Sourcepub fn lock(&self) -> MutexGuard<'_, T>
pub fn lock(&self) -> MutexGuard<'_, T>
Locks the Mutex
and returns a guard that permits access to the inner data.
The returned value may be dereferenced for data access and the lock will be dropped when the guard falls out of scope.
let lock = spin::Mutex::new(0);
{
let mut data = lock.lock();
// The lock is now locked and the data can be accessed
*data += 1;
// The lock is implicitly dropped at the end of the scope
}
Sourcepub fn is_locked(&self) -> bool
pub fn is_locked(&self) -> bool
Returns true
if the lock is currently held.
§Safety
This function provides no synchronization guarantees and so its result should be considered ‘out of date’ the instant it is called. Do not use it for synchronization purposes. However, it may be useful as a heuristic.
Sourcepub unsafe fn force_unlock(&self)
pub unsafe fn force_unlock(&self)
Sourcepub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
Trait Implementations§
Source§impl Deref for LockedHeap
impl Deref for LockedHeap
Source§impl GlobalAlloc for LockedHeap
impl GlobalAlloc for LockedHeap
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout
. Read more