Skip to content

Commit 6879380

Browse files
committed
Implement identifiers for clock and link.
1 parent 10e9573 commit 6879380

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

statime-base/src/identifiers.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use core::sync::atomic::AtomicUsize;
2+
3+
/// Unique identifier for a clock
4+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
5+
pub struct ClockId(usize);
6+
7+
impl ClockId {
8+
/// Get a new identifier for a clock.
9+
pub fn new() -> ClockId {
10+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
11+
ClockId(COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
12+
}
13+
}
14+
15+
/// Unique identifier for a clock
16+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
17+
pub struct LinkId(usize);
18+
19+
impl LinkId {
20+
/// Get a new identifier for a clock.
21+
pub fn new() -> LinkId {
22+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
23+
LinkId(COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
24+
}
25+
}

statime-base/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Base types and traits for time management.
22
#![no_std]
33

4+
mod identifiers;
45
mod time_types;
6+
7+
pub use identifiers::*;
58
pub use time_types::*;
69

710
#[cfg(feature = "std")]

0 commit comments

Comments
 (0)