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);
19 void work(TDatums& tDatums);
24 const unsigned int mMaxBufferSize;
26 unsigned long long mNextExpectedId;
42 template<
typename TDatums>
44 mMaxBufferSize{maxBufferSize},
45 mStopWhenEmpty{
false},
50 template<
typename TDatums>
55 template<
typename TDatums>
62 bool profileSpeed = (tDatums !=
nullptr);
67 auto& tDatumsNoPtr = *tDatums;
69 if (tDatumsNoPtr[0].
id == mNextExpectedId)
75 mPriorityQueueBuffer.emplace(tDatums);
78 if (mPriorityQueueBuffer.size() > mMaxBufferSize)
80 tDatums = mPriorityQueueBuffer.top();
81 mPriorityQueueBuffer.pop();
89 if (!mPriorityQueueBuffer.empty() && ((*mPriorityQueueBuffer.top())[0].
id == mNextExpectedId || mStopWhenEmpty))
91 tDatums = { mPriorityQueueBuffer.top() };
92 mPriorityQueueBuffer.pop();
98 const auto& tDatumsNoPtr = *tDatums;
99 mNextExpectedId = tDatumsNoPtr[0].id + 1;
103 std::this_thread::sleep_for(std::chrono::milliseconds{1});
105 if (profileSpeed || tDatums !=
nullptr)
114 catch (
const std::exception& e)
118 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
122 template<
typename TDatums>
128 if (mPriorityQueueBuffer.empty())
130 mStopWhenEmpty =
true;
133 catch (
const std::exception& e)
135 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
142 #endif // OPENPOSE_THREAD_W_QUEUE_ORDERER_HPP
void work(TDatums &tDatums)
Definition: wQueueOrderer.hpp:56
void initializationOnThread()
Definition: wQueueOrderer.hpp:51
Definition: pointerContainer.hpp:13
static const std::string timerInit(const int line, const std::string &function, const std::string &file)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
Definition: wQueueOrderer.hpp:12
void tryStop()
Definition: wQueueOrderer.hpp:123
void dLog(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:53
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
Definition: pointerContainer.hpp:7
WQueueOrderer(const unsigned int maxBufferSize=64u)
Definition: wQueueOrderer.hpp:43
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)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
static void timerEnd(const std::string &key)