// Shared_Queue.hh
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <queue>
#ifndef SHARED_QUEUE_HH
#define SHARED_QUEUE_HH
template <class T>
class SharedQueue
{
public:
SharedQueue() :
_q(),
_q_mutex(),
_q_cv()
{};
SharedQueue( const SharedQueue& other )
std::cout << "Copy Constructor SharedQueue" << std::endl;
// (Read)Lock the other queue for copying
std::unique_lock<std::mutex> other_lock(other._q_mutex);
_q = other._q;
}
std::queue<T> * queue() { return& _q; }
std::mutex * mutex() { return& _q_mutex; }
std::condition_variable * cv() { return& _q_cv; }
private:
// Queue
std::queue<T> _q;
// Synchronisation
std::mutex _q_mutex;
std::condition_variable _q_cv;
};
#endif