Fixposition SDK 0.0.0-heads/main-0-g7b59b93
Collection of c++ libraries and apps for use with Fixposition products
|
Helper class for handling threads. More...
#include <thread.hpp>
Public Types | |
using | ThreadFunc = std::function<void(Thread*, void*)> |
Thread main function. | |
using | PrepFunc = std::function<void(void*)> |
Thread prepare function. | |
using | CleanFunc = std::function<void(void*)> |
Thread cleanup function. | |
Public Member Functions | |
Thread (const std::string &name, ThreadFunc func, void *arg=nullptr, PrepFunc prep=nullptr, CleanFunc clean=nullptr) | |
Constructor. | |
~Thread () | |
Destructor, blocks until thread has stopped. | |
const std::string & | GetName () |
Get thread name. | |
Main (controlling) thread methods | |
bool | Start () |
Start the thread. | |
void | Stop () |
Stop the thread. | |
void | Wakeup () |
Wakup a sleeping thread. | |
bool | IsRunning () |
Check if thread is running. | |
Worker thread methods | |
bool | Sleep (const uint32_t millis) |
Sleep until timeout or woken up. | |
bool | SleepUntil (const uint32_t period, const uint32_t min_sleep=0) |
Sleep until next period start or woken up. | |
bool | ShouldAbort () |
Check if we should abort. | |
Helper class for handling threads.
Example:
Definition at line 144 of file thread.hpp.
using fpsdk::common::thread::Thread::ThreadFunc = std::function<void(Thread*, void*)> |
Thread main function.
Definition at line 147 of file thread.hpp.
using fpsdk::common::thread::Thread::PrepFunc = std::function<void(void*)> |
Thread prepare function.
Definition at line 148 of file thread.hpp.
using fpsdk::common::thread::Thread::CleanFunc = std::function<void(void*)> |
Thread cleanup function.
Definition at line 149 of file thread.hpp.
fpsdk::common::thread::Thread::Thread | ( | const std::string & | name, |
ThreadFunc | func, | ||
void * | arg = nullptr, | ||
PrepFunc | prep = nullptr, | ||
CleanFunc | clean = nullptr ) |
Constructor.
[in] | name | Name of the thread, for debugging |
[in] | func | The thread function |
[in] | arg | Optional thread function user argument |
[in] | prep | Optional prepare function, called before the thread function |
[in] | clean | Optional cleanup function, called after the threadd stopped (or crashed) |
const std::string & fpsdk::common::thread::Thread::GetName | ( | ) |
Get thread name.
bool fpsdk::common::thread::Thread::Start | ( | ) |
Start the thread.
void fpsdk::common::thread::Thread::Stop | ( | ) |
Stop the thread.
void fpsdk::common::thread::Thread::Wakeup | ( | ) |
Wakup a sleeping thread.
bool fpsdk::common::thread::Thread::IsRunning | ( | ) |
Check if thread is running.
bool fpsdk::common::thread::Thread::Sleep | ( | const uint32_t | millis | ) |
Sleep until timeout or woken up.
[in] | millis | Number of [ms] to sleep |
bool fpsdk::common::thread::Thread::SleepUntil | ( | const uint32_t | period, |
const uint32_t | min_sleep = 0 ) |
Sleep until next period start or woken up.
See BinarySemaphore::WaitUntil() for a detailed explanation.
[in] | period | Period duration [ms], must be > 0 |
[in] | min_sleep | Minimal sleep duration [ms], must be < period |
bool fpsdk::common::thread::Thread::ShouldAbort | ( | ) |
Check if we should abort.
while (!thread_.ShouldAbort()) { do_stuff(); }