diff Core/MultiThreading/ThreadedCommandProcessor.cpp @ 466:9da3596069b8

handling failed commands
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Jul 2013 12:11:45 +0200
parents d665b8fc8560
children 322c1b497036
line wrap: on
line diff
--- a/Core/MultiThreading/ThreadedCommandProcessor.cpp	Fri Jul 12 11:15:27 2013 +0200
+++ b/Core/MultiThreading/ThreadedCommandProcessor.cpp	Fri Jul 12 12:11:45 2013 +0200
@@ -47,9 +47,19 @@
 
       if (command.get() != NULL)
       {
+        bool success = false;
+
         try
         {
-          dynamic_cast<ICommand&>(*command).Execute();
+          if (that->success_)
+          {
+            // No command has failed so far
+            success = dynamic_cast<ICommand&>(*command).Execute();
+          }
+          else
+          {
+            // A command has already failed. Skip the execution of this command.
+          }
         }
         catch (OrthancException)
         {
@@ -59,6 +69,10 @@
           boost::mutex::scoped_lock lock(that->mutex_);
           assert(that->remainingCommands_ > 0);
           that->remainingCommands_--;
+
+          if (!success)
+            that->success_ = false;
+
           that->processedCommand_.notify_all();
         }
       }
@@ -72,7 +86,8 @@
     {
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
-
+    
+    success_ = true;
     done_ = false;
     threads_.resize(numThreads);
     remainingCommands_ = 0;
@@ -115,7 +130,7 @@
   }
 
 
-  void ThreadedCommandProcessor::Join()
+  bool ThreadedCommandProcessor::Join()
   {
     boost::mutex::scoped_lock lock(mutex_);
 
@@ -123,5 +138,11 @@
     {
       processedCommand_.wait(lock);
     }
+
+    // Reset the "success" flag for subsequent commands
+    bool hasSucceeded = success_;
+    success_ = true;
+
+    return hasSucceeded;
   }
 }