sectorsync_core/
barrier.rs1use crate::ids::{BarrierId, InstanceId, StationId, Tick};
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum BarrierScope {
8 Instance(InstanceId),
10 Station(StationId),
12}
13
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16pub enum CommandQueueMode {
17 Buffer,
19 Reject,
21 Drain,
23}
24
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
27pub enum BarrierState {
28 Running,
30 Requested,
32 WaitingTickBoundary,
34 Frozen,
36 Resuming,
38}
39
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42pub struct RuntimeBarrier {
43 pub id: BarrierId,
45 pub scope: BarrierScope,
47 pub requested_at: Tick,
49 pub target_tick: Tick,
51 pub command_mode: CommandQueueMode,
53 pub state: BarrierState,
55}
56
57impl RuntimeBarrier {
58 pub const fn requested(
60 id: BarrierId,
61 scope: BarrierScope,
62 requested_at: Tick,
63 target_tick: Tick,
64 command_mode: CommandQueueMode,
65 ) -> Self {
66 Self {
67 id,
68 scope,
69 requested_at,
70 target_tick,
71 command_mode,
72 state: BarrierState::Requested,
73 }
74 }
75
76 pub fn wait_for_tick_boundary(&mut self) {
78 self.state = BarrierState::WaitingTickBoundary;
79 }
80
81 pub fn freeze(&mut self) {
83 self.state = BarrierState::Frozen;
84 }
85
86 pub fn resume(&mut self) {
88 self.state = BarrierState::Resuming;
89 }
90
91 pub fn finish(&mut self) {
93 self.state = BarrierState::Running;
94 }
95}