1 #ifndef OPENPOSE_THREAD_SUB_THREAD_HPP
2 #define OPENPOSE_THREAD_SUB_THREAD_HPP
9 template<
typename TDatums,
typename TWorker = std::shared_ptr<Worker<TDatums>>>
13 explicit SubThread(
const std::vector<TWorker>& tWorkers);
25 return mTWorkers.size();
28 bool workTWorkers(TDatums& tDatums,
const bool inputIsRunning);
31 std::vector<TWorker> mTWorkers;
44 template<
typename TDatums,
typename TWorker>
50 template<
typename TDatums,
typename TWorker>
55 template<
typename TDatums,
typename TWorker>
63 for (
auto& tWorkers : mTWorkers)
66 if (tWorkers->isRunning())
72 if ((*mTWorkers.crbegin())->isRunning())
75 auto allRunning =
true;
76 auto lastOneStopped =
false;
77 for (
auto& worker : mTWorkers)
82 if (!worker->checkAndWork(tDatums))
85 lastOneStopped =
true;
88 lastOneStopped =
false;
97 auto lastRunning = (*mTWorkers.crbegin())->isRunning();
101 auto lastIndexNotRunning = 0ull;
102 for (
auto i = mTWorkers.size() - 1 ; i > 0 ; i--)
104 if (!mTWorkers[i]->checkAndWork(tDatums))
106 lastIndexNotRunning = i;
112 for (
auto i = 0ull; i < lastIndexNotRunning ; i++)
113 mTWorkers[i]->stop();
117 for (
auto i = lastIndexNotRunning+1; i < mTWorkers.size() ; i++)
119 mTWorkers[i]->tryStop();
120 if (mTWorkers[i]->isRunning())
133 catch (
const std::exception& e)
135 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
140 template<
typename TDatums,
typename TWorker>
145 for (
auto& tWorker : mTWorkers)
146 tWorker->initializationOnThreadNoException();
148 catch (
const std::exception& e)
150 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
size_t getTWorkersSize() const
void initializationOnThread()
SubThread(const std::vector< TWorker > &tWorkers)
bool workTWorkers(TDatums &tDatums, const bool inputIsRunning)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")