OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
subThreadQueueIn.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
2 #define OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
3 
8 
9 namespace op
10 {
11  template<typename TDatums, typename TWorker = std::shared_ptr<Worker<TDatums>>, typename TQueue = Queue<TDatums>>
12  class SubThreadQueueIn : public SubThread<TDatums, TWorker>
13  {
14  public:
15  SubThreadQueueIn(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueIn);
16 
17  virtual ~SubThreadQueueIn();
18 
19  bool work();
20 
21  private:
22  std::shared_ptr<TQueue> spTQueueIn;
23 
24  DELETE_COPY(SubThreadQueueIn);
25  };
26 }
27 
28 
29 
30 
31 
32 // Implementation
33 namespace op
34 {
35  template<typename TDatums, typename TWorker, typename TQueue>
37  const std::shared_ptr<TQueue>& tQueueIn) :
38  SubThread<TDatums, TWorker>{tWorkers},
39  spTQueueIn{tQueueIn}
40  {
41  // spTQueueIn->addPopper();
42  }
43 
44  template<typename TDatums, typename TWorker, typename TQueue>
46  {
47  }
48 
49  template<typename TDatums, typename TWorker, typename TQueue>
51  {
52  try
53  {
54  // Pop TDatums
55  if (spTQueueIn->empty())
56  std::this_thread::sleep_for(std::chrono::microseconds{100});
57  TDatums tDatums;
58  bool queueIsRunning = spTQueueIn->tryPop(tDatums);
59  // Check queue not empty
60  if (!queueIsRunning)
61  queueIsRunning = spTQueueIn->isRunning();
62  // Process TDatums
63  const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning);
64  // Close queue input if all workers closed
65  if (!workersAreRunning)
66  spTQueueIn->stop();
67  return workersAreRunning;
68  }
69  catch (const std::exception& e)
70  {
71  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
72  spTQueueIn->stop();
73  return false;
74  }
75  }
76 
78 }
79 
80 #endif // OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
SubThreadQueueIn(const std::vector< TWorker > &tWorkers, const std::shared_ptr< TQueue > &tQueueIn)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")