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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
822 B
C++
Raw Normal View History

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