Mercurial > hg > orthanc
changeset 466:9da3596069b8
handling failed commands
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Jul 2013 12:11:45 +0200 |
parents | 7a966b440f19 |
children | 322c1b497036 |
files | Core/ICommand.h Core/MultiThreading/ThreadedCommandProcessor.cpp Core/MultiThreading/ThreadedCommandProcessor.h |
diffstat | 3 files changed, 27 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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; }; }
--- 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; } }
--- 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<boost::thread*> 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(); }; }