|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Runs one dynamic state's script on its own thread. More...
#include <ScriptRunner.hpp>
Public Types | |
| using | Clock = std::chrono::steady_clock |
Public Member Functions | |
| ScriptRunner ()=default | |
| ~ScriptRunner () | |
| ScriptRunner (const ScriptRunner &)=delete | |
| ScriptRunner & | operator= (const ScriptRunner &)=delete |
| void | start (const DynamicState &ds, ScriptEnv env) |
| Begin running ds. | |
| void | stop () |
| Cancel and reap. | |
| bool | isActive () const |
| double | elapsedSeconds () const |
| Seconds since start(), which is what elapsed() reports. | |
Private Member Functions | |
| void | run (DynamicState ds, ScriptEnv env) |
Private Attributes | |
| std::mutex | mtx_ |
| std::condition_variable | cv_ |
| std::thread | thread_ |
| std::atomic< bool > | active_ {false} |
| std::atomic< bool > | stop_ {false} |
| Clock::time_point | started_at_ {} |
Runs one dynamic state's script on its own thread.
Modelled on HoldTimer, and for its reasons rather than by analogy:
The stop flag is checked at every statement boundary, inside every wait, and at the top of every loop iteration, so a transition or an abort preempts a running script in well under a millisecond rather than at the next statement.
Because it owns a thread, the interpreter is a plain recursive tree walk — the thread IS the continuation. No resumable VM, no stepped scheduler.
Definition at line 79 of file ScriptRunner.hpp.
| using sequencer::ScriptRunner::Clock = std::chrono::steady_clock |
Definition at line 81 of file ScriptRunner.hpp.
|
default |
Referenced by operator=(), and ScriptRunner().
| sequencer::ScriptRunner::~ScriptRunner | ( | ) |
Definition at line 61 of file ScriptRunner.cpp.
References stop().
|
delete |
References ScriptRunner().
| double sequencer::ScriptRunner::elapsedSeconds | ( | ) | const |
Seconds since start(), which is what elapsed() reports.
0 when not running.
Definition at line 65 of file ScriptRunner.cpp.
References active_, lk, mtx_, and started_at_.
|
inline |
Definition at line 99 of file ScriptRunner.hpp.
References active_.
|
delete |
References ScriptRunner().
|
private |
Definition at line 486 of file ScriptRunner.cpp.
References active_, cv_, mtx_, sequencer::StateMachine::name(), sequencer::DynamicState::program, sequencer::DynamicState::return_target, sequencer::ScriptEnv::state_name, stop_, sequencer::DynamicState::timeout_ms, sequencer::DynamicState::timeout_target, fsw::script::ScriptProgram::top_begin, fsw::script::ScriptProgram::top_end, and sequencer::ScriptEnv::transition.
Referenced by start().
| void sequencer::ScriptRunner::start | ( | const DynamicState & | ds, |
| ScriptEnv | env ) |
Begin running ds.
Supersedes anything already running (which is stopped first).
Definition at line 72 of file ScriptRunner.cpp.
References active_, lk, mtx_, sequencer::DynamicState::name, run(), started_at_, stop(), stop_, and thread_.
| void sequencer::ScriptRunner::stop | ( | ) |
Cancel and reap.
Safe when nothing is running, and safe to call from the transition the script itself requested — that path detaches rather than self-joining, which would be a std::terminate.
Definition at line 101 of file ScriptRunner.cpp.
References active_, cv_, lk, mtx_, stop_, and thread_.
Referenced by start(), and ~ScriptRunner().
|
private |
Definition at line 112 of file ScriptRunner.hpp.
Referenced by elapsedSeconds(), isActive(), run(), start(), and stop().
|
private |
Definition at line 110 of file ScriptRunner.hpp.
|
mutableprivate |
Definition at line 109 of file ScriptRunner.hpp.
Referenced by elapsedSeconds(), run(), start(), and stop().
|
private |
Definition at line 114 of file ScriptRunner.hpp.
Referenced by elapsedSeconds(), and start().
|
private |
Definition at line 113 of file ScriptRunner.hpp.
|
private |
Definition at line 111 of file ScriptRunner.hpp.