Skip to content

Commit 373a1f3

Browse files
committed
[eclipse-iceoryx#139] Add bitset as id tracker
1 parent b5eab2a commit 373a1f3

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

iceoryx2-cal/src/event/id_tracker/bitset.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,34 @@
1111
// SPDX-License-Identifier: Apache-2.0 OR MIT
1212

1313
use iceoryx2_bb_lock_free::mpmc::bit_set::RelocatableBitSet;
14+
use iceoryx2_bb_log::fail;
1415

1516
use super::IdTracker;
16-
use crate::event::TriggerId;
17+
use crate::event::{NotifierNotifyError, TriggerId};
1718

18-
//impl IdTracker for RelocatableBitSet {
19-
// fn set(&self, id: TriggerId) {
20-
// self.set(id)
21-
// }
22-
//}
19+
impl IdTracker for RelocatableBitSet {
20+
fn trigger_id_max(&self) -> TriggerId {
21+
TriggerId::new(self.capacity() as u64)
22+
}
23+
24+
fn add(&self, id: TriggerId) -> Result<(), NotifierNotifyError> {
25+
if self.trigger_id_max() >= id {
26+
fail!(from self, with NotifierNotifyError::TriggerIdOutOfBounds,
27+
"Unable to set bit {:?} since it is out of bounds.", id);
28+
}
29+
self.set(id.as_u64() as usize);
30+
31+
Ok(())
32+
}
33+
34+
fn acquire_all<F: FnMut(TriggerId)>(&self, mut callback: F) {
35+
self.reset_all(|bit_index| callback(TriggerId::new(bit_index as u64)))
36+
}
37+
38+
fn acquire(&self) -> Option<TriggerId> {
39+
match self.reset_next() {
40+
Some(id) => Some(TriggerId::new(id as u64)),
41+
None => None,
42+
}
43+
}
44+
}

iceoryx2-cal/src/event/id_tracker/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
pub mod bitset;
1414
pub mod queue;
1515

16-
use super::TriggerId;
16+
use super::{NotifierNotifyError, TriggerId};
1717
use iceoryx2_bb_elementary::relocatable_container::RelocatableContainer;
1818

1919
pub trait IdTracker: RelocatableContainer {
2020
fn trigger_id_max(&self) -> TriggerId;
21-
fn set(&self, id: TriggerId);
22-
fn reset_next(&self) -> TriggerId;
23-
fn reset_all<F: FnMut(TriggerId)>(&self, callback: F);
21+
fn add(&self, id: TriggerId) -> Result<(), NotifierNotifyError>;
22+
fn acquire(&self) -> Option<TriggerId>;
23+
fn acquire_all<F: FnMut(TriggerId)>(&self, callback: F);
2424
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information regarding copyright ownership.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Apache Software License 2.0 which is available at
8+
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9+
// which is available at https://opensource.org/licenses/MIT.
10+
//
11+
// SPDX-License-Identifier: Apache-2.0 OR MIT

iceoryx2-cal/src/event/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub use iceoryx2_bb_system_types::path::Path;
2424
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
2525
pub enum NotifierNotifyError {
2626
FailedToDeliverSignal,
27+
TriggerIdOutOfBounds,
2728
InternalFailure,
2829
}
2930

0 commit comments

Comments
 (0)