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

[#31] Solve circular dependency #32

Merged
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
30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/eclipse-iceoryx/iceoryx2"
rust-version = "1.72.1"
version = "0.0.2"
version = "0.0.5"

[workspace.dependencies]
iceoryx2-bb-threadsafe = { version = "0.0.2", path = "iceoryx2-bb/threadsafe/" }
iceoryx2-bb-lock-free = { version = "0.0.2", path = "iceoryx2-bb/lock-free/" }
iceoryx2-bb-container = { version = "0.0.2", path = "iceoryx2-bb/container/" }
iceoryx2-bb-elementary = { version = "0.0.2", path = "iceoryx2-bb/elementary/" }
iceoryx2-bb-log = { version = "0.0.2", path = "iceoryx2-bb/log/" }
iceoryx2-bb-memory = { version = "0.0.2", path = "iceoryx2-bb/memory/" }
iceoryx2-bb-posix = { version = "0.0.2", path = "iceoryx2-bb/posix/" }
iceoryx2-bb-system-types = { version = "0.0.2", path = "iceoryx2-bb/system-types/" }
iceoryx2-bb-testing = { version = "0.0.2", path = "iceoryx2-bb/testing/" }
iceoryx2-bb-threadsafe = { version = "0.0.5", path = "iceoryx2-bb/threadsafe/" }
iceoryx2-bb-lock-free = { version = "0.0.5", path = "iceoryx2-bb/lock-free/" }
iceoryx2-bb-container = { version = "0.0.5", path = "iceoryx2-bb/container/" }
iceoryx2-bb-elementary = { version = "0.0.5", path = "iceoryx2-bb/elementary/" }
iceoryx2-bb-log = { version = "0.0.5", path = "iceoryx2-bb/log/" }
iceoryx2-bb-memory = { version = "0.0.5", path = "iceoryx2-bb/memory/" }
iceoryx2-bb-posix = { version = "0.0.5", path = "iceoryx2-bb/posix/" }
iceoryx2-bb-system-types = { version = "0.0.5", path = "iceoryx2-bb/system-types/" }
iceoryx2-bb-testing = { version = "0.0.5", path = "iceoryx2-bb/testing/" }

iceoryx2-pal-concurrency-sync = { version = "0.0.2", path = "iceoryx2-pal/concurrency-sync/" }
iceoryx2-pal-posix = { version = "0.0.2", path = "iceoryx2-pal/posix/" }
iceoryx2-pal-configuration = { version = "0.0.2", path = "iceoryx2-pal/configuration/" }
iceoryx2-pal-concurrency-sync = { version = "0.0.5", path = "iceoryx2-pal/concurrency-sync/" }
iceoryx2-pal-posix = { version = "0.0.5", path = "iceoryx2-pal/posix/" }
iceoryx2-pal-configuration = { version = "0.0.5", path = "iceoryx2-pal/configuration/" }

iceoryx2-cal = { version = "0.0.2", path = "iceoryx2-cal" }
iceoryx2-cal = { version = "0.0.5", path = "iceoryx2-cal" }

iceoryx2 = { version = "0.0.2", path = "iceoryx2/" }
iceoryx2 = { version = "0.0.5", path = "iceoryx2/" }

bindgen = { version = "0.65.1" }
bitflags = { version = "1.3.2" }
Expand Down
2 changes: 0 additions & 2 deletions iceoryx2-bb/container/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ iceoryx2-bb-elementary = { workspace = true }
iceoryx2-bb-log = { workspace = true }

[dev-dependencies]
pin-init = { workspace = true }
generic-tests = { workspace = true }
iceoryx2-bb-memory = { workspace = true }
iceoryx2-bb-testing = { workspace = true }
6 changes: 2 additions & 4 deletions iceoryx2-bb/container/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@
//!
//! ```
//! use iceoryx2_bb_container::queue::RelocatableQueue;
//! use iceoryx2_bb_memory::bump_allocator::BumpAllocator;
//! use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
//! use iceoryx2_bb_elementary::relocatable_container::RelocatableContainer;
//! use std::ptr::NonNull;
//!
//! const QUEUE_CAPACITY:usize = 12;
//! const MEM_SIZE: usize = RelocatableQueue::<u128>::const_memory_size(QUEUE_CAPACITY);
//! let mut memory = [0u8; MEM_SIZE];
//!
//! let bump_allocator = BumpAllocator::new(
//! unsafe { NonNull::new_unchecked(memory.as_mut_ptr() as *mut u8) },
//! MEM_SIZE);
//! let bump_allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
//!
//! let queue = unsafe { RelocatableQueue::<u128>::new_uninit(QUEUE_CAPACITY) };
//! unsafe { queue.init(&bump_allocator).expect("queue init failed") };
Expand Down
6 changes: 2 additions & 4 deletions iceoryx2-bb/container/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@
//!
//! ```
//! use iceoryx2_bb_container::vec::Vec;
//! use iceoryx2_bb_memory::bump_allocator::BumpAllocator;
//! use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
//! use iceoryx2_bb_elementary::relocatable_container::RelocatableContainer;
//! use std::ptr::NonNull;
//!
//! const VEC_CAPACITY:usize = 12;
//! const MEM_SIZE: usize = Vec::<u128>::const_memory_size(VEC_CAPACITY);
//! let mut memory = [0u8; MEM_SIZE];
//!
//! let bump_allocator = BumpAllocator::new(
//! unsafe { NonNull::new_unchecked(memory.as_mut_ptr() as *mut u8) },
//! MEM_SIZE);
//! let bump_allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
//!
//! let vec = unsafe { Vec::<u128>::new_uninit(VEC_CAPACITY) };
//! unsafe { vec.init(&bump_allocator).expect("vec init failed") };
Expand Down
15 changes: 5 additions & 10 deletions iceoryx2-bb/container/tests/queue_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use iceoryx2_bb_container::queue::*;
use iceoryx2_bb_memory::{bump_allocator::BumpAllocator, memory::Memory};
use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
use iceoryx2_bb_testing::assert_that;
use pin_init::init_stack;

const SUT_CAPACITY: usize = 128;
type Sut = FixedSizeQueue<usize, SUT_CAPACITY>;

#[test]
fn queue_push_pop_works_with_uninitialized_memory() {
init_stack!(
memory =
Memory::<{ Queue::<usize>::const_memory_size(129_usize) }, BumpAllocator>::new_filled(
0xff,
)
);
let memory = memory.unwrap();
let mut memory = [0u8; 1024];
let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);

let mut sut = unsafe { RelocatableQueue::<usize>::new_uninit(SUT_CAPACITY) };
unsafe { assert_that!(sut.init(memory.allocator()), is_ok) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };

for i in 0..sut.capacity() {
let element = i * 2 + 3;
Expand Down
14 changes: 4 additions & 10 deletions iceoryx2-bb/container/tests/vec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use iceoryx2_bb_container::vec::*;
use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
use iceoryx2_bb_elementary::relocatable_container::RelocatableContainer;
use iceoryx2_bb_memory::{bump_allocator::BumpAllocator, memory::Memory};
use iceoryx2_bb_testing::assert_that;
use pin_init::init_stack;

const SUT_CAPACITY: usize = 128;
type Sut = FixedSizeVec<usize, SUT_CAPACITY>;
Expand Down Expand Up @@ -70,15 +69,10 @@ fn fixed_size_vec_push_pop_works() {

#[test]
fn vec_push_pop_works_with_uninitialized_memory() {
init_stack!(
memory =
Memory::<{ Vec::<usize>::const_memory_size(129_usize) }, BumpAllocator>::new_filled(
0xff,
)
);
let memory = memory.unwrap();
let mut memory = [0u8; 1024];
let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
let mut sut = unsafe { Vec::<usize>::new_uninit(SUT_CAPACITY) };
unsafe { assert_that!(sut.init(memory.allocator()), is_ok) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };

for i in 0..sut.capacity() {
let element = i * 2 + 3;
Expand Down
56 changes: 56 additions & 0 deletions iceoryx2-bb/elementary/src/bump_allocator.rs
Copy link
Member

Choose a reason for hiding this comment

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

Did you forget to commit the deleted bump_allocator from memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elBoberido Nope, the bump allocator in elementary is a simplistic version for internal tests and documentation the real and good one is stored under memory.
The elementary bump allocator has also the tag #[doc(hidden)] with a comment that this is for internal use only.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2023 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{allocator::BaseAllocator, math::align};
use std::sync::atomic::{AtomicUsize, Ordering};

/// Simple BumpAllocator for testing purposes. Do not use this in production. If you are looking
/// for a production ready BumpAllocator use the one from iceoryx2_bb_memory::bump_allocator
#[doc(hidden)]
pub struct BumpAllocator {
start: usize,
pos: AtomicUsize,
}

impl BumpAllocator {
pub fn new(start: usize) -> Self {
Self {
start,
pos: AtomicUsize::new(start),
}
}
}

impl BaseAllocator for BumpAllocator {
fn allocate(
&self,
layout: std::alloc::Layout,
) -> Result<std::ptr::NonNull<[u8]>, crate::allocator::AllocationError> {
let mem = align(self.pos.load(Ordering::Relaxed), layout.align());
self.pos.store(mem + layout.size(), Ordering::Relaxed);

unsafe {
Ok(std::ptr::NonNull::new_unchecked(
std::slice::from_raw_parts_mut(mem as *mut u8, layout.size()),
))
}
}

unsafe fn deallocate(
&self,
_ptr: std::ptr::NonNull<u8>,
_layout: std::alloc::Layout,
) -> Result<(), crate::allocator::DeallocationError> {
self.pos.store(self.start, Ordering::Relaxed);
Ok(())
}
}
1 change: 1 addition & 0 deletions iceoryx2-bb/elementary/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#[macro_use]
pub mod enum_gen;
pub mod allocator;
pub mod bump_allocator;
pub mod lazy_singleton;
pub mod math;
pub mod owning_pointer;
Expand Down
1 change: 0 additions & 1 deletion iceoryx2-bb/lock-free/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tiny-fn = { workspace = true }

[dev-dependencies]
iceoryx2-bb-posix = { workspace = true }
iceoryx2-bb-memory = { workspace = true }
iceoryx2-bb-testing = { workspace = true }
pin-init = { workspace = true }
generic-tests = { workspace = true }
14 changes: 8 additions & 6 deletions iceoryx2-bb/lock-free/src/mpmc/unique_index_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
//! ## Runtime fixed size UniqueIndexSet
//!
//! ```
//! use iceoryx2_bb_memory::heap_allocator::*;
//! use iceoryx2_bb_elementary::bump_allocator::*;
//! use iceoryx2_bb_lock_free::mpmc::unique_index_set::*;
//! use iceoryx2_bb_elementary::relocatable_container::*;
//!
//! const CAPACITY: usize = 128;
//! let heap_allocator = HeapAllocator::new();
//! let mut memory = [0u8; UniqueIndexSet::const_memory_size(CAPACITY)];
//! let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
//!
//! let index_set = unsafe { UniqueIndexSet::new_uninit(CAPACITY) };
//! unsafe { index_set.init(&heap_allocator) }.expect("failed to allocate enough memory");
//! unsafe { index_set.init(&allocator) }.expect("failed to allocate enough memory");
//!
//! let new_index = match unsafe { index_set.acquire() } {
//! None => panic!("Out of indices"),
Expand Down Expand Up @@ -147,15 +148,16 @@ impl Drop for UniqueIndex<'_> {
///
/// ## With a custom allocator
/// ```
/// use iceoryx2_bb_memory::heap_allocator::*;
/// use iceoryx2_bb_elementary::bump_allocator::*;
/// use iceoryx2_bb_lock_free::mpmc::unique_index_set::*;
/// use iceoryx2_bb_elementary::relocatable_container::*;
///
/// const CAPACITY: usize = 128;
/// let heap_allocator = HeapAllocator::new();
/// let mut memory = [0u8; UniqueIndexSet::const_memory_size(CAPACITY)];
/// let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
///
/// let index_set = unsafe { UniqueIndexSet::new_uninit(CAPACITY) };
/// unsafe { index_set.init(&heap_allocator) }.expect("failed to allocate enough memory");
/// unsafe { index_set.init(&allocator) }.expect("failed to allocate enough memory");
///
/// let new_index = match unsafe { index_set.acquire() } {
/// None => panic!("Out of indices"),
Expand Down
15 changes: 4 additions & 11 deletions iceoryx2-bb/lock-free/tests/mpmc_container_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ unsafe impl Send for TestType {}

#[generic_tests::define]
mod mpmc_container {
use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
use iceoryx2_bb_elementary::relocatable_container::RelocatableContainer;
use iceoryx2_bb_lock_free::mpmc::container::*;
use iceoryx2_bb_lock_free::mpmc::unique_index_set::*;
use iceoryx2_bb_memory::bump_allocator::BumpAllocator;
use iceoryx2_bb_memory::memory::Memory;
use iceoryx2_bb_posix::system_configuration::SystemInfo;
use iceoryx2_bb_testing::assert_that;
use pin_init::init_stack;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt::Debug;
Expand Down Expand Up @@ -117,15 +115,10 @@ mod mpmc_container {
>() {
// TestType is the largest test type so it is safe to acquire this memory for every test
// case - hack required since `T` cannot be used in const operations
init_stack!(
memory = Memory::<
{ Container::<crate::TestType>::const_memory_size(129_usize) },
BumpAllocator,
>::new_filled(0xff,)
);
let memory = memory.unwrap();
let mut memory = [0u8; Container::<crate::TestType>::const_memory_size(129_usize)];
let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
let sut = unsafe { Container::<T>::new_uninit(CAPACITY) };
unsafe { assert_that!(sut.init(memory.allocator()), is_ok) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };

let mut stored_indices = vec![];
for i in 0..CAPACITY - 1 {
Expand Down
13 changes: 4 additions & 9 deletions iceoryx2-bb/lock-free/tests/mpmc_unique_index_set_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
use iceoryx2_bb_elementary::relocatable_container::RelocatableContainer;
use iceoryx2_bb_lock_free::mpmc::unique_index_set::*;
use iceoryx2_bb_memory::bump_allocator::BumpAllocator;
use iceoryx2_bb_memory::memory::Memory;
use iceoryx2_bb_posix::system_configuration::SystemInfo;
use iceoryx2_bb_testing::assert_that;
use pin_init::init_stack;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Barrier, Mutex};
use std::thread;
Expand Down Expand Up @@ -101,13 +99,10 @@ fn mpmc_unique_index_set_borrowed_indices_works() {

#[test]
fn mpmc_unique_index_set_acquire_and_release_works_with_uninitialized_memory() {
init_stack!(
memory =
Memory::<{ UniqueIndexSet::const_memory_size(128) }, BumpAllocator>::new_filled(0xff,)
);
let memory = memory.unwrap();
let mut memory = [0u8; UniqueIndexSet::const_memory_size(128)];
let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
let sut = unsafe { UniqueIndexSet::new_uninit(CAPACITY) };
unsafe { assert_that!(sut.init(memory.allocator()), is_ok) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };

let mut ids = vec![];

Expand Down
30 changes: 21 additions & 9 deletions iceoryx2-pal/posix/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@ use std::env;
use std::path::PathBuf;

fn main() {
#[cfg(target_os = "linux")]
println!("cargo:rustc-link-lib=acl");
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
println!("cargo:rustc-link-lib=pthread");

println!("cargo:rerun-if-changed=src/c/posix.h");

let bindings = bindgen::Builder::default()
.header("src/c/posix.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
if std::env::var("DOCS_RS").is_ok() {
println!("cargo:rerun-if-changed=src/c/posix_docs_rs.h");
} else {
#[cfg(target_os = "linux")]
println!("cargo:rustc-link-lib=acl");
println!("cargo:rerun-if-changed=src/c/posix.h");
}

let bindings = if std::env::var("DOCS_RS").is_ok() {
bindgen::Builder::default()
.header("src/c/posix_docs_rs.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings")
} else {
bindgen::Builder::default()
.header("src/c/posix.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings")
};

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
Expand Down
Loading