Struct buddy_system_allocator::LockedHeap
source · [−]pub struct LockedHeap(_);
Expand description
A locked version of Heap
Usage
Create a locked heap and add a memory region to it:
use buddy_system_allocator::*;
let mut heap = LockedHeap::new();
unsafe {
heap.lock().init(begin, size);
// or
heap.lock().add_to_heap(begin, end);
}
Implementations
sourceimpl LockedHeap
impl LockedHeap
sourcepub const fn new() -> LockedHeap
pub const fn new() -> LockedHeap
Creates an empty heap
sourcepub const fn empty() -> LockedHeap
pub const fn empty() -> LockedHeap
Creates an empty heap
Methods from Deref<Target = Mutex<Heap>>
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 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 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
sourceimpl Deref for LockedHeap
impl Deref for LockedHeap
sourceimpl GlobalAlloc for LockedHeap
impl GlobalAlloc for LockedHeap
sourceunsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocate memory as described by the given layout
. Read more
sourceunsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
Deallocate the block of memory at the given ptr
pointer with the given layout
. Read more
Auto Trait Implementations
impl !RefUnwindSafe for LockedHeap
impl Send for LockedHeap
impl Sync for LockedHeap
impl Unpin for LockedHeap
impl UnwindSafe for LockedHeap
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more