36 lines
741 B
C++
36 lines
741 B
C++
#ifndef PROJECT_TSQUEUE_H
|
|
#define PROJECT_TSQUEUE_H
|
|
|
|
#include <mutex>
|
|
#include <condition_variable>
|
|
#include <queue>
|
|
|
|
namespace ffcpp {
|
|
|
|
template<typename T> class TSQueue {
|
|
private:
|
|
using LockType = std::lock_guard<std::mutex>;
|
|
|
|
private:
|
|
mutable std::mutex _mutex;
|
|
std::condition_variable _cond;
|
|
std::queue<std::shared_ptr<T>> _queue;
|
|
|
|
public:
|
|
bool empty() const {
|
|
LockType lock(_mutex);
|
|
return _queue.empty();
|
|
}
|
|
|
|
void push(T value) {
|
|
auto data = std::make_shared<T>(std::move(value));
|
|
LockType lock(_mutex);
|
|
_queue.push(data);
|
|
_cond.notify_one();
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif //PROJECT_TSQUEUE_H
|