#pragma once #include //#include #include #include using namespace std; template class ASyncQueue { public: ASyncQueue(int max_size); ~ASyncQueue(); void put(const T& val); void take(T& val); void clear(); bool isEmpty(); bool isFull(); int count(); public: string name; private: mutex lock; //condition_variable_any cv_full, cv_empty; list q; int size; int max_size; }; using namespace std; template ASyncQueue::ASyncQueue(int max_size) :max_size(max_size) { } template ASyncQueue::~ASyncQueue() { } template void ASyncQueue::put(const T& val) { lock_guard locker(lock); q.emplace_back(val); } template void ASyncQueue::take(T& val) { lock_guard locker(lock); val = q.front(); q.pop_front(); } template void ASyncQueue::clear() { lock_guard locker(lock); q.clear(); } template bool ASyncQueue::isEmpty() { return q.size() == 0; } template bool ASyncQueue::isFull() { return q.size() == max_size; } template int ASyncQueue::count() { lock_guard locker(lock); return q.size(); }