# HG changeset patch # User Sebastien Jodogne # Date 1373623905 -7200 # Node ID 9da3596069b87c33373655af63d3a25ca98702d1 # Parent 7a966b440f196c3f235be6a26a8851902674f8c6 handling failed commands diff -r 7a966b440f19 -r 9da3596069b8 Core/ICommand.h --- a/Core/ICommand.h Fri Jul 12 11:15:27 2013 +0200 +++ b/Core/ICommand.h Fri Jul 12 12:11:45 2013 +0200 @@ -43,6 +43,6 @@ class ICommand : public IDynamicObject { public: - virtual void Execute() = 0; + virtual bool Execute() = 0; }; } diff -r 7a966b440f19 -r 9da3596069b8 Core/MultiThreading/ThreadedCommandProcessor.cpp --- 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(*command).Execute(); + if (that->success_) + { + // No command has failed so far + success = dynamic_cast(*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; } } diff -r 7a966b440f19 -r 9da3596069b8 Core/MultiThreading/ThreadedCommandProcessor.h --- a/Core/MultiThreading/ThreadedCommandProcessor.h Fri Jul 12 11:15:27 2013 +0200 +++ b/Core/MultiThreading/ThreadedCommandProcessor.h Fri Jul 12 12:11:45 2013 +0200 @@ -46,6 +46,7 @@ std::vector threads_; boost::mutex mutex_; + bool success_; unsigned int remainingCommands_; boost::condition_variable processedCommand_; @@ -59,6 +60,6 @@ // This takes the ownership of the command void Post(ICommand* command); - void Join(); + bool Join(); }; }