PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
roster_pass_work.hpp
Go to the documentation of this file.
1#ifndef PINEFORGE_SOURCE_ROSTER_PASS_WORK_HPP
2#define PINEFORGE_SOURCE_ROSTER_PASS_WORK_HPP
3
4#if defined(PINEFORGE_ROSTER_PASS_OBSERVER)
5#include <cstdint>
6
7// Test-build observation only. No decision, receipt or hash reads this
8// overlay, and ordinary builds define neither storage nor observer code.
9namespace pineforge::source::roster_pass_work {
10struct Counts {
11 std::uint64_t roster_cohort_visits = 0;
12 std::uint64_t due_passes = 0;
13};
14inline thread_local Counts* observer = nullptr;
15
16inline void note(std::uint64_t Counts::*field) noexcept {
17 if (observer) ++(observer->*field);
18}
19
20class Scope {
21public:
22 explicit Scope(Counts& counts) noexcept : previous_(observer) { observer = &counts; }
23 ~Scope() { observer = previous_; }
24 Scope(const Scope&) = delete;
25 Scope& operator=(const Scope&) = delete;
26private:
27 Counts* previous_;
28};
29} // namespace pineforge::source::roster_pass_work
30
31#define PF_ROSTER_PASS_WORK(field) \
32 ::pineforge::source::roster_pass_work::note( \
33 &::pineforge::source::roster_pass_work::Counts::field)
34#else
35#define PF_ROSTER_PASS_WORK(field) ((void)0)
36#endif
37
38#endif // PINEFORGE_SOURCE_ROSTER_PASS_WORK_HPP