Mercurial > hg > orthanc
diff Core/MultiThreading/SharedMessageQueue.cpp @ 452:80f7539147a2
WaitEmpty
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Jul 2013 11:48:02 +0200 |
parents | 58b433bb9762 |
children | 08eca5d86aad |
line wrap: on
line diff
--- a/Core/MultiThreading/SharedMessageQueue.cpp Thu Jul 04 09:53:15 2013 +0200 +++ b/Core/MultiThreading/SharedMessageQueue.cpp Thu Jul 04 11:48:02 2013 +0200 @@ -89,7 +89,34 @@ std::auto_ptr<IDynamicObject> message(queue_.front()); queue_.pop_front(); + emptied_.notify_all(); return message.release(); } + + + + bool SharedMessageQueue::WaitEmpty(int32_t millisecondsTimeout) + { + boost::mutex::scoped_lock lock(mutex_); + + // Wait for the queue to become empty + if (!queue_.empty()) + { + if (millisecondsTimeout == 0) + { + emptied_.wait(lock); + } + else + { + if (!emptied_.timed_wait + (lock, boost::posix_time::milliseconds(millisecondsTimeout))) + { + return false; + } + } + } + + return true; + } }