// return shared pointer to value - which if set to nullptr, // indicates container was empty at the time of the call. inline std::shared_ptr<T> try_pop() { std::lock_guard<std::mutex> lock(mut); if (data_queue.empty()) { return std::shared_ptr<T>(); } else { auto res = std::move(front_or_top(data_queue)); data_queue.pop(); return std::move(res); } }
// return value in specified reference indicating whether // value successfully returned or not inline bool try_pop(std::shared_ptr<T>& rValue) { std::lock_guard<std::mutex> lock(mut); if (data_queue.empty()) { rValue.reset(); return false; } else { rValue = std::move(front_or_top(data_queue)); data_queue.pop(); return true; } }
// wait for non empty lambda condition before returning shared pointer to value inline std::shared_ptr<T> wait_and_pop() { std::unique_lock<std::mutex> lock(mut); data_cond.wait(lock, [this]{ return !data_queue.empty() || shutdownFlag; }); if (!shutdownFlag) { auto res = std::move(front_or_top(data_queue)); data_queue.pop(); return std::move(res); } return nullptr; }