Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update workflows to main branch #101

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/doctests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

name: Documentation Tests

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/embedded-builds.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

name: Embedded Builds

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

name: Formatting check

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/full-test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

name: Integration Tests

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/tsan-test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

name: TSAN Integration Test

Expand All @@ -22,13 +22,14 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rust-src
toolchain: ${{ matrix.rust }}

- uses: actions-rs/cargo@v1
with:
command: test
toolchain: nightly
args: ${{ matrix.build }} --features=short-potato --manifest-path bbqtest/Cargo.toml --target x86_64-unknown-linux-gnu -- --nocapture
args: ${{ matrix.build }} --features=short-potato --manifest-path bbqtest/Cargo.toml -Zbuild-std --target x86_64-unknown-linux-gnu -- --nocapture
env:
RUSTFLAGS: "-Z sanitizer=thread"
RUST_TEST_THREADS: 1
Expand Down
7 changes: 6 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bbqueue"
version = "0.5.0"
version = "0.5.1"
description = "A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers"
repository = "https://github.com/jamesmunns/bbqueue"
authors = ["James Munns <[email protected]>"]
Expand All @@ -17,8 +17,13 @@ license = "MIT OR Apache-2.0"
[dependencies]
cortex-m = { version = "0.6.0", optional = true }

[dependencies.defmt]
version = "0.3.0"
optional = true

[features]
thumbv6 = ["cortex-m"]
defmt_0_3 = ["defmt"]

[package.metadata.docs.rs]
all-features = true
55 changes: 31 additions & 24 deletions core/src/bbbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ impl<'a, const N: usize> BBBuffer<N> {
}

// Drop the producer and consumer halves
// Clippy's hint are ignored because this is done intentionnaly to prevent any use after
// the release fo the lock.
#[allow(clippy::drop_non_drop)]
drop(prod);
#[allow(clippy::drop_non_drop)]
drop(cons);

// Re-initialize the buffer (not totally needed, but nice to do)
Expand Down Expand Up @@ -247,35 +251,35 @@ impl<const A: usize> BBBuffer<A> {
// This will not be initialized until we split the buffer
buf: UnsafeCell::new(MaybeUninit::uninit()),

/// Owned by the writer
// Owned by the writer
write: AtomicUsize::new(0),

/// Owned by the reader
// Owned by the reader
read: AtomicUsize::new(0),

/// Cooperatively owned
///
/// NOTE: This should generally be initialized as size_of::<self.buf>(), however
/// this would prevent the structure from being entirely zero-initialized,
/// and can cause the .data section to be much larger than necessary. By
/// forcing the `last` pointer to be zero initially, we place the structure
/// in an "inverted" condition, which will be resolved on the first commited
/// bytes that are written to the structure.
///
/// When read == last == write, no bytes will be allowed to be read (good), but
/// write grants can be given out (also good).
// Cooperatively owned
//
// NOTE: This should generally be initialized as size_of::<self.buf>(), however
// this would prevent the structure from being entirely zero-initialized,
// and can cause the .data section to be much larger than necessary. By
// forcing the `last` pointer to be zero initially, we place the structure
// in an "inverted" condition, which will be resolved on the first commited
// bytes that are written to the structure.
//
// When read == last == write, no bytes will be allowed to be read (good), but
// write grants can be given out (also good).
last: AtomicUsize::new(0),

/// Owned by the Writer, "private"
// Owned by the Writer, "private"
reserve: AtomicUsize::new(0),

/// Owned by the Reader, "private"
// Owned by the Reader, "private"
read_in_progress: AtomicBool::new(false),

/// Owned by the Writer, "private"
// Owned by the Writer, "private"
write_in_progress: AtomicBool::new(false),

/// We haven't split at the start
// We haven't split at the start
already_split: AtomicBool::new(false),
}
}
Expand Down Expand Up @@ -369,6 +373,7 @@ impl<'a, const N: usize> Producer<'a, N> {
return Err(Error::InsufficientSize);
}
} else {
#[allow(clippy::collapsible_if)]
if write + sz <= max {
// Non inverted condition
write
Expand All @@ -395,8 +400,7 @@ impl<'a, const N: usize> Producer<'a, N> {
// This is sound, as UnsafeCell, MaybeUninit, and GenericArray
// are all `#[repr(Transparent)]
let start_of_buf_ptr = inner.buf.get().cast::<u8>();
let grant_slice =
unsafe { from_raw_parts_mut(start_of_buf_ptr.offset(start as isize), sz) };
let grant_slice = unsafe { from_raw_parts_mut(start_of_buf_ptr.add(start), sz) };

Ok(GrantW {
buf: grant_slice,
Expand Down Expand Up @@ -471,6 +475,7 @@ impl<'a, const N: usize> Producer<'a, N> {
return Err(Error::InsufficientSize);
}
} else {
#[allow(clippy::collapsible_if)]
if write != max {
// Some (or all) room remaining in un-inverted case
sz = min(max - write, sz);
Expand Down Expand Up @@ -498,8 +503,7 @@ impl<'a, const N: usize> Producer<'a, N> {
// This is sound, as UnsafeCell, MaybeUninit, and GenericArray
// are all `#[repr(Transparent)]
let start_of_buf_ptr = inner.buf.get().cast::<u8>();
let grant_slice =
unsafe { from_raw_parts_mut(start_of_buf_ptr.offset(start as isize), sz) };
let grant_slice = unsafe { from_raw_parts_mut(start_of_buf_ptr.add(start), sz) };

Ok(GrantW {
buf: grant_slice,
Expand Down Expand Up @@ -589,7 +593,7 @@ impl<'a, const N: usize> Consumer<'a, N> {
// This is sound, as UnsafeCell, MaybeUninit, and GenericArray
// are all `#[repr(Transparent)]
let start_of_buf_ptr = inner.buf.get().cast::<u8>();
let grant_slice = unsafe { from_raw_parts_mut(start_of_buf_ptr.offset(read as isize), sz) };
let grant_slice = unsafe { from_raw_parts_mut(start_of_buf_ptr.add(read), sz) };

Ok(GrantR {
buf: grant_slice,
Expand Down Expand Up @@ -641,8 +645,7 @@ impl<'a, const N: usize> Consumer<'a, N> {
// This is sound, as UnsafeCell, MaybeUninit, and GenericArray
// are all `#[repr(Transparent)]
let start_of_buf_ptr = inner.buf.get().cast::<u8>();
let grant_slice1 =
unsafe { from_raw_parts_mut(start_of_buf_ptr.offset(read as isize), sz1) };
let grant_slice1 = unsafe { from_raw_parts_mut(start_of_buf_ptr.add(read), sz1) };
let grant_slice2 = unsafe { from_raw_parts_mut(start_of_buf_ptr, sz2) };

Ok(SplitGrantR {
Expand Down Expand Up @@ -780,6 +783,8 @@ impl<'a, const N: usize> GrantW<'a, N> {
/// `&'static mut [u8]`, it is not possible for the inner reference to outlive the
/// grant itself.
///
/// # Safety
///
/// You MUST guarantee that in no cases, the reference that is returned here outlives
/// the grant itself. Once the grant has been released, referencing the data contained
/// WILL cause undefined behavior.
Expand Down Expand Up @@ -919,6 +924,8 @@ impl<'a, const N: usize> GrantR<'a, N> {
/// `&'static [u8]`, it is not possible for the inner reference to outlive the
/// grant itself.
///
/// # Safety
///
/// You MUST guarantee that in no cases, the reference that is returned here outlives
/// the grant itself. Once the grant has been released, referencing the data contained
/// WILL cause undefined behavior.
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub type Result<T> = CoreResult<T, Error>;

/// Error type used by the `BBQueue` interfaces
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[cfg_attr(feature = "defmt_0_3", derive(defmt::Format))]
pub enum Error {
/// The buffer does not contain sufficient size for the requested action
InsufficientSize,
Expand Down
Loading