Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
451:0e8bd937a0f3 | 452:80f7539147a2 |
---|---|
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 std::auto_ptr<IDynamicObject> message(queue_.front()); | 90 std::auto_ptr<IDynamicObject> message(queue_.front()); |
91 queue_.pop_front(); | 91 queue_.pop_front(); |
92 emptied_.notify_all(); | |
92 | 93 |
93 return message.release(); | 94 return message.release(); |
94 } | 95 } |
96 | |
97 | |
98 | |
99 bool SharedMessageQueue::WaitEmpty(int32_t millisecondsTimeout) | |
100 { | |
101 boost::mutex::scoped_lock lock(mutex_); | |
102 | |
103 // Wait for the queue to become empty | |
104 if (!queue_.empty()) | |
105 { | |
106 if (millisecondsTimeout == 0) | |
107 { | |
108 emptied_.wait(lock); | |
109 } | |
110 else | |
111 { | |
112 if (!emptied_.timed_wait | |
113 (lock, boost::posix_time::milliseconds(millisecondsTimeout))) | |
114 { | |
115 return false; | |
116 } | |
117 } | |
118 } | |
119 | |
120 return true; | |
121 } | |
95 } | 122 } |