added class for thread-safe queue
This commit is contained in:
parent
4b03986c7b
commit
ed5a8c9665
35
include/ffcpp/TSQueue.h
Normal file
35
include/ffcpp/TSQueue.h
Normal 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
|
||||||
@ -27,7 +27,8 @@ set(SOURCE_FILES MediaFile.cpp
|
|||||||
Resampler.cpp
|
Resampler.cpp
|
||||||
../include/ffcpp/Resampler.h
|
../include/ffcpp/Resampler.h
|
||||||
Player.cpp
|
Player.cpp
|
||||||
../include/ffcpp/Player.h )
|
../include/ffcpp/Player.h
|
||||||
|
../include/ffcpp/TSQueue.h)
|
||||||
|
|
||||||
add_library(ffcpp ${SOURCE_FILES})
|
add_library(ffcpp ${SOURCE_FILES})
|
||||||
target_link_libraries(ffcpp ${FFMPEG_LIBRARIES})
|
target_link_libraries(ffcpp ${FFMPEG_LIBRARIES})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user