|
CIRCT 24.0.0git
|
Background thread which services various requests. More...
#include <Accelerator.h>

Classes | |
| struct | DeferStart |
| Tag type used to construct the base class without starting the service thread. More... | |
Public Member Functions | |
| AcceleratorServiceThread (Context *ctxt=nullptr) | |
| Exceptions thrown by listener callbacks and tasks are reported to ctxt's logger if given (otherwise to stderr) rather than stopping the thread. | |
| virtual | ~AcceleratorServiceThread () |
| virtual void | addListener (std::initializer_list< ReadChannelPort * > listenPorts, std::function< void(ReadChannelPort *, MessageData)> callback) |
| When there's data on any of the listenPorts, call the callback. | |
| virtual void | addPoll (HWModule &module) |
| Poll this module. | |
| virtual void | addTask (std::function< void(void)> task) |
| Add a task to be invoked on every service iteration. | |
| virtual void | stop () |
| Instruct the service thread to stop running. | |
Protected Member Functions | |
| AcceleratorServiceThread (DeferStart, Context *ctxt=nullptr) | |
| virtual void | start () |
| Start the service thread. | |
| virtual void | loop () |
| The main service loop. | |
| virtual void | poll () |
| Perform a single iteration of servicing: drain any ready listener futures, invoke their callbacks, and run all registered tasks. | |
Protected Attributes | |
| std::atomic< bool > | shutdown {false} |
| Set to true to request the service loop to exit. | |
| std::thread | me |
| The thread running loop(). | |
| std::mutex | m |
| Protects listeners and taskList. | |
| std::map< ReadChannelPort *, std::pair< std::function< void(ReadChannelPort *, MessageData)>, std::future< MessageData > > > | listeners |
| Map of read ports to callbacks and their in-flight async reads. | |
| std::vector< std::function< void(void)> > | taskList |
| Tasks which should be called on every loop iteration. | |
Private Member Functions | |
| void | runReportingErrors (const std::function< void()> &f) |
| Run f, reporting any exception it throws. | |
Private Attributes | |
| Context * | ctxt |
| Looked up through the context each time, since it may be replaced. | |
Background thread which services various requests.
Currently, it listens on ports and calls callbacks for incoming messages on said ports.
All methods are virtual so that users may provide their own service thread implementation. Overriders can reuse the default implementation piecemeal by invoking the base-class methods – typically overriding poll() (to change what a single iteration does) or loop() (to change how iterations are scheduled). Subclasses that need to run their own loop() from the outset should use the protected DeferStart constructor to prevent the base class from starting the thread, then call start() themselves.
Definition at line 241 of file Accelerator.h.
| esi::AcceleratorServiceThread::AcceleratorServiceThread | ( | Context * | ctxt = nullptr | ) |
Exceptions thrown by listener callbacks and tasks are reported to ctxt's logger if given (otherwise to stderr) rather than stopping the thread.
Definition at line 379 of file Accelerator.cpp.
|
virtual |
Definition at line 384 of file Accelerator.cpp.
References stop().
|
explicitprotected |
Definition at line 382 of file Accelerator.cpp.
References ctxt.
|
virtual |
When there's data on any of the listenPorts, call the callback.
Callable from any thread.
Definition at line 462 of file Accelerator.cpp.
|
virtual |
|
virtual |
Add a task to be invoked on every service iteration.
Callable from any thread.
Definition at line 473 of file Accelerator.cpp.
Referenced by addPoll().
|
protectedvirtual |
|
protectedvirtual |
Perform a single iteration of servicing: drain any ready listener futures, invoke their callbacks, and run all registered tasks.
Overriders can invoke this from a custom loop to reuse the default servicing behavior.
Definition at line 407 of file Accelerator.cpp.
References assert(), listeners, m, runReportingErrors(), and taskList.
Referenced by loop().
|
private |
Run f, reporting any exception it throws.
Definition at line 441 of file Accelerator.cpp.
References ctxt.
Referenced by poll().
|
protectedvirtual |
Start the service thread.
Called by the default constructor. Spawns a std::thread which invokes loop() via virtual dispatch.
Definition at line 386 of file Accelerator.cpp.
Referenced by AcceleratorServiceThread().
|
virtual |
Instruct the service thread to stop running.
Definition at line 390 of file Accelerator.cpp.
Referenced by ~AcceleratorServiceThread().
|
private |
Looked up through the context each time, since it may be replaced.
Definition at line 308 of file Accelerator.h.
Referenced by AcceleratorServiceThread(), AcceleratorServiceThread(), esiaccel.accelerator.AcceleratorConnection::manifest(), and runReportingErrors().
|
protected |
Map of read ports to callbacks and their in-flight async reads.
Definition at line 298 of file Accelerator.h.
Referenced by addListener(), and poll().
|
protected |
Protects listeners and taskList.
Definition at line 292 of file Accelerator.h.
Referenced by addListener(), addTask(), and poll().
|
protected |
The thread running loop().
Definition at line 289 of file Accelerator.h.
|
protected |
Set to true to request the service loop to exit.
Definition at line 287 of file Accelerator.h.
|
protected |
Tasks which should be called on every loop iteration.
Definition at line 301 of file Accelerator.h.