32#include <sptk5/sptk.h>
33#include <sptk5/threads/Semaphore.h>
72 std::unique_lock lock(m_mutex);
73 m_queue->push(std::move(data));
87 std::unique_lock lock(m_mutex);
101 bool pop(T& item, std::chrono::milliseconds timeout)
105 std::scoped_lock lock(m_mutex);
106 if (!m_queue->empty())
108 item = std::move(m_queue->front());
131 std::scoped_lock lock(m_mutex);
132 return m_queue->empty();
140 std::scoped_lock lock(m_mutex);
141 return m_queue->size();
149 std::scoped_lock lock(m_mutex);
150 m_queue = std::make_shared<std::queue<T>>();
164 std::scoped_lock lock(m_mutex);
166 auto newQueue = std::make_shared<std::queue<T>>();
170 while (m_queue->size())
172 T& item = m_queue->front();
174 newQueue->push(item);
181 rc = callbackFunction(item);
199 mutable std::mutex m_mutex;
209 std::shared_ptr<std::queue<T>> m_queue {std::make_shared<std::queue<T>>()};
SPTK generic exception class.
Definition: Exception.h:56
Generic unnamed semaphore class.
Definition: Semaphore.h:52
bool sleep_for(std::chrono::milliseconds timeout)
Wait until semaphore value is greater than zero, or until timeout interval is passed.
void post()
Post the semaphore.
Definition: SynchronizedQueue.h:49
size_t size() const
Definition: SynchronizedQueue.h:138
void push(T &&data)
Definition: SynchronizedQueue.h:70
virtual void wakeup()
Definition: SynchronizedQueue.h:121
void clear()
Definition: SynchronizedQueue.h:147
bool each(const CallbackFunction &callbackFunction)
Definition: SynchronizedQueue.h:162
bool pop(T &item, std::chrono::milliseconds timeout)
Definition: SynchronizedQueue.h:101
bool empty() const
Definition: SynchronizedQueue.h:129
std::function< bool(T &item)> CallbackFunction
Definition: SynchronizedQueue.h:60
void push(const T &data)
Definition: SynchronizedQueue.h:85