pub struct LockedHeapWithRescue { /* private fields */ }
Expand description
A locked version of Heap
with rescue before oom
Usage
Create a locked heap:
use buddy_system_allocator::*;
let heap = LockedHeapWithRescue::new(|heap: &mut Heap| {});
Before oom, the allocator will try to call rescue function and try for one more time.
Implementations
sourceimpl LockedHeapWithRescue
impl LockedHeapWithRescue
sourcepub fn new(rescue: fn(_: &mut Heap)) -> LockedHeapWithRescue
pub fn new(rescue: fn(_: &mut Heap)) -> LockedHeapWithRescue
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 LockedHeapWithRescue
impl Deref for LockedHeapWithRescue
sourceimpl GlobalAlloc for LockedHeapWithRescue
impl GlobalAlloc for LockedHeapWithRescue
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 LockedHeapWithRescue
impl Send for LockedHeapWithRescue
impl Sync for LockedHeapWithRescue
impl Unpin for LockedHeapWithRescue
impl UnwindSafe for LockedHeapWithRescue
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