Mercurial > hg > orthanc-python
diff Sources/OnChangeCallback.cpp @ 91:55c41aa7053b
On Orthanc stopping, wait for all the queued events to have been processed
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Aug 2021 14:18:23 +0200 |
parents | 0b3ef425db31 |
children | eb6ac5a801d1 |
line wrap: on
line diff
--- a/Sources/OnChangeCallback.cpp Thu Aug 19 11:41:15 2021 +0200 +++ b/Sources/OnChangeCallback.cpp Thu Aug 19 14:18:23 2021 +0200 @@ -80,6 +80,7 @@ boost::mutex mutex_; Queue queue_; boost::condition_variable elementAvailable_; + boost::condition_variable emptied_; public: ~PendingChanges() @@ -123,8 +124,23 @@ std::unique_ptr<PendingChange> change(queue_.front()); queue_.pop_front(); + if (queue_.empty()) + { + emptied_.notify_all(); + } + return change.release(); } + + void WaitEmpty() + { + boost::mutex::scoped_lock lock(mutex_); + + while (!queue_.empty()) + { + emptied_.wait(lock); + } + } }; @@ -198,6 +214,10 @@ if (changeType == OrthancPluginChangeType_OrthancStopped) { + // If stopping, make sure to have processed all the events that + // are pending in the queue before returning (new in 3.4) + pendingChanges_.WaitEmpty(); + StopThread(); }