Construct a new `VMClock` instance. Upon creation the VMClock shared memory page existence is verified, a reader is constructed, and the memory page is read to determine the current state of the clock.
(
vmclock_shm_path: &str,
ctrl_receiver: mpsc::Receiver<ControlRequest>,
clock_disruption_sender: watch::Sender<ClockDisruptionEvent>,
)
| 81 | let previous_shm_body = *reader.snapshot()?; |
| 82 | |
| 83 | self.transition_to_running(Running { |
| 84 | reader, |
| 85 | previous_shm_body, |
| 86 | }); |
| 87 | |
| 88 | Ok(()) |
| 89 | } |
| 90 | |
| 91 | /// Returns a clone of the shared [`State`] handle. |
| 92 | pub fn shared_state(&self) -> Arc<Mutex<State>> { |
| 93 | self.shared_state.clone() |
| 94 | } |
| 95 | |
| 96 | /// Returns the last VMClock read's disruption marker, or 0 if the VMClock is not running. |
| 97 | pub fn last_disruption_marker(&self) -> u64 { |
| 98 | match &self.internal_state { |
| 99 | InternalState::Running(running) => running.previous_shm_body.disruption_marker, |
| 100 | InternalState::Failed => 0, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /// VMClock runner. |
| 105 | /// |
| 106 | /// When `Running`, reads the VMClock shared memory file and sends clock disruption events to |
| 107 | /// channel subscribers. If a sample ever errors out, the task transitions to `Failed` and |
| 108 | /// continues running in that state. |
| 109 | /// |
| 110 | /// When `Failed`, logs an error every [`VMCLOCK_FAILED_LOG_INTERVAL`] stating the VMClock was |