osom_asm_x86_64/models/
label.rs1use core::sync::atomic::{AtomicU32, Ordering};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4#[must_use]
5#[repr(transparent)]
6pub struct Label {
7 value: u32,
8}
9
10static LABEL_COUNTER: AtomicU32 = AtomicU32::new(0);
11
12#[must_use]
13fn get_next_label_value() -> u32 {
14 loop {
15 let value = LABEL_COUNTER.load(Ordering::SeqCst);
16
17 assert!(value != u32::MAX, "Label counter overflow.");
18
19 if LABEL_COUNTER
20 .compare_exchange(value, value + 1, Ordering::SeqCst, Ordering::SeqCst)
21 .is_ok()
22 {
23 return value;
24 }
25 }
26}
27
28impl Label {
29 #[inline(always)]
30 pub fn new() -> Self {
31 Self {
32 value: get_next_label_value(),
33 }
34 }
35}
36
37impl Default for Label {
38 #[inline(always)]
39 fn default() -> Self {
40 Self::new()
41 }
42}