Skip to main content

iceoryx2_bb_testing/
lifetime_tracker.rs

1// Copyright (c) 2026 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
12
13use iceoryx2_bb_elementary_traits::zero_copy_send::ZeroCopySend;
14
15#[cfg(feature = "std")]
16use std::sync::MutexGuard;
17
18#[cfg(not(feature = "std"))]
19use iceoryx2_pal_concurrency_sync::spin_lock::SpinLockGuard as MutexGuard;
20
21#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
22#[repr(transparent)]
23pub struct LifetimeTracker(internal::LifetimeTracker);
24
25impl core::ops::Deref for LifetimeTracker {
26    type Target = internal::LifetimeTracker;
27
28    fn deref(&self) -> &Self::Target {
29        &self.0
30    }
31}
32
33impl core::ops::DerefMut for LifetimeTracker {
34    fn deref_mut(&mut self) -> &mut Self::Target {
35        &mut self.0
36    }
37}
38
39impl LifetimeTracker {
40    pub fn new() -> Self {
41        Self(internal::LifetimeTracker::new())
42    }
43
44    pub fn new_with_value(value: usize) -> Self {
45        Self(internal::LifetimeTracker::new_with_value(value))
46    }
47
48    pub fn start_tracking() -> MutexGuard<'static, internal::LifetimeTrackingState> {
49        internal::LifetimeTracker::start_tracking()
50    }
51}
52
53unsafe impl ZeroCopySend for LifetimeTracker {}
54
55mod internal {
56    pub use iceoryx2_pal_testing::lifetime_tracker::LifetimeTracker;
57    pub use iceoryx2_pal_testing::lifetime_tracker::LifetimeTrackingState;
58}