27#ifndef APF_THREADTOOLS_H
28#define APF_THREADTOOLS_H
33#include <condition_variable>
42class ScopedThread : NonCopyable
45 ScopedThread(F f,
int usleeptime)
48 , _sleeptime(std::chrono::microseconds(usleeptime))
49 , _thread(std::thread(&ScopedThread::_thread_function, this))
54 _keep_running.store(
false, std::memory_order_release);
59 void _thread_function()
61 while (_keep_running.load(std::memory_order_acquire))
64 std::this_thread::sleep_for(_sleeptime);
68 std::atomic<bool> _keep_running;
70 std::chrono::microseconds _sleeptime;
74class Semaphore : NonCopyable
79 Semaphore(
int count = 0) : _count{count} {}
81 Semaphore(Semaphore&&)
85 throw std::logic_error(
"This is just a work-around, don't move!");
90 std::lock_guard<std::mutex> guard{_mtx};
97 std::unique_lock<std::mutex> lock{_mtx};
98 _cv.wait(lock, [
this]() {
return _count > 0; });
104 std::condition_variable _cv;
Miscellaneous helper classes.
Audio Processing Framework.