Skip to content

Commit

Permalink
Switch to Rust stable, closes #128
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jan 25, 2024
1 parent ea5fc3e commit 1e88090
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-plz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/[email protected]
env:
Expand Down
46 changes: 21 additions & 25 deletions crates/fluke-buffet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(thread_local)]

mod roll;
pub use roll::*;

Expand All @@ -23,10 +21,8 @@ pub const NUM_BUF: u32 = 64 * 1024;
#[cfg(feature = "miri")]
pub const NUM_BUF: u32 = 64;

#[thread_local]
static BUF_POOL: BufPool = BufPool::new_empty(BUF_SIZE, NUM_BUF);

thread_local! {
static BUF_POOL: BufPool = const { BufPool::new_empty(BUF_SIZE, NUM_BUF) };
static BUF_POOL_DESTRUCTOR: RefCell<Option<MmapMut>> = const { RefCell::new(None) };
}

Expand Down Expand Up @@ -172,7 +168,7 @@ pub struct BufMut {
impl BufMut {
#[inline(always)]
pub fn alloc() -> Result<BufMut, Error> {
BUF_POOL.alloc()
BUF_POOL.with(|bp| bp.alloc())
}

#[inline(always)]
Expand Down Expand Up @@ -239,7 +235,7 @@ impl BufMut {
};

std::mem::forget(self); // don't decrease ref count
BUF_POOL.inc(left.index); // in fact, increase it by 1
BUF_POOL.with(|bp| bp.inc(left.index)); // in fact, increase it by 1

(left, right)
}
Expand All @@ -261,7 +257,7 @@ impl ops::Deref for BufMut {
fn deref(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
BUF_POOL.base_ptr(self.index).add(self.off as _),
BUF_POOL.with(|bp| bp.base_ptr(self.index).add(self.off as _)),
self.len as _,
)
}
Expand All @@ -273,7 +269,7 @@ impl ops::DerefMut for BufMut {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe {
std::slice::from_raw_parts_mut(
BUF_POOL.base_ptr(self.index).add(self.off as _),
BUF_POOL.with(|bp| bp.base_ptr(self.index).add(self.off as _)),
self.len as _,
)
}
Expand All @@ -282,7 +278,7 @@ impl ops::DerefMut for BufMut {

unsafe impl fluke_maybe_uring::buf::IoBuf for BufMut {
fn stable_ptr(&self) -> *const u8 {
unsafe { BUF_POOL.base_ptr(self.index).add(self.off as _) as *const u8 }
unsafe { BUF_POOL.with(|bp| bp.base_ptr(self.index).add(self.off as _)) as *const u8 }
}

fn bytes_init(&self) -> usize {
Expand All @@ -302,7 +298,7 @@ unsafe impl fluke_maybe_uring::buf::IoBuf for BufMut {

unsafe impl fluke_maybe_uring::buf::IoBufMut for BufMut {
fn stable_mut_ptr(&mut self) -> *mut u8 {
unsafe { BUF_POOL.base_ptr(self.index).add(self.off as _) }
unsafe { BUF_POOL.with(|bp| bp.base_ptr(self.index).add(self.off as _)) }
}

unsafe fn set_init(&mut self, _pos: usize) {
Expand All @@ -313,7 +309,7 @@ unsafe impl fluke_maybe_uring::buf::IoBufMut for BufMut {

impl Drop for BufMut {
fn drop(&mut self) {
BUF_POOL.dec(self.index);
BUF_POOL.with(|bp| bp.dec(self.index));
}
}

Expand Down Expand Up @@ -386,15 +382,15 @@ impl Buf {
};

std::mem::forget(self); // don't decrease ref count
BUF_POOL.inc(left.index); // in fact, increase it by 1
BUF_POOL.with(|bp| bp.inc(left.index)); // in fact, increase it by 1

(left, right)
}
}

unsafe impl fluke_maybe_uring::buf::IoBuf for Buf {
fn stable_ptr(&self) -> *const u8 {
unsafe { BUF_POOL.base_ptr(self.index).add(self.off as _) as *const u8 }
unsafe { BUF_POOL.with(|bp| bp.base_ptr(self.index).add(self.off as _)) as *const u8 }
}

fn bytes_init(&self) -> usize {
Expand All @@ -413,7 +409,7 @@ impl ops::Deref for Buf {
fn deref(&self) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
BUF_POOL.base_ptr(self.index).add(self.off as _),
BUF_POOL.with(|bp| bp.base_ptr(self.index).add(self.off as _)),
self.len as _,
)
}
Expand All @@ -422,7 +418,7 @@ impl ops::Deref for Buf {

impl Clone for Buf {
fn clone(&self) -> Self {
BUF_POOL.inc(self.index);
BUF_POOL.with(|bp| bp.inc(self.index));
Self {
index: self.index,
off: self.off,
Expand All @@ -434,7 +430,7 @@ impl Clone for Buf {

impl Drop for Buf {
fn drop(&mut self) {
BUF_POOL.dec(self.index);
BUF_POOL.with(|bp| bp.dec(self.index));
}
}

Expand Down Expand Up @@ -469,41 +465,41 @@ mod tests {

#[test]
fn freeze_test() -> eyre::Result<()> {
let total_bufs = BUF_POOL.num_free()?;
let total_bufs = BUF_POOL.with(|bp| bp.num_free())?;
let mut bm = BufMut::alloc().unwrap();

assert_eq!(total_bufs - 1, BUF_POOL.num_free()?);
assert_eq!(total_bufs - 1, BUF_POOL.with(|bp| bp.num_free())?);
assert_eq!(bm.len(), 4096);

bm[..11].copy_from_slice(b"hello world");
assert_eq!(&bm[..11], b"hello world");

let b = bm.freeze();
assert_eq!(&b[..11], b"hello world");
assert_eq!(total_bufs - 1, BUF_POOL.num_free()?);
assert_eq!(total_bufs - 1, BUF_POOL.with(|bp| bp.num_free())?);

let b2 = b.clone();
assert_eq!(&b[..11], b"hello world");
assert_eq!(total_bufs - 1, BUF_POOL.num_free()?);
assert_eq!(total_bufs - 1, BUF_POOL.with(|bp| bp.num_free())?);

drop(b);
assert_eq!(total_bufs - 1, BUF_POOL.num_free()?);
assert_eq!(total_bufs - 1, BUF_POOL.with(|bp| bp.num_free())?);

drop(b2);
assert_eq!(total_bufs, BUF_POOL.num_free()?);
assert_eq!(total_bufs, BUF_POOL.with(|bp| bp.num_free())?);

Ok(())
}

#[test]
fn split_test() -> eyre::Result<()> {
let total_bufs = BUF_POOL.num_free()?;
let total_bufs = BUF_POOL.with(|bp| bp.num_free())?;
let mut bm = BufMut::alloc().unwrap();

bm[..12].copy_from_slice(b"yellowjacket");
let (a, b) = bm.split_at(6);

assert_eq!(total_bufs - 1, BUF_POOL.num_free()?);
assert_eq!(total_bufs - 1, BUF_POOL.with(|bp| bp.num_free())?);
assert_eq!(&a[..], b"yellow");
assert_eq!(&b[..6], b"jacket");

Expand Down
2 changes: 0 additions & 2 deletions crates/fluke-maybe-uring/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(incomplete_features)]

use std::future::Future;

pub mod buf;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-01-24"
channel = "stable"
components = ["llvm-tools", "clippy", "rust-src"]
2 changes: 1 addition & 1 deletion scripts/cov.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eux

export RUSTFLAGS='-C instrument-coverage --cfg=coverage --cfg=coverage_nightly --cfg=trybuild_no_target -C instrument-coverage --cfg=coverage --cfg=coverage_nightly --cfg=trybuild_no_target'
export RUSTFLAGS='-C instrument-coverage --cfg=coverage --cfg=trybuild_no_target'

export CARGO_INCREMENTAL=0
export CARGO_TARGET_DIR="${PWD}/target-cov"
Expand Down
1 change: 1 addition & 0 deletions test-crates/fluke-curl-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
target
1 change: 1 addition & 0 deletions test-crates/fluke-h2spec/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
target
2 changes: 1 addition & 1 deletion test-crates/fluke-tls-sample/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/target
/targettarget
1 change: 1 addition & 0 deletions test-crates/hyper-testbed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
1 change: 1 addition & 0 deletions test-crates/sample-h2-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target

0 comments on commit 1e88090

Please sign in to comment.