Skip to content

Commit 0e0a5fc

Browse files
authored
Merge pull request #49 from thalesfragoso/spin-night
Add new use_spin_nightly feature
2 parents 6bd19b9 + 15e7940 commit 0e0a5fc

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

.github/workflows/build.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ jobs:
105105
run: cargo build --features alloc_ref
106106

107107
- name: "Run cargo test with `alloc_ref` feature"
108-
run: cargo test
108+
run: cargo test --features alloc_ref
109+
110+
- name: "Run cargo test with `use_spin_nightly` feature"
111+
run: cargo test --features use_spin_nightly
109112

110113
check_formatting:
111114
name: "Check Formatting"

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ documentation = "https://docs.rs/crate/linked_list_allocator"
1212
homepage = "http://os.phil-opp.com/kernel-heap.html#a-better-allocator"
1313

1414
[features]
15-
default = ["use_spin", "const_mut_refs"]
15+
default = ["use_spin_nightly"]
1616
use_spin = ["spinning_top"]
17+
use_spin_nightly = ["use_spin", "spinning_top/nightly", "const_mut_refs"]
1718
alloc_ref = []
18-
const_mut_refs = ["spinning_top/nightly"]
19+
const_mut_refs = []
1920

2021
[dependencies.spinning_top]
2122
version = "0.1.0"

Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- Add new `use_spin_nightly` feature, which, together with `const_mut_refs`, makes the `empty` method of `LockedHeap` const ([#49](https://github.com/phil-opp/linked-list-allocator/pull/49))
4+
35
# 0.8.10 – 2020-12-28
46

57
- Made hole module public for external uses ([#47](https://github.com/phil-opp/linked-list-allocator/pull/47))

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn init_heap() {
3232

3333
- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by using a spinlock.
3434
- **`const_mut_refs`** (default): Makes the `Heap::empty` function `const`; requires nightly Rust.
35+
- **`use_spin_nightly`** (default): Makes the `LockedHeap::empty` function `const`, automatically enables `use_spin` and `const_mut_refs`; requires nightly Rust.
3536
- **`alloc_ref`**: Provide an implementation of the unstable [`AllocRef`] trait; requires nightly Rust.
3637
- Warning: The `AllocRef` trait is still regularly changed on the Rust side, so expect some regular breakage when using this feature.
3738

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ impl Heap {
155155
}
156156
}
157157

158-
#[cfg(feature = "alloc_ref")]
159-
#[cfg(feature = "use_spin")]
158+
#[cfg(all(feature = "alloc_ref", feature = "use_spin"))]
160159
unsafe impl Allocator for LockedHeap {
161160
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
162161
if layout.size() == 0 {
@@ -181,13 +180,13 @@ pub struct LockedHeap(Spinlock<Heap>);
181180
#[cfg(feature = "use_spin")]
182181
impl LockedHeap {
183182
/// Creates an empty heap. All allocate calls will return `None`.
184-
#[cfg(feature = "const_mut_refs")]
183+
#[cfg(feature = "use_spin_nightly")]
185184
pub const fn empty() -> LockedHeap {
186185
LockedHeap(Spinlock::new(Heap::empty()))
187186
}
188187

189188
/// Creates an empty heap. All allocate calls will return `None`.
190-
#[cfg(not(feature = "const_mut_refs"))]
189+
#[cfg(not(feature = "use_spin_nightly"))]
191190
pub fn empty() -> LockedHeap {
192191
LockedHeap(Spinlock::new(Heap::empty()))
193192
}

0 commit comments

Comments
 (0)