| | #ifndef OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP |
| | #define OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP |
| |
|
| | #include <openpose/core/common.hpp> |
| | #include <openpose/thread/queue.hpp> |
| | #include <openpose/thread/thread.hpp> |
| | #include <openpose/thread/worker.hpp> |
| |
|
| | namespace op |
| | { |
| | template<typename TDatums, typename TWorker = std::shared_ptr<Worker<TDatums>>, typename TQueue = Queue<TDatums>> |
| | class SubThreadQueueIn : public SubThread<TDatums, TWorker> |
| | { |
| | public: |
| | SubThreadQueueIn(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueIn); |
| |
|
| | virtual ~SubThreadQueueIn(); |
| |
|
| | bool work(); |
| |
|
| | private: |
| | std::shared_ptr<TQueue> spTQueueIn; |
| |
|
| | DELETE_COPY(SubThreadQueueIn); |
| | }; |
| | } |
| |
|
| |
|
| |
|
| |
|
| |
|
| | |
| | namespace op |
| | { |
| | template<typename TDatums, typename TWorker, typename TQueue> |
| | SubThreadQueueIn<TDatums, TWorker, TQueue>::SubThreadQueueIn(const std::vector<TWorker>& tWorkers, |
| | const std::shared_ptr<TQueue>& tQueueIn) : |
| | SubThread<TDatums, TWorker>{tWorkers}, |
| | spTQueueIn{tQueueIn} |
| | { |
| | |
| | } |
| |
|
| | template<typename TDatums, typename TWorker, typename TQueue> |
| | SubThreadQueueIn<TDatums, TWorker, TQueue>::~SubThreadQueueIn() |
| | { |
| | } |
| |
|
| | template<typename TDatums, typename TWorker, typename TQueue> |
| | bool SubThreadQueueIn<TDatums, TWorker, TQueue>::work() |
| | { |
| | try |
| | { |
| | |
| | if (spTQueueIn->empty()) |
| | std::this_thread::sleep_for(std::chrono::microseconds{100}); |
| | TDatums tDatums; |
| | bool queueIsRunning = spTQueueIn->tryPop(tDatums); |
| | |
| | if (!queueIsRunning) |
| | queueIsRunning = spTQueueIn->isRunning(); |
| | |
| | const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning); |
| | |
| | if (!workersAreRunning) |
| | spTQueueIn->stop(); |
| | return workersAreRunning; |
| | } |
| | catch (const std::exception& e) |
| | { |
| | error(e.what(), __LINE__, __FUNCTION__, __FILE__); |
| | spTQueueIn->stop(); |
| | return false; |
| | } |
| | } |
| |
|
| | COMPILE_TEMPLATE_DATUM(SubThreadQueueIn); |
| | } |
| |
|
| | #endif |
| |
|