marcel_os::allocator

Struct Locked

Source
pub struct Locked<A> { /* private fields */ }
Expand description

A wrapper around a spin::Mutex to provide safe, locked access to the inner allocator. The Locked type ensures that only one thread can access the allocator at a time.

Implementations§

Source§

impl<A> Locked<A>

Source

pub const fn new(inner: A) -> Self

Creates a new Locked instance with the provided inner value.

§Arguments
  • inner - The value to be wrapped in the Locked mutex.
§Returns

A Locked instance containing the provided value.

Source

pub fn lock(&self) -> MutexGuard<'_, A>

Locks the inner mutex and returns a guard for accessing the wrapped value.

§Returns

A MutexGuard that allows mutable access to the wrapped value.

Trait Implementations§

Source§

impl GlobalAlloc for Locked<BumpAllocator>

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates a memory block with the specified layout.

§Safety

This function must be used in a single-threaded environment or protected by a lock.

Source§

unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout)

Deallocates a memory block. Since this is a bump allocator, deallocation is only meaningful when all allocations are freed at once.

§Safety

The provided pointer must be valid and previously allocated.

1.28.0§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more
1.28.0§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more
Source§

impl GlobalAlloc for Locked<FixedSizeBlockAllocator>

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates memory with the requested layout.

§Safety

This function must be called only in a thread-safe context.

Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocates memory and inserts it back into the free list if applicable.

§Safety

The provided pointer must be valid and previously allocated.

1.28.0§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more
1.28.0§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more
Source§

impl GlobalAlloc for Locked<LinkedListAllocator>

Implements the global allocator trait for LinkedListAllocator.

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates a memory block with the given layout.

§Safety

The caller must ensure that the requested allocation is valid and does not cause undefined behavior.

Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocates a previously allocated memory block.

§Safety

The caller must ensure that the pointer and layout are valid and that the memory block was allocated by this allocator.

1.28.0§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more
1.28.0§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more

Auto Trait Implementations§

§

impl<A> !Freeze for Locked<A>

§

impl<A> !RefUnwindSafe for Locked<A>

§

impl<A> Send for Locked<A>
where A: Send,

§

impl<A> Sync for Locked<A>
where A: Send,

§

impl<A> Unpin for Locked<A>
where A: Unpin,

§

impl<A> UnwindSafe for Locked<A>
where A: UnwindSafe,

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.

§

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.

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.