Revision cfdc7053f2bba3965c665328fc1d014f44cab16b authored by Lonca Emmanuel on 17 March 2021, 12:16:06 UTC, committed by Lonca Emmanuel on 17 March 2021, 12:16:06 UTC
1 parent 76983f8
ConcurrentStrQueue.h
#ifndef __CONCURRENT_STR_QUEUE__
#define __CONCURRENT_STR_QUEUE__
#include <string>
#include <queue>
#include <mutex>
#include <condition_variable>
namespace CoQuiAAS {
class ConcurrentStrQueue {
public:
inline void push(std::string str) {
std::unique_lock<std::mutex> mlock(queue_mut);
elements.push(str);
mlock.unlock();
cond.notify_one();
}
inline std::string pop() {
std::unique_lock<std::mutex> mlock(queue_mut);
while (elements.empty()){
cond.wait(mlock);
}
auto item = elements.front();
elements.pop();
return item;
}
private:
std::queue<std::string> elements;
std::mutex queue_mut;
std::condition_variable cond;
};
}
#endif
Computing file changes ...