1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/queue_signalled.hpp
Steffen Vogel 0735eb0f89 Make project REUSE compliant
And various other cleanups and harmonizations

Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
2023-09-07 11:16:04 +02:00

45 lines
801 B
C++

/* Wrapper around queue that uses POSIX CV's for signalling writes.
*
* Author: Georg Martin Reinke <georg.reinke@rwth-aachen.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <mutex>
#include <condition_variable>
#include <villas/queue.hpp>
namespace villas {
template<typename T>
class QueueSignalled : public Queue<T> {
private:
std::condition_variable cv;
public:
void push(const T &data)
{
Queue<T>::push(data);
cv.notify_one();
}
T pop()
{
std::unique_lock<std::mutex> l(Queue<T>::mtx);
while (Queue<T>::queue.empty())
cv.wait(l);
T res = Queue<T>::queue.front();
Queue<T>::queue.pop();
return res;
}
};
} // namespace villas