![]() |
Fixposition SDK 0.0.0-heads/main-0-gb93ddb4
Collection of c++ libraries and apps for use with Fixposition products on Linux
|
Helper class for handling threads. More...
#include <thread.hpp>
Public Types | |
| using | ThreadFunc = std::function<bool(Thread& thread, void* arg)> |
| Thread main function. | |
| using | PrepFunc = std::function<void(void* arg)> |
| Thread pepare function. | |
| using | CleanFunc = std::function<void(void* arg)> |
| 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. | |
| static const char * | StatusStr (const Status status) |
| Stringify 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 161 of file thread.hpp.
| using fpsdk::common::thread::Thread::ThreadFunc = std::function<bool(Thread& thread, void* arg)> |
Thread main function.
| [in] | thread | Reference to the thread handle |
| [in] | arg | User argument passed in Thread contstructor |
Definition at line 173 of file thread.hpp.
| using fpsdk::common::thread::Thread::PrepFunc = std::function<void(void* arg)> |
Thread pepare function.
| [in] | arg | User argument passed in Thread contstructor |
Definition at line 180 of file thread.hpp.
| using fpsdk::common::thread::Thread::CleanFunc = std::function<void(void* arg)> |
Thread cleanup function.
| [in] | arg | User argument passed in Thread contstructor |
Definition at line 187 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.
|
static |
Stringify status.
| [in] | status | The status |
| 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 |