#ifndef OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP #define OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP #include #include #include #include namespace op { template>, typename TQueue = Queue> class SubThreadQueueIn : public SubThread { public: SubThreadQueueIn(const std::vector& tWorkers, const std::shared_ptr& tQueueIn); virtual ~SubThreadQueueIn(); bool work(); private: std::shared_ptr spTQueueIn; DELETE_COPY(SubThreadQueueIn); }; } // Implementation namespace op { template SubThreadQueueIn::SubThreadQueueIn(const std::vector& tWorkers, const std::shared_ptr& tQueueIn) : SubThread{tWorkers}, spTQueueIn{tQueueIn} { // spTQueueIn->addPopper(); } template SubThreadQueueIn::~SubThreadQueueIn() { } template bool SubThreadQueueIn::work() { try { // Pop TDatums if (spTQueueIn->empty()) std::this_thread::sleep_for(std::chrono::microseconds{100}); TDatums tDatums; bool queueIsRunning = spTQueueIn->tryPop(tDatums); // Check queue not empty if (!queueIsRunning) queueIsRunning = spTQueueIn->isRunning(); // Process TDatums const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning); // Close queue input if all workers closed 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 // OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP