A reusable threadloop for plugins.
More...
#include <threadloop.hpp>
|
| threadloop (const std::string &name_, phonebook *pb_) |
|
void | start () override |
| Starts the thread. More...
|
|
void | stop () override |
| Joins the thread. More...
|
|
virtual void | internal_stop () |
| Stops the thread. More...
|
|
| plugin (std::string name_, phonebook *pb_) |
|
std::string | get_name () const noexcept |
|
void | spdlogger (const char *log_level) |
|
|
std::size_t | iteration_no = 0 |
|
std::size_t | skip_no = 0 |
|
std::string | name |
|
const phonebook * | pb |
|
const std::shared_ptr< record_logger > | record_logger_ |
|
const std::shared_ptr< gen_guid > | gen_guid_ |
|
const std::size_t | id |
|
A reusable threadloop for plugins.
The thread continuously runs _p_one_iteration()
and is stopable by stop()
.
This factors out the common code I noticed in many different plugins.
◆ skip_option
Enumerator |
---|
run | Run iteration NOW. Only then does CPU timer begin counting.
|
skip_and_spin | AKA "busy wait". Skip but try again very quickly.
|
skip_and_yield | Yielding gives up a scheduling quantum, which is determined by the OS, but usually on the order of 1-10ms. This is nicer to the other threads in the system.
|
stop | Calls stop.
|
◆ _p_one_iteration()
virtual void ILLIXR::threadloop::_p_one_iteration |
( |
| ) |
|
|
protectedpure virtual |
Override with the computation the thread does every loop.
This gets called in rapid succession.
◆ internal_stop()
virtual void ILLIXR::threadloop::internal_stop |
( |
| ) |
|
|
inlinevirtual |
Stops the thread.
A thread should call this if it wants to stop itself (due to out of data for example).
◆ should_terminate()
bool ILLIXR::threadloop::should_terminate |
( |
| ) |
|
|
inlineprotected |
Whether the thread has been asked to terminate.
Check this before doing long-running computation; it makes termination more responsive.
◆ start()
void ILLIXR::threadloop::start |
( |
| ) |
|
|
inlineoverridevirtual |
Starts the thread.
This cannot go into the constructor because it starts a thread which calls _p_one_iteration()
which is virtual in the child class.
Calling a virtual child method from the parent constructor will not work as expected 1. Instead, the ISO CPP FAQ recommends calling a start()
method immediately after construction 2.
Reimplemented from ILLIXR::plugin.
◆ stop()
void ILLIXR::threadloop::stop |
( |
| ) |
|
|
inlineoverridevirtual |
Joins the thread.
Must have already stopped the stoplight.
Reimplemented from ILLIXR::plugin.
The documentation for this class was generated from the following file: