NASFAQ/connections/safe_queue/safe_queue.h

37 lines
490 B
C
Raw Normal View History

2022-05-07 14:49:43 +00:00
#ifndef _SAFE_QUEUE_H_
#define _SAFE_QUEUE_H_
2022-02-18 09:24:24 +00:00
#include <queue>
#include <mutex>
#include <condition_variable>
// A threadsafe-queue.
template <class T>
2022-05-07 14:49:43 +00:00
class TestQueue
2022-02-18 09:24:24 +00:00
{
public:
2022-05-07 14:49:43 +00:00
TestQueue();
~TestQueue();
private:
std::queue<T> q;
};
2022-02-18 09:24:24 +00:00
2022-05-07 14:49:43 +00:00
// A threadsafe-queue.
template <class T>
class SafeQueue
{
public:
SafeQueue(void);
~SafeQueue(void);
2022-02-18 09:24:24 +00:00
2022-05-07 14:49:43 +00:00
void enqueue(T);
T dequeue(void);
bool empty(void);
2022-02-18 09:24:24 +00:00
private:
std::queue<T> q;
mutable std::mutex m;
std::condition_variable c;
};
#endif