#pragma once // Spec: SPEC.md NFR-THR-01. Worker threads never touch UI state: they post closures here and the // SDL main thread drains them. Hard cap: kMaxPending closures; overflow drops the oldest and counts it. #include #include #include #include #include namespace dp { class UiQueue { public: static constexpr std::size_t kMaxPending = 4096; static UiQueue& instance(); // Any thread. void post(std::function fn); // Main thread only. Returns the number of closures run (bounded by kMaxPending per call). std::size_t drain(); std::uint64_t dropped() const { return dropped_.load(); } private: std::mutex mutex_; std::deque> items_; std::atomic dropped_{0}; }; } // namespace dp