1
0
Fork 0
This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
uni-m.cds-adv-prog/ex10/shared_queue.hh

39 lines
764 B
C++

// 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