Skip to content
Open
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
103 changes: 95 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ human-panic = { version = "2.0.2" }
lazy_static = { version = "1.4.0" }
libc = { version = "0.2.169", features = ['extra_traits'] }
log = { version = "0.4.21" }
loom = { version = "0.7.2" }
once_cell = { version = "1.19.0" }
postcard = { version = "1.1.3", default-features = false, features = ["alloc"] }
proc-macro2 = { version = "1.0.84" }
Expand Down Expand Up @@ -164,3 +165,8 @@ strip = true
lto = true
# opt-level = "z"
panic = "abort"

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(loom)',
] }
3 changes: 3 additions & 0 deletions iceoryx2-bb/elementary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[lints]
workspace = true

[dependencies]
iceoryx2-bb-elementary-traits = { workspace = true }
iceoryx2-pal-concurrency-sync = { workspace = true }
Expand Down
11 changes: 11 additions & 0 deletions iceoryx2-bb/elementary/src/lazy_singleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<T> Default for LazySingleton<T> {

impl<T> LazySingleton<T> {
/// Creates a new [`LazySingleton`] where the underlying value is not yet initialized.
#[cfg(not(all(test, loom)))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to make iceoryx2 no_std. Has this a negative effect on this goal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mox692 @elBoberido Is there a chance to wait for #1156 before proceeding with this? It's hard to tell how those changes will interfere with this.

I am actively working to get it merged now. Pending reviews it should be in sometime this week...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1156 Is merged. If you can rebase this PR and adapt as required, should be good to go.

pub const fn new() -> Self {
Self {
data: UnsafeCell::new(None),
Expand All @@ -63,6 +64,16 @@ impl<T> LazySingleton<T> {
}
}

/// Creates a new [`LazySingleton`] where the underlying value is not yet initialized.
#[cfg(all(test, loom))]
pub fn new() -> Self {
Self {
data: UnsafeCell::new(None),
is_initialized: IoxAtomicBool::new(false),
is_finalized: IoxAtomicBool::new(false),
}
}
Comment on lines +68 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document that loom cannot handle const functions somewhere? I mean in case we introduce a new function and loom breaks. A good option would be to add the error message and the fix to FAQ_ICEORYX_DEVS.md.


/// Returns true if the underlying value was initialized, otherwise false.
pub fn is_initialized(&self) -> bool {
self.is_initialized.load(Ordering::Relaxed)
Expand Down
10 changes: 10 additions & 0 deletions iceoryx2-bb/elementary/src/unique_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ pub struct UniqueId {

impl Default for UniqueId {
fn default() -> Self {
#[cfg(not(all(test, loom)))]
static COUNTER: IoxAtomicU64 = IoxAtomicU64::new(0);
#[cfg(all(test, loom))]
static COUNTER: std::sync::LazyLock<IoxAtomicU64> = std::sync::LazyLock::new(|| {
unimplemented!("loom does not provide const-initialization for atomic variables.")
});

UniqueId {
value: COUNTER.fetch_add(1, Ordering::Relaxed),
Expand Down Expand Up @@ -105,7 +110,12 @@ pub struct TypedUniqueId<T> {

impl<T> Default for TypedUniqueId<T> {
fn default() -> Self {
#[cfg(not(all(test, loom)))]
static COUNTER: IoxAtomicU64 = IoxAtomicU64::new(0);
#[cfg(all(test, loom))]
static COUNTER: std::sync::LazyLock<IoxAtomicU64> = std::sync::LazyLock::new(|| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orecham I guess this is not an issue for no_std as long as iceoryx2 is build with std support.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work fine, but would mean only the std build is being validated - maybe OK, at least for the first steps?

unimplemented!("loom does not provide const-initialization for atomic variables.")
});

Self {
value: COUNTER.fetch_add(1, Ordering::Relaxed),
Expand Down
6 changes: 6 additions & 0 deletions iceoryx2-bb/lock-free/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[lints]
workspace = true

[dependencies]
iceoryx2-bb-log = { workspace = true }
iceoryx2-bb-elementary = { workspace = true }
Expand All @@ -21,3 +24,6 @@ iceoryx2-bb-posix = { workspace = true }
iceoryx2-bb-testing = { workspace = true }
iceoryx2-pal-testing = { workspace = true }
generic-tests = { workspace = true }

[target.'cfg(loom)'.dev-dependencies]
loom = { workspace = true }
27 changes: 20 additions & 7 deletions iceoryx2-bb/lock-free/src/spsc/index_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@
//! }
//! ```

use core::{alloc::Layout, cell::UnsafeCell, fmt::Debug, sync::atomic::Ordering};
#[cfg(all(test, loom))]
use loom::cell::UnsafeCell;

#[cfg(not(all(test, loom)))]
use core::cell::UnsafeCell;

use core::{alloc::Layout, fmt::Debug};
use iceoryx2_bb_elementary::math::unaligned_mem_size;
use iceoryx2_bb_elementary::{bump_allocator::BumpAllocator, relocatable_ptr::RelocatablePointer};
use iceoryx2_bb_elementary_traits::{
owning_pointer::OwningPointer, pointer_trait::PointerTrait,
relocatable_container::RelocatableContainer,
};
use iceoryx2_bb_log::{fail, fatal_panic};
use iceoryx2_pal_concurrency_sync::iox_atomic::IoxAtomicBool;
use iceoryx2_pal_concurrency_sync::iox_atomic::IoxAtomicU64;
use iceoryx2_pal_concurrency_sync::iox_atomic::{fence, IoxAtomicBool, IoxAtomicU64, Ordering};

/// The [`Producer`] of the [`IndexQueue`]/[`FixedSizeIndexQueue`] which can add values to it
/// via [`Producer::push()`].
Expand Down Expand Up @@ -195,11 +200,19 @@ pub mod details {
}

unsafe fn at(&self, position: u64) -> *mut u64 {
(*self
let cell = &*self
.data_ptr
.as_ptr()
.add((position % self.capacity as u64) as usize))
.get()
.add((position % self.capacity as u64) as usize);

#[cfg(all(test, loom))]
{
cell.get_mut().deref() as *mut u64
}
#[cfg(not(all(test, loom)))]
{
cell.get()
}
}

/// Acquires the [`Producer`] of the [`IndexQueue`]. This is threadsafe and lock-free without
Expand Down Expand Up @@ -309,7 +322,7 @@ pub mod details {
let value = unsafe { *self.at(read_position) };
// prevent that `out` and `read_position` statements are reordered according to
// the AS-IF rule.
core::sync::atomic::fence(Ordering::AcqRel);
fence(Ordering::AcqRel);
self.read_position
.store(read_position + 1, Ordering::Relaxed);

Expand Down
3 changes: 3 additions & 0 deletions iceoryx2-bb/log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[lints]
workspace = true

[features]
default = []
std = []
Expand Down
12 changes: 12 additions & 0 deletions iceoryx2-bb/log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,20 @@ static DEFAULT_LOGGER: logger::null::Logger = logger::null::Logger::new();
const DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Info;

static mut LOGGER: Option<&'static dyn Log> = None;

#[cfg(not(all(test, loom)))]
static LOG_LEVEL: IoxAtomicU8 = IoxAtomicU8::new(DEFAULT_LOG_LEVEL as u8);
#[cfg(all(test, loom))]
static LOG_LEVEL: std::sync::LazyLock<IoxAtomicU8> = std::sync::LazyLock::new(|| {
unimplemented!("loom does not provide const-initialization for atomic variables.")
});

#[cfg(not(all(test, loom)))]
static INIT: Once = Once::new();
#[cfg(all(test, loom))]
static INIT: std::sync::LazyLock<Once> = std::sync::LazyLock::new(|| {
unimplemented!("loom does not provide const-initialization for atomic variables.")
});

pub trait Log: Send + Sync {
/// logs a message
Expand Down
3 changes: 3 additions & 0 deletions iceoryx2-bb/posix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }

[lints]
workspace = true

[features]
# Use https://crates.io/crates/libc for the platform abstraction. This simplifies
# cross-compilation since bindgen is not required anymore. Unfortunately, the libc crate
Expand Down
6 changes: 6 additions & 0 deletions iceoryx2-bb/posix/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,14 @@ impl Drop for SignalGuard {
}
}

#[cfg(not(all(test, loom)))]
static LAST_SIGNAL: IoxAtomicUsize = IoxAtomicUsize::new(posix::MAX_SIGNAL_VALUE);

#[cfg(all(test, loom))]
static LAST_SIGNAL: std::sync::LazyLock<IoxAtomicUsize> = std::sync::LazyLock::new(|| {
unimplemented!("loom does not provide const-initialization for atomic variables.")
});

/// Manages POSIX signal handling. It provides an interface to register custom callbacks for
/// signals, to perform a blocking wait until a certain signal arrived (for instance like CTRL+c) and
/// tracks signals which were received by the process.
Expand Down
Loading