|
RTC Toolkit 5.1.0
|
Base class for Data Task computations. More...
#include <rtctk/dataTask/computationBase.hpp>
Public Types | |
| enum class | State : uint8_t { RUNNING , IDLE , ERROR , OFF } |
| Current state of the worker thread. More... | |
| using | TopicType = TopicTypeX |
| using | ServiceContainer = rtctk::componentFramework::ServiceContainer |
| using | ComponentMetricsIf = rtctk::componentFramework::ComponentMetricsIf |
Public Member Functions | |
| ComputationBase (ServiceContainer &services, const std::string &shm_name, size_t to_read, size_t to_skip, std::chrono::milliseconds sample_timeout, std::optional< numapp::NumaPolicies > thread_policies) | |
| Constructor. | |
| virtual | ~ComputationBase ()=default |
| Destructor. | |
| void | SetSamplesToRead (size_t value) |
| Sets the number of samples to read. | |
| size_t | GetSamplesToRead () const |
| Gets the number of samples to read. | |
| void | SetSamplesToSkip (size_t value) |
| Sets the number of samples to skip. | |
| size_t | GetSamplesToSkip () const |
| Gets the number of samples to skip. | |
| void | Spawn () |
| Spawns the worker thread (sync method). | |
| void | Join () |
| Terminates the worker thread (sync method). | |
| void | Run (std::optional< size_t > cycles=std::nullopt) |
| Commands the worker thread to perform number of computation cycles (async method). | |
| void | RunOnceSync (std::optional< std::chrono::milliseconds > poll_interval=std::nullopt) |
| Commands the worker thread to perform a single computation cycle (sync method). | |
| void | Idle () |
| Commands the worker thread to stop performing computation cycles (async method). | |
| State | GetState () const |
| Returns the current state of the worker thread. | |
| size_t | GetCycles () const |
| Retrieves number of computation cycles performed since running. | |
| void | CheckErrors () |
| Checks for errors in the worker thread and rethrows them to the caller. | |
Protected Member Functions | |
| virtual void | OnThreadStart () |
| Optional user-hook called after worker thread started and reader was created. | |
| virtual void | OnCycleStart (size_t to_read) |
| Optional user-hook called immediately before a read-cycle from SHM starts. | |
| virtual void | CopyData (size_t sample_idx, const TopicType &sample) noexcept=0 |
| User-hook used to copy data of a single computation cycle into user-owned sample buffer. | |
| virtual void | Compute ()=0 |
| User-hook to perform a computation cycle. | |
| virtual void | Publish ()=0 |
| User-hook to publish a computation result. | |
Base class for Data Task computations.
This class will take care of reading data from shared memory and then invoking user-defined methods to accumulate data and then perform a computation.
Both continuous and on-demand computations are supported.
| TopicTypeX | The shared memory queue topic. |
| ReaderType | Type of IPCQ reader to be used defaults to ipcq::Reader<TopicTypeX>. |
| using rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::ComponentMetricsIf = rtctk::componentFramework::ComponentMetricsIf |
| using rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::ServiceContainer = rtctk::componentFramework::ServiceContainer |
| using rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::TopicType = TopicTypeX |
|
strong |
|
inline |
Constructor.
| services | Service container object to get access to monitoring metrics or OLDB. |
| shm_name | Name of the shared memory queue. |
| to_read | Number of samples to read per cycle. |
| to_skip | Number of samples to skip per cycle. |
| sample_timeout | Maximum time to wait for a single cycle until error. |
| thread_policies | Used to set CPU or memory policy. |
|
virtualdefault |
Destructor.
Note, we cannot call Join in here since this will result in virtual methods being called when the derived class has already been destroyed. Therefore, do not forget to call Join() in your derived class destructor in oder to properly terminate the worker thread.
|
inline |
Checks for errors in the worker thread and rethrows them to the caller.
Useful for detecting async errors in states RUNNING or IDLE.
|
protectedpure virtual |
User-hook to perform a computation cycle.
Duration is automatically measured and published via ComponentMetrics service.
|
protectedpure virtualnoexcept |
User-hook used to copy data of a single computation cycle into user-owned sample buffer.
Duration is automatically measured and published via ComponentMetrics service.
|
inline |
Retrieves number of computation cycles performed since running.
Useful for waiting after async command methods (Run, Idle).
|
inline |
Gets the number of samples to read.
|
inline |
Gets the number of samples to skip.
|
inline |
Returns the current state of the worker thread.
Useful for waiting after async command methods (Run, Idle).
|
inline |
Commands the worker thread to stop performing computation cycles (async method).
State IDLE is entered where the shared memory queue is continuously being reset.
|
inline |
Terminates the worker thread (sync method).
Once joined the worker thread will be in the OFF state.
|
inlineprotectedvirtual |
Optional user-hook called immediately before a read-cycle from SHM starts.
Useful for resizing the sample buffer in case it can change dynamically.
|
inlineprotectedvirtual |
Optional user-hook called after worker thread started and reader was created.
Useful for GPU computations to initialise the GPU in the worker thread.
|
protectedpure virtual |
User-hook to publish a computation result.
Duration is automatically measured and published via ComponentMetrics service.
|
inline |
Commands the worker thread to perform number of computation cycles (async method).
State RUNNING is entered and the shared memory queue is read and computations are invoked. Once the requested number of cycles are performed the worker thread auto-transitions to state IDLE.
| cycles | Number of computation cycles to perform (default no limit on cycles). |
|
inline |
Commands the worker thread to perform a single computation cycle (sync method).
This method will unblock once one cycle has been completed or an error occurs.
| poll_interval | Time to wait between checking for completion. |
|
inline |
Sets the number of samples to read.
This is useful if samples to read is a dynamic configuration parameter that can change after class construction.
|
inline |
Sets the number of samples to skip.
This is useful if samples to skip is a dynamic configuration parameter that can change after class construction.
|
inline |
Spawns the worker thread (sync method).
Once spawned the worker thread will be in the IDLE state.