OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
openswmm::IOThread Class Reference

Producer-consumer IO thread for writing simulation snapshots. More...

#include <IOThread.hpp>

Collaboration diagram for openswmm::IOThread:

Public Member Functions

 IOThread (PluginFactory &factory, std::size_t capacity=DEFAULT_QUEUE_CAPACITY)
 Construct (does NOT start the thread).
 
 ~IOThread ()
 
 IOThread (const IOThread &)=delete
 
IOThreadoperator= (const IOThread &)=delete
 
void start ()
 Start the IO worker thread.
 
void post (SimulationSnapshot snap)
 Post a snapshot to the write queue.
 
void stop ()
 Signal the IO thread to finish and join it.
 
bool running () const noexcept
 True if the thread is running.
 
int tasks_completed () const noexcept
 Number of tasks processed so far.
 
int last_error () const noexcept
 Last error code from a plugin update (0 = no error).
 

Static Public Attributes

static constexpr std::size_t DEFAULT_QUEUE_CAPACITY = 8
 Default maximum queue depth.
 

Detailed Description

Producer-consumer IO thread for writing simulation snapshots.

One IOThread per SWMMEngine instance. Shared with PluginFactory.

Constructor & Destructor Documentation

◆ IOThread() [1/2]

openswmm::IOThread::IOThread ( PluginFactory factory,
std::size_t  capacity = DEFAULT_QUEUE_CAPACITY 
)
explicit

Construct (does NOT start the thread).

Parameters
factoryPlugin factory whose update_all() is called per task.
capacityMaximum number of queued snapshots before post() blocks.

◆ ~IOThread()

openswmm::IOThread::~IOThread ( )
Here is the call graph for this function:

◆ IOThread() [2/2]

openswmm::IOThread::IOThread ( const IOThread )
delete

Member Function Documentation

◆ last_error()

int openswmm::IOThread::last_error ( ) const
inlinenoexcept

Last error code from a plugin update (0 = no error).

◆ operator=()

IOThread & openswmm::IOThread::operator= ( const IOThread )
delete

◆ post()

void openswmm::IOThread::post ( SimulationSnapshot  snap)

Post a snapshot to the write queue.

Blocks if the queue is at capacity. Thread-safe.

Parameters
snapSnapshot to write (moved into the queue).

◆ running()

bool openswmm::IOThread::running ( ) const
inlinenoexcept

True if the thread is running.

◆ start()

void openswmm::IOThread::start ( )

Start the IO worker thread.

Precondition
Thread must not already be running.

◆ stop()

void openswmm::IOThread::stop ( )

Signal the IO thread to finish and join it.

Waits for all queued tasks to be processed, then joins the thread. Safe to call even if start() was never called.

Here is the caller graph for this function:

◆ tasks_completed()

int openswmm::IOThread::tasks_completed ( ) const
inlinenoexcept

Number of tasks processed so far.

Member Data Documentation

◆ DEFAULT_QUEUE_CAPACITY

constexpr std::size_t openswmm::IOThread::DEFAULT_QUEUE_CAPACITY = 8
staticconstexpr

Default maximum queue depth.


The documentation for this class was generated from the following files: