Skip to content

Use new nightly GlobalAlloc API #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Removed LOCKED_ALLOCATOR static
  • Loading branch information
weclaw1 committed Apr 17, 2018
commit aec3742e248b637ccf6dcf0634fa6df2b8d52e86
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ mod hole;
#[cfg(test)]
mod test;

#[cfg(feature = "use_spin")]
pub static mut LOCKED_ALLOCATOR: LockedHeap = LockedHeap::empty();

/// A fixed size heap backed by a linked list of free memory blocks.
pub struct Heap {
bottom: usize,
Expand Down Expand Up @@ -176,15 +173,15 @@ impl Deref for LockedHeap {
}

#[cfg(feature = "use_spin")]
unsafe impl<'a> GlobalAlloc for &'a LockedHeap {
unsafe impl GlobalAlloc for LockedHeap {
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
LOCKED_ALLOCATOR.0.lock().allocate_first_fit(layout).ok().map_or(0 as *mut Opaque, |allocation| {
self.0.lock().allocate_first_fit(layout).ok().map_or(0 as *mut Opaque, |allocation| {
allocation.as_ptr()
})
}

unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {
LOCKED_ALLOCATOR.0.lock().deallocate(NonNull::new_unchecked(ptr), layout)
self.0.lock().deallocate(NonNull::new_unchecked(ptr), layout)
}

fn oom(&self) -> ! {
Expand Down