18#ifndef __FPSDK_COMMON_THREAD_HPP__
19#define __FPSDK_COMMON_THREAD_HPP__
23#include <condition_variable>
84 bool WaitUntil(
const uint32_t period,
const uint32_t min_sleep = 0);
88 std::condition_variable cond_;
241 bool SleepUntil(
const uint32_t period,
const uint32_t min_sleep = 0);
258 std::unique_ptr<std::thread> thread_;
263 std::atomic<bool> abort_;
A binary semaphore, useful for thread synchronisation.
bool WaitUntil(const uint32_t period, const uint32_t min_sleep=0)
Wait (take), with timout aligned to a period.
bool WaitFor(const uint32_t millis)
Wait (take), with timeout.
void Notify()
Notify ("signal", "give")
Helper class for handling threads.
Thread(const std::string &name, ThreadFunc func, void *arg=nullptr, PrepFunc prep=nullptr, CleanFunc clean=nullptr)
Constructor.
void Stop()
Stop the thread.
std::function< void(void *)> PrepFunc
Thread prepare function.
bool ShouldAbort()
Check if we should abort.
void Wakeup()
Wakup a sleeping thread.
std::function< void(void *)> CleanFunc
Thread cleanup function.
bool SleepUntil(const uint32_t period, const uint32_t min_sleep=0)
Sleep until next period start or woken up.
std::function< void(Thread *, void *)> ThreadFunc
Thread main function.
bool Sleep(const uint32_t millis)
Sleep until timeout or woken up.
bool IsRunning()
Check if thread is running.
bool Start()
Start the thread.
~Thread()
Destructor, blocks until thread has stopped.
const std::string & GetName()
Get thread name.
void SetThreadName(const std::string &name)
Set thread name.
std::size_t ThisThreadId()
Get numeric thread ID.