18#ifndef __FPSDK_COMMON_THREAD_HPP__ 
   19#define __FPSDK_COMMON_THREAD_HPP__ 
   23#include <condition_variable> 
  100    std::condition_variable cond_;  
 
  234    bool Start(
const bool try_catch = 
true);
 
  317    std::unique_ptr<std::thread> thread_;                     
 
  322    std::atomic<bool>            abort_   = 
false;            
 
  323    std::atomic<bool>            started_ = 
false;            
 
  327    void _Thread(
const bool try_catch);  
 
A binary semaphore, useful for thread synchronisation.
 
WaitRes WaitUntil(const uint32_t period, const uint32_t min_sleep=0)
Wait (take), with timout aligned to a period.
 
WaitRes WaitFor(const uint32_t millis)
Wait (take), with timeout.
 
void Notify()
Notify ("signal", "give")
 
Status GetStatus() const
Check thread status.
 
Thread(const std::string &name, ThreadFunc func, void *arg=nullptr, PrepFunc prep=nullptr, CleanFunc clean=nullptr)
Constructor.
 
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.
 
void Wakeup()
Wakup a sleeping thread.
 
@ RUNNING
Running (Start(ed) and happily running)
 
@ FAILED
Failed (was Start()ed, but crashed due to an exception)
 
@ STOPPED
Stopped (not Start()ed, or properly and happily Stop()ped)
 
std::function< bool(Thread &thread, void *arg)> ThreadFunc
Thread main function.
 
std::function< void(void *arg)> CleanFunc
Thread cleanup function.
 
static const char * StatusStr(const Status status)
Stringify status.
 
bool Stop()
Stop the thread.
 
std::function< void(void *arg)> PrepFunc
Thread pepare function.
 
~Thread()
Destructor, blocks until thread has stopped.
 
WaitRes Sleep(const uint32_t millis)
Sleep until timeout or woken up.
 
const std::string & GetName()
Get thread name.
 
bool Start(const bool try_catch=true)
Start the thread.
 
WaitRes
Thread sleep result.
 
@ TIMEOUT
Sleep or wait timeout has expired (no wakeup, no interrupt)
 
@ WOKEN
Thread was woken up (sleep interrupted), or semaphore was taken (wait interrupted)
 
void SetThreadName(const std::string &name)
Set thread name.
 
std::size_t ThisThreadId()
Get numeric thread ID.
 
Fixposition SDK: Common library.