59#ifndef OPENSWMM_ENGINE_IO_THREAD_HPP
60#define OPENSWMM_ENGINE_IO_THREAD_HPP
66#include <condition_variable>
171 bool running() const noexcept {
return running_.load(std::memory_order_relaxed); }
177 return tasks_completed_.load(std::memory_order_relaxed);
183 int last_error() const noexcept {
return last_error_.load(std::memory_order_relaxed); }
193 const std::size_t capacity_;
196 std::queue<WriteTask> queue_;
197 mutable std::mutex mutex_;
198 mutable std::condition_variable cv_idle_;
199 bool writing_ =
false;
200 std::condition_variable cv_not_full_;
201 std::condition_variable cv_not_empty_;
202 std::atomic<bool> stop_flag_{
false};
203 std::atomic<bool> running_{
false};
204 std::atomic<int> tasks_completed_{0};
205 std::atomic<int> last_error_{0};
206 int next_sequence_ = 0;
Ring-buffer task descriptor for the IO thread (Phase 5, R17).
void stop()
Signal the IO thread to finish and join it.
Definition IOThread.cpp:122
int tasks_completed() const noexcept
Number of tasks processed so far.
Definition IOThread.hpp:176
static constexpr std::size_t DEFAULT_QUEUE_CAPACITY
Default maximum queue depth.
Definition IOThread.hpp:94
void start()
Start the IO worker thread.
Definition IOThread.cpp:91
IOThread(PluginFactory &factory, std::size_t capacity=DEFAULT_QUEUE_CAPACITY)
Construct (does NOT start the thread).
Definition IOThread.cpp:80
~IOThread()
Stop/drain and join the native worker before releasing queue storage. Can block for plugin writes; de...
Definition IOThread.cpp:83
bool running() const noexcept
True if the thread is running.
Definition IOThread.hpp:171
void post(SimulationSnapshot snap)
Post a snapshot to the write queue.
Definition IOThread.cpp:102
int last_error() const noexcept
Last error code from a plugin update (0 = no error).
Definition IOThread.hpp:183
IOThread & operator=(const IOThread &)=delete
Disable assignment of thread/queue ownership.
IOThread(const IOThread &)=delete
Disable copying a live thread, queue and borrowed factory association.
int flush() const
Definition IOThread.cpp:136
Manages plugin discovery, loading, and lifecycle for one engine instance.
Definition PluginFactory.hpp:91
Definition ExchangeLaw.hpp:60
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:123