changeset 2110:5b818f677dd6

fix in BagOfTasksProcessor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 Oct 2016 15:36:39 +0200
parents d5c29fd74ffa
children 64d0224595cc
files Core/MultiThreading/BagOfTasksProcessor.cpp Core/MultiThreading/BagOfTasksProcessor.h
diffstat 2 files changed, 32 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Core/MultiThreading/BagOfTasksProcessor.cpp	Wed Oct 26 13:32:02 2016 +0200
+++ b/Core/MultiThreading/BagOfTasksProcessor.cpp	Wed Oct 26 15:36:39 2016 +0200
@@ -33,8 +33,10 @@
 #include "../PrecompiledHeaders.h"
 #include "BagOfTasksProcessor.h"
 
+#include "../Logging.h"
 #include "../OrthancException.h"
 
+#include <stdio.h>
 
 namespace Orthanc
 {
@@ -58,12 +60,19 @@
       {
         return command_->Execute();
       }
-      catch (OrthancException&)
+      catch (OrthancException& e)
       {
+        LOG(ERROR) << "Exception while processing a bag of tasks: " << e.What();
         return false;
       }
-      catch (std::runtime_error&)
+      catch (std::runtime_error& e)
       {
+        LOG(ERROR) << "Runtime exception while processing a bag of tasks: " << e.what();
+        return false;
+      }
+      catch (...)
+      {
+        LOG(ERROR) << "Native exception while processing a bag of tasks";
         return false;
       }
     }
@@ -75,6 +84,20 @@
   };
 
 
+  void BagOfTasksProcessor::SignalProgress(Task& task,
+                                           Bag& bag)
+  {
+    assert(bag.done_ < bag.size_);
+
+    bag.done_ += 1;
+
+    if (bag.done_ == bag.size_)
+    {
+      exitStatus_[task.GetBag()] = (bag.status_ == BagStatus_Running);
+      bagFinished_.notify_all();
+    }
+  }
+
   void BagOfTasksProcessor::Worker(BagOfTasksProcessor* that)
   {
     while (that->continue_)
@@ -93,8 +116,9 @@
 
           if (bag->second.status_ != BagStatus_Running)
           {
-            // This bag of task has failed or is tagged as canceled, do nothing
-            bag->second.done_ += 1;
+            // Do not execute this task, as its parent bag of tasks
+            // has failed or is tagged as canceled
+            that->SignalProgress(task, bag->second);
             continue;
           }
         }
@@ -112,14 +136,7 @@
             bag->second.status_ = BagStatus_Failed;
           }
 
-          assert(bag->second.done_ < bag->second.size_);
-          bag->second.done_ += 1;
-
-          if (bag->second.done_ == bag->second.size_)
-          {
-            that->exitStatus_[task.GetBag()] = (bag->second.status_ == BagStatus_Running);
-            that->bagFinished_.notify_all();
-          }
+          that->SignalProgress(task, bag->second);
         }
       }
     }
--- a/Core/MultiThreading/BagOfTasksProcessor.h	Wed Oct 26 13:32:02 2016 +0200
+++ b/Core/MultiThreading/BagOfTasksProcessor.h	Wed Oct 26 15:36:39 2016 +0200
@@ -97,6 +97,9 @@
 
     float GetProgress(int64_t bag);
 
+    void SignalProgress(Task& task,
+                        Bag& bag);
+
   public:
     class Handle : public boost::noncopyable
     {