12 #ifndef RTCTK_DATATASK_MESSAGEQUEUE_HPP
13 #define RTCTK_DATATASK_MESSAGEQUEUE_HPP
16 #include <condition_variable>
29 inline void Post(T
const& value) {
31 std::unique_lock<std::mutex> lock(m_mtx);
38 std::unique_lock<std::mutex> lock(m_mtx);
39 m_cv.wait(lock, [&]{
return not m_queue.empty();});
40 auto ret = m_queue.front();
45 template <
class Rep,
class Period>
46 inline T
Pend(std::chrono::duration<Rep, Period> timeout) {
47 std::unique_lock<std::mutex> lock(m_mtx);
48 auto to = m_cv.wait_for(lock, timeout, [&]{
return not m_queue.empty();});
50 throw(std::runtime_error(
"MessageQueue.Pend() timed out"));
52 auto ret = m_queue.front();
58 std::unique_lock<std::mutex> lock(m_mtx);
59 if(not m_queue.empty()) {
60 auto ret = m_queue.front();
69 std::unique_lock<std::mutex> lock(m_mtx);
70 while(not m_queue.empty()) {
77 std::condition_variable m_cv;
78 std::queue<T> m_queue;