changeset 58:ef1a1ce0c1e3

During Orthanc shutdown, wait for all the pending events to have been processed
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 22 Jan 2021 07:36:18 +0100
parents 46fe70776d61
children d88ae86b7b79
files NEWS Sources/OnChangeCallback.cpp
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Jan 21 18:27:06 2021 +0100
+++ b/NEWS	Fri Jan 22 07:36:18 2021 +0100
@@ -2,6 +2,7 @@
 ===============================
 
 * Fix possible deadlock with "orthanc.RegisterOnChangeCallback()"
+* During Orthanc shutdown, wait for all the pending events to have been processed
 
 
 Version 3.0 (2020-12-09)
--- a/Sources/OnChangeCallback.cpp	Thu Jan 21 18:27:06 2021 +0100
+++ b/Sources/OnChangeCallback.cpp	Fri Jan 22 07:36:18 2021 +0100
@@ -135,6 +135,17 @@
 static PyObject*       changesCallback_ = NULL;
 
 
+static void StopThread()
+{
+  stopping_ = true;
+
+  if (changesThread_.joinable())
+  {
+    changesThread_.join();
+  }
+}
+
+
 static void ChangesWorker()
 {
   while (!stopping_)
@@ -184,6 +195,12 @@
                                                const char* resourceId)
 {
   pendingChanges_.Enqueue(changeType, resourceType, resourceId);
+
+  if (changeType == OrthancPluginChangeType_OrthancStopped)
+  {
+    StopThread();
+  }
+  
   return OrthancPluginErrorCode_Success;
 }
 
@@ -227,12 +244,7 @@
 
 void FinalizeOnChangeCallback()
 {
-  stopping_ = true;
-
-  if (changesThread_.joinable())
-  {
-    changesThread_.join();
-  }
+  StopThread();
 
   {
     PythonLock lock;