Skip to content

Commit c41eef9

Browse files
authored
Merge pull request #23 from phil-opp/replace-spin-dependency
Use new spinning_top crate instead of `spin`
2 parents 0b7fddd + 1b0d0cb commit c41eef9

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ homepage = "http://os.phil-opp.com/kernel-heap.html#a-better-allocator"
1313

1414
[features]
1515
default = ["use_spin"]
16-
use_spin = ["spin"]
16+
use_spin = ["spinning_top"]
1717

18-
[dependencies.spin]
19-
version = "0.5.0"
18+
[dependencies.spinning_top]
19+
version = "0.1.0"
20+
features = ["nightly"]
2021
optional = true

src/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
extern crate std;
88

99
#[cfg(feature = "use_spin")]
10-
extern crate spin;
10+
extern crate spinning_top;
1111

1212
extern crate alloc;
1313

14-
use alloc::alloc::{AllocRef, AllocErr, Layout};
15-
use core::alloc::{GlobalAlloc};
14+
use alloc::alloc::{AllocErr, AllocRef, Layout};
15+
use core::alloc::GlobalAlloc;
1616
use core::mem;
1717
#[cfg(feature = "use_spin")]
1818
use core::ops::Deref;
1919
use core::ptr::NonNull;
2020
use hole::{Hole, HoleList};
2121
#[cfg(feature = "use_spin")]
22-
use spin::Mutex;
22+
use spinning_top::Spinlock;
2323

2424
mod hole;
2525
#[cfg(test)]
@@ -140,21 +140,21 @@ unsafe impl AllocRef for Heap {
140140
}
141141

142142
#[cfg(feature = "use_spin")]
143-
pub struct LockedHeap(Mutex<Heap>);
143+
pub struct LockedHeap(Spinlock<Heap>);
144144

145145
#[cfg(feature = "use_spin")]
146146
impl LockedHeap {
147147
/// Creates an empty heap. All allocate calls will return `None`.
148148
pub const fn empty() -> LockedHeap {
149-
LockedHeap(Mutex::new(Heap::empty()))
149+
LockedHeap(Spinlock::new(Heap::empty()))
150150
}
151151

152152
/// Creates a new heap with the given `bottom` and `size`. The bottom address must be valid
153153
/// and the memory in the `[heap_bottom, heap_bottom + heap_size)` range must not be used for
154154
/// anything else. This function is unsafe because it can cause undefined behavior if the
155155
/// given address is invalid.
156156
pub unsafe fn new(heap_bottom: usize, heap_size: usize) -> LockedHeap {
157-
LockedHeap(Mutex::new(Heap {
157+
LockedHeap(Spinlock::new(Heap {
158158
bottom: heap_bottom,
159159
size: heap_size,
160160
holes: HoleList::new(heap_bottom, heap_size),
@@ -164,9 +164,9 @@ impl LockedHeap {
164164

165165
#[cfg(feature = "use_spin")]
166166
impl Deref for LockedHeap {
167-
type Target = Mutex<Heap>;
167+
type Target = Spinlock<Heap>;
168168

169-
fn deref(&self) -> &Mutex<Heap> {
169+
fn deref(&self) -> &Spinlock<Heap> {
170170
&self.0
171171
}
172172
}

0 commit comments

Comments
 (0)