Skip to content

Commit

Permalink
Add new use_spin_nightly feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesfragoso committed Dec 31, 2020
1 parent 6bd19b9 commit fe9f01c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ jobs:
run: cargo build --features alloc_ref

- name: "Run cargo test with `alloc_ref` feature"
run: cargo test
run: cargo test --features alloc_ref

- name: "Run cargo test with `use_spin_nightly` feature"
run: cargo test --features use_spin_nightly

check_formatting:
name: "Check Formatting"
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ homepage = "http://os.phil-opp.com/kernel-heap.html#a-better-allocator"
[features]
default = ["use_spin", "const_mut_refs"]
use_spin = ["spinning_top"]
use_spin_nightly = ["use_spin", "spinning_top/nightly", "const_mut_refs"]
alloc_ref = []
const_mut_refs = ["spinning_top/nightly"]
const_mut_refs = []

[dependencies.spinning_top]
version = "0.1.0"
Expand Down
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- 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))

# 0.8.10 – 2020-12-28

- Made hole module public for external uses ([#47](https://github.com/phil-opp/linked-list-allocator/pull/47))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn init_heap() {

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

Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ impl Heap {
}
}

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

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

0 comments on commit fe9f01c

Please sign in to comment.