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.hpp

51 lines
814 B
C++
Raw Permalink Normal View History

2018-11-30 21:40:48 +01:00
/** Wrapper around queue that uses POSIX CV's for signalling writes.
*
* @file
* @author Georg Martin Reinke <georg.reinke@rwth-aachen.de>
2022-03-15 09:28:57 -04:00
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
2022-07-04 18:20:03 +02:00
* @license Apache 2.0
2018-11-30 21:40:48 +01:00
*********************************************************************************/
#pragma once
#include <mutex>
#include <queue>
namespace villas {
template<typename T>
class Queue {
protected:
std::queue<T> queue;
2018-12-04 00:31:21 +01:00
std::mutex mtx;
2018-11-30 21:40:48 +01:00
public:
void push(T p)
{
2018-12-04 00:31:21 +01:00
std::unique_lock<std::mutex> guard(mtx);
2018-11-30 21:40:48 +01:00
queue.push(p);
}
T pop()
{
2018-12-04 00:31:21 +01:00
std::unique_lock<std::mutex> guard(mtx);
2018-11-30 21:40:48 +01:00
T res = queue.front();
queue.pop();
return res;
}
bool empty()
{
2018-12-04 00:31:21 +01:00
std::unique_lock<std::mutex> guard(mtx);
2018-11-30 21:40:48 +01:00
return queue.empty();
}
};
2020-06-15 22:16:38 +02:00
} /* namespace villas */