Class ILLIXR::threadloop
ClassList > ILLIXR > threadloop
A reusable threadloop for plugins. More...
#include <threadloop.hpp>
Inherits the following classes: ILLIXR::plugin
Public Functions
| Type | Name |
|---|---|
| virtual void | start () override Starts the thread. |
| virtual void | stop () override Joins the thread. |
| threadloop (std::string name_, phonebook * pb_) |
|
| virtual | ~threadloop () override |
Public Functions inherited from ILLIXR::plugin
See ILLIXR::plugin
| Type | Name |
|---|---|
| std::string | get_name () noexcept const |
| plugin (const std::string & name_, phonebook * pb_) |
|
| virtual void | start () A method which Spindle calls when it starts the component. |
| virtual void | stop () A method which Spindle calls when it stops the component. |
| virtual | ~plugin () = default |
Protected Types
| Type | Name |
|---|---|
| enum | skip_option |
Protected Attributes
| Type | Name |
|---|---|
| std::size_t | iteration_no = 0 |
| std::size_t | skip_no = 0 |
Protected Attributes inherited from ILLIXR::plugin
See ILLIXR::plugin
| Type | Name |
|---|---|
| const std::shared_ptr< gen_guid > | gen_guid_ |
| const std::size_t | id |
| std::string | name |
| const phonebook * | pb |
| const std::shared_ptr< record_logger > | record_logger_ |
Protected Functions
| Type | Name |
|---|---|
| virtual void | _p_one_iteration () = 0 Override with the computation the thread does every loop. |
| virtual skip_option | _p_should_skip () Gets called in a tight loop, to gate the invocation of _p_one_iteration() __ |
| virtual void | _p_thread_setup () Gets called at setup time, from the new thread. |
| bool | should_terminate () Whether the thread has been asked to terminate. |
Detailed Description
The thread continuously runs _p_one_iteration() and is stopable by stop().
This factors out the common code I noticed in many different plugins.
Public Functions Documentation
function start
Starts the thread.
inline virtual void ILLIXR::threadloop::start () override
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.
Implements ILLIXR::plugin::start
function stop
Joins the thread.
inline virtual void ILLIXR::threadloop::stop () override
Must have already stopped the stoplight.
Implements ILLIXR::plugin::stop
function threadloop
inline ILLIXR::threadloop::threadloop (
std::string name_,
phonebook * pb_
)
function ~threadloop
inline virtual ILLIXR::threadloop::~threadloop () override
Protected Types Documentation
enum skip_option
enum ILLIXR::threadloop::skip_option {
run,
skip_and_spin,
skip_and_yield,
stop
};
Protected Attributes Documentation
variable iteration_no
std::size_t ILLIXR::threadloop::iteration_no;
variable skip_no
std::size_t ILLIXR::threadloop::skip_no;
Protected Functions Documentation
function _p_one_iteration
Override with the computation the thread does every loop.
virtual void ILLIXR::threadloop::_p_one_iteration () = 0
This gets called in rapid succession.
function _p_should_skip
Gets called in a tight loop, to gate the invocation of _p_one_iteration() __
inline virtual skip_option ILLIXR::threadloop::_p_should_skip ()
function _p_thread_setup
Gets called at setup time, from the new thread.
inline virtual void ILLIXR::threadloop::_p_thread_setup ()
function should_terminate
Whether the thread has been asked to terminate.
inline bool ILLIXR::threadloop::should_terminate ()
Check this before doing long-running computation; it makes termination more responsive.
The documentation for this class was generated from the following file common/threadloop.hpp