|
CIRCT 23.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 () | |
| 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) | |
| 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. | |
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 240 of file Accelerator.h.
| esi::AcceleratorServiceThread::AcceleratorServiceThread | ( | ) |
Definition at line 379 of file Accelerator.cpp.
References start().
|
virtual |
Definition at line 381 of file Accelerator.cpp.
References stop().
|
explicitprotected |
Definition at line 380 of file Accelerator.cpp.
|
virtual |
When there's data on any of the listenPorts, call the callback.
Callable from any thread.
Definition at line 441 of file Accelerator.cpp.
|
virtual |
|
virtual |
Add a task to be invoked on every service iteration.
Callable from any thread.
Definition at line 452 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 404 of file Accelerator.cpp.
References assert(), listeners, m, and taskList.
Referenced by loop().
|
protectedvirtual |
Start the service thread.
Called by the default constructor. Spawns a std::thread which invokes loop() via virtual dispatch.
Definition at line 383 of file Accelerator.cpp.
Referenced by AcceleratorServiceThread().
|
virtual |
Instruct the service thread to stop running.
Definition at line 387 of file Accelerator.cpp.
Referenced by ~AcceleratorServiceThread().
|
protected |
Map of read ports to callbacks and their in-flight async reads.
Definition at line 294 of file Accelerator.h.
Referenced by addListener(), and poll().
|
protected |
Protects listeners and taskList.
Definition at line 288 of file Accelerator.h.
Referenced by addListener(), addTask(), and poll().
|
protected |
The thread running loop().
Definition at line 285 of file Accelerator.h.
|
protected |
Set to true to request the service loop to exit.
Definition at line 283 of file Accelerator.h.
|
protected |
Tasks which should be called on every loop iteration.
Definition at line 297 of file Accelerator.h.