OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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  bool work();
18 
19  private:
20  std::shared_ptr<TQueue> spTQueueIn;
21 
22  DELETE_COPY(SubThreadQueueIn);
23  };
24 }
25 
26 
27 
28 
29 
30 // Implementation
31 namespace op
32 {
33  template<typename TDatums, typename TWorker, typename TQueue>
34  SubThreadQueueIn<TDatums, TWorker, TQueue>::SubThreadQueueIn(const std::vector<TWorker>& tWorkers, const std::shared_ptr<TQueue>& tQueueIn) :
35  SubThread<TDatums, TWorker>{tWorkers},
36  spTQueueIn{tQueueIn}
37  {
38  // spTQueueIn->addPopper();
39  }
40 
41  template<typename TDatums, typename TWorker, typename TQueue>
43  {
44  try
45  {
46  // Pop TDatums
47  TDatums tDatums;
48  bool queueIsRunning = spTQueueIn->tryPop(tDatums);
49  // Check queue not empty
50  if (!queueIsRunning)
51  queueIsRunning = spTQueueIn->isRunning();
52  // Process TDatums
53  const auto workersAreRunning = this->workTWorkers(tDatums, queueIsRunning);
54  // Close queue input if all workers closed
55  if (!workersAreRunning)
56  spTQueueIn->stop();
57  return workersAreRunning;
58  }
59  catch (const std::exception& e)
60  {
61  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
62  spTQueueIn->stop();
63  return false;
64  }
65  }
66 
67  COMPILE_TEMPLATE_DATUM(SubThreadQueueIn);
68 }
69 
70 #endif // OPENPOSE_THREAD_THREAD_QUEUE_IN_HPP
Definition: subThread.hpp:10
SubThreadQueueIn(const std::vector< TWorker > &tWorkers, const std::shared_ptr< TQueue > &tQueueIn)
Definition: subThreadQueueIn.hpp:34
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
spTQueueIn
Definition: subThreadQueueIn.hpp:36
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
Definition: subThreadQueueIn.hpp:12