Mercurial > hg > orthanc-python
changeset 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 | 53f3920af4c3 |
children | c814297de620 |
files | NEWS Sources/OnChangeCallback.cpp |
diffstat | 2 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Thu Aug 19 11:41:15 2021 +0200 +++ b/NEWS Thu Aug 19 14:18:23 2021 +0200 @@ -1,6 +1,9 @@ Pending changes in the mainline =============================== +* On Orthanc stopping, wait for all the queued events to have been processed +* Docker-based builder scripts distinguishing Debian buster and bullseye + Version 3.3 (2021-08-12) ========================
--- 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(); }