Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
421 B
11
Indexable
Never
	void pop(T &item, int deadlineMs)
	{
		std::unique_lock<std::mutex> lock(m_Mutex);
		while (m_Queue.empty())
		{
			if(m_Cond.wait_for(lock, std::chrono::milliseconds(deadlineMs)) == std::cv_status::timeout)
			{
				return;
			}
		}
		item = m_Queue.front();
		m_Queue.pop();
	}

	void push(const T &item)
	{
		std::unique_lock<std::mutex> lock(m_Mutex);
		m_Queue.push(item);
		lock.unlock();
		m_Cond.notify_one();
	}