1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2025 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
//! Helper struct to tag things cyclicly. For instance in an event loop where
//! all untagged things shall be removed from a list.
//!
//! ```
//! use iceoryx2_bb_elementary::cyclic_tagger::*;
//!
//! struct MyThing {
//! some_property: u64,
//! tag: Tag,
//! }
//!
//! impl Taggable for MyThing {
//! fn tag(&self) -> &Tag {
//! &self.tag
//! }
//! }
//!
//! let mut my_things: Vec<MyThing> = Vec::new();
//!
//! let global_tagger = CyclicTagger::new();
//! // in event loop
//! global_tagger.next_cycle();
//! for thing in &my_things {
//! // tag only things with property 123
//! if thing.some_property == 123 {
//! global_tagger.tag(&thing.tag);
//! }
//! }
//!
//! // add a new thing
//! my_things.push(MyThing { some_property: 456, tag: global_tagger.create_tag() });
//!
//! // remove all non-taged things
//! my_things.retain(|thing| thing.was_tagged_by(&global_tagger));
//! ```
use AtomicU8;
use Ordering;
/// The [`CyclicTagger`] can tag any object that implements [`Taggable`]. When tagging elements
/// cyclicly the cycle shall always start with [`CyclicTagger::next_cycle()`].
;
/// This tracks the mark of the [`CyclicTagger`] when it is tagged.
;
/// Identifies structs that can be tagged by the [`CyclicTagger`].