43 [[nodiscard]]
Duration delay() const noexcept {
return delay_; }
50 self->
at(self->clock_->now() + self->delay_, m);
63 driver_thread_ = std::this_thread::get_id();
67 if (std::this_thread::get_id() == self->driver_thread_) {
68 self->
at(self->clock_->now() + self->delay_, m);
82 using Refill = Timestamp (*)(
void* ctx, Timestamp due);
83 void set_refill(
const SimClock& clock,
void* ctx,
Refill refill, Timestamp first)
noexcept {
84 refill_clock_ = &clock;
87 refill_gate_ =
Timestamp{std::numeric_limits<std::int64_t>::min()};
93 const std::lock_guard<std::mutex> lock(inbox_mutex_);
95 inbox_pending_.store(
true, std::memory_order_release);
100 if (FASTMM_UNLIKELY(refill_ !=
nullptr) && refill_next_ !=
Timestamp::max() &&
101 refill_clock_->
now() >= refill_gate_) {
102 refill_gate_ = refill_next_;
103 refill_next_ = refill_(refill_ctx_, refill_next_);
105 if (FASTMM_LIKELY(!inbox_pending_.load(std::memory_order_acquire)))
return;
106 const std::lock_guard<std::mutex> lock(inbox_mutex_);
110 inbox_pending_.store(
false, std::memory_order_release);
113 [[nodiscard]]
bool empty() const noexcept {
return queue_.empty(); }
114 [[nodiscard]] std::size_t
size() const noexcept {
return queue_.size(); }
123 queue_.erase(queue_.begin());
128 std::multimap<std::int64_t, ParamUpdateMsg> queue_;
130 const SimClock* clock_ =
nullptr;
131 std::thread::id driver_thread_{};
132 const SimClock* refill_clock_ =
nullptr;
133 void* refill_ctx_ =
nullptr;
135 Timestamp refill_gate_{};
137 std::mutex inbox_mutex_;
138 std::vector<ParamUpdateMsg> inbox_;
139 std::atomic<bool> inbox_pending_{
false};
Deterministic clock for sim/backtest/replay. 1 cycle == 1 ns.
Definition time.hpp:338
Timestamp now() const noexcept
Definition time.hpp:342
Definition param_schedule.hpp:38
void set_delay(Duration d) noexcept
Added to the time of updates that arrive through sink() (the slow tier's delay).
Definition param_schedule.hpp:44
Duration delay() const noexcept
Definition param_schedule.hpp:45
Timestamp next_ts() const noexcept
The earliest delivery time (Timestamp::max() when empty).
Definition param_schedule.hpp:118
ParamSink threaded_sink(const SimClock &clock) noexcept
Like sink(), for a schedule that other threads publish to as well: an update from the thread that cal...
Definition param_schedule.hpp:63
void set_refill(const SimClock &clock, void *ctx, Refill refill, Timestamp first) noexcept
Definition param_schedule.hpp:85
void collect()
Driver thread: schedules the posted updates delay() after the clock's time (the clock passed to sink(...
Definition param_schedule.hpp:101
Timestamp(*)(void *ctx, Timestamp due) Refill
refill(ctx, due) adds the updates due at due (at() with that time) and returns when the next ones are...
Definition param_schedule.hpp:84
void post(const ParamUpdateMsg &m)
Any thread: holds m until the next collect().
Definition param_schedule.hpp:94
bool empty() const noexcept
Definition param_schedule.hpp:115
ParamSink sink(const SimClock &clock) noexcept
A ParamPublisher sink: each update is delivered delay() after clock's time at the publish.
Definition param_schedule.hpp:47
ParamUpdateMsg pop() noexcept
Removes the earliest update; its recv_ts is the delivery time.
Definition param_schedule.hpp:122
std::size_t size() const noexcept
Definition param_schedule.hpp:116
void at(Timestamp ts, const ParamUpdateMsg &m)
Delivers m at ts; updates with the same time keep the order they were added in.
Definition param_schedule.hpp:41
Event bus message structs (5.5).
Definition strategy_harness.hpp:40
ParamPublisher: builds ParamUpdate messages for a running engine, off the engine thread (ADR-0013).
Where a built update goes; push returns false when it was not accepted (full).
Definition param_publisher.hpp:49
New strategy parameter values (ADR-0013): up to kMaxFields (field index, raw value) pairs,...
Definition messages.hpp:795
EventHeader hdr
Definition messages.hpp:813
std::int64_t ns
Definition time.hpp:46
static constexpr Timestamp max() noexcept
Definition time.hpp:56