Skip to content

Commit

Permalink
Improve API using new Rust 1.50 feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nickray committed Feb 11, 2021
1 parent 0c0f433 commit 4552c1b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ jobs:

steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
name: Install Rust
with:
profile: minimal
toolchain: stable
override: true
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "interchange"
version = "0.1.1"
version = "0.1.2"
authors = ["Nicolas Stalder <[email protected]>"]
edition = "2018"
description = "Request/response mechanism for embedded development, using atomics"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub trait Interchange: Sized {
fn claim() -> Option<(Requester<Self>, Responder<Self>)>;

/// Method for debugging: how many allocated clients have not been claimed.
fn available_clients() -> usize;
fn unclaimed_clients() -> usize;

/// Method purely for testing - do not use in production
///
Expand Down
12 changes: 7 additions & 5 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
#[macro_export]
macro_rules! interchange {
($Name:ident: ($REQUEST:ty, $RESPONSE:ty)) => {
$crate::interchange!($Name: ($REQUEST, $RESPONSE, 1, [None]));
$crate::interchange!($Name: ($REQUEST, $RESPONSE, 1));
};

($Name:ident: ($REQUEST:ty, $RESPONSE:ty, $N:expr, $Nones:expr)) => {
($Name:ident: ($REQUEST:ty, $RESPONSE:ty, $N:expr)) => {

// TODO: figure out how to implement, e.g., Clone iff REQUEST
// and RESPONSE are clone (do not introduce Clone, Debug, etc. trait bounds).
Expand All @@ -49,8 +49,10 @@ macro_rules! interchange {
use core::cell::UnsafeCell;

// TODO(nickray): This turns up in .data section, fix this.
// static mut INTERCHANGES: [Option<$Name>; $N] = [None; $N];
static mut INTERCHANGES: [Option<$Name>; $N] = $Nones;

// yay Rust 1.50
const NONE: Option<$Name> = None;
static mut INTERCHANGES: [Option<$Name>; $N] = [NONE; $N];
static mut STATES: [u8; $N] = [0u8; $N];
unsafe {
let mut cell: MaybeUninit<UnsafeCell<&'static mut Option<$Name>>> = MaybeUninit::uninit();
Expand Down Expand Up @@ -110,7 +112,7 @@ macro_rules! interchange {
}
}

fn available_clients() -> usize {
fn unclaimed_clients() -> usize {
Self::CLIENT_CAPACITY - Self::last_claimed().load(core::sync::atomic::Ordering::SeqCst)
}

Expand Down

0 comments on commit 4552c1b

Please sign in to comment.