1 #ifndef OPENPOSE_THREAD_W_QUEUE_ORDERER_HPP
2 #define OPENPOSE_THREAD_W_QUEUE_ORDERER_HPP
11 template<
typename TDatums>
15 explicit WQueueOrderer(
const unsigned int maxBufferSize = 64u);
21 void work(TDatums& tDatums);
26 const unsigned int mMaxBufferSize;
28 unsigned long long mNextExpectedId;
29 unsigned long long mNextExpectedSubId;
43 template<
typename TDatums>
45 mMaxBufferSize{maxBufferSize},
46 mStopWhenEmpty{false},
52 template<
typename TDatums>
57 template<
typename TDatums>
62 template<
typename TDatums>
69 bool profileSpeed = (tDatums !=
nullptr);
74 auto& tDatumsNoPtr = *tDatums;
76 if (tDatumsNoPtr[0]->
id == mNextExpectedId && tDatumsNoPtr[0]->subId == mNextExpectedSubId)
79 if (tDatumsNoPtr[0]->subIdMax == 0)
85 if (mNextExpectedSubId > tDatumsNoPtr[0]->subIdMax)
87 mNextExpectedSubId = 0;
96 mPriorityQueueBuffer.emplace(tDatums);
99 if (mPriorityQueueBuffer.size() > mMaxBufferSize)
101 tDatums = mPriorityQueueBuffer.top();
102 mPriorityQueueBuffer.pop();
110 if (!mPriorityQueueBuffer.empty()
111 && (mStopWhenEmpty ||
112 ((*mPriorityQueueBuffer.top())[0]->
id == mNextExpectedId
113 && (*mPriorityQueueBuffer.top())[0]->subId == mNextExpectedSubId)))
115 tDatums = { mPriorityQueueBuffer.top() };
116 mPriorityQueueBuffer.pop();
122 const auto& tDatumsNoPtr = *tDatums;
124 if (tDatumsNoPtr[0]->subIdMax == 0)
125 mNextExpectedId = tDatumsNoPtr[0]->id + 1;
129 mNextExpectedSubId = tDatumsNoPtr[0]->subId + 1;
130 if (mNextExpectedSubId > tDatumsNoPtr[0]->subIdMax)
132 mNextExpectedSubId = 0;
133 mNextExpectedId = tDatumsNoPtr[0]->id + 1;
139 std::this_thread::sleep_for(std::chrono::milliseconds{1});
141 if (profileSpeed || tDatums !=
nullptr)
150 catch (
const std::exception& e)
154 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
158 template<
typename TDatums>
164 if (mPriorityQueueBuffer.empty())
166 mStopWhenEmpty =
true;
169 catch (
const std::exception& e)
171 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
static void printAveragedTimeMsOnIterationX(const std::string &key, const int line, const std::string &function, const std::string &file, const unsigned long long x=DEFAULT_X)
static const std::string timerInit(const int line, const std::string &function, const std::string &file)
static void timerEnd(const std::string &key)
void work(TDatums &tDatums)
WQueueOrderer(const unsigned int maxBufferSize=64u)
void initializationOnThread()
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
void opLogIfDebug(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")