![]() |
Fixposition SDK 0.0.0-heads/main-0-gd0a6ce2
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<bool(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 | |
enum | Status { STOPPED , RUNNING , FAILED } |
Thread status. More... | |
bool | Start (const bool try_catch=true) |
Start the thread. | |
bool | Stop () |
Stop the thread. | |
void | Wakeup () |
Wakup a sleeping thread. | |
Status | GetStatus () const |
Check thread status. | |
Worker thread methods | |
WaitRes | Sleep (const uint32_t millis) |
Sleep until timeout or woken up. | |
WaitRes | 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 154 of file thread.hpp.
using fpsdk::common::thread::Thread::ThreadFunc = std::function<bool(Thread*, void*)> |
Thread main function.
Definition at line 157 of file thread.hpp.
using fpsdk::common::thread::Thread::PrepFunc = std::function<void(void*)> |
Thread prepare function.
Definition at line 158 of file thread.hpp.
using fpsdk::common::thread::Thread::CleanFunc = std::function<void(void*)> |
Thread cleanup function.
Definition at line 159 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 | ( | const bool | try_catch = true | ) |
Start the thread.
[in] | try_catch | Run user-supplied thread function in a try ... catch block |
bool fpsdk::common::thread::Thread::Stop | ( | ) |
Stop the thread.
Status fpsdk::common::thread::Thread::GetStatus | ( | ) | const |
Check thread status.
WaitRes fpsdk::common::thread::Thread::Sleep | ( | const uint32_t | millis | ) |
Sleep until timeout or woken up.
[in] | millis | Number of [ms] to sleep |
WaitRes 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 |