added class for thread-safe queue

This commit is contained in:
selim mustafaev 2017-01-03 15:46:56 +03:00
parent 4b03986c7b
commit ed5a8c9665
2 changed files with 37 additions and 1 deletions

35
include/ffcpp/TSQueue.h Normal file
View File

@ -0,0 +1,35 @@
#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

View File

@ -27,7 +27,8 @@ set(SOURCE_FILES MediaFile.cpp
Resampler.cpp
../include/ffcpp/Resampler.h
Player.cpp
../include/ffcpp/Player.h )
../include/ffcpp/Player.h
../include/ffcpp/TSQueue.h)
add_library(ffcpp ${SOURCE_FILES})
target_link_libraries(ffcpp ${FFMPEG_LIBRARIES})