diff Core/JobsEngine/JobsEngine.cpp @ 2570:2e879c796ec7 jobs

JobsRegistry::SubmitAndWait(), StoreScuJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 May 2018 21:42:04 +0200
parents 2af17cd5eb1f
children 3372c5255333
line wrap: on
line diff
--- a/Core/JobsEngine/JobsEngine.cpp	Mon May 07 15:37:20 2018 +0200
+++ b/Core/JobsEngine/JobsEngine.cpp	Mon May 07 21:42:04 2018 +0200
@@ -102,6 +102,7 @@
         return false;
 
       case JobStepCode_Retry:
+        running.GetJob().ReleaseResources();
         running.MarkRetry(dynamic_cast<JobStepRetry&>(*result).GetTimeout());
         return false;
 
@@ -190,11 +191,6 @@
     
   void JobsEngine::SetWorkersCount(size_t count)
   {
-    if (count == 0)
-    {
-      throw OrthancException(ErrorCode_ParameterOutOfRange);
-    }
-      
     boost::mutex::scoped_lock lock(stateMutex_);
       
     if (state_ != State_Setup)
@@ -218,6 +214,19 @@
 
     retryHandler_ = boost::thread(RetryHandler, this);
 
+    if (workers_.size() == 0)
+    {
+      // Use all the available CPUs
+      size_t n = boost::thread::hardware_concurrency();
+      
+      if (n == 0)
+      {
+        n = 1;
+      }
+
+      workers_.resize(n);
+    }      
+
     for (size_t i = 0; i < workers_.size(); i++)
     {
       workers_[i] = boost::thread(Worker, this, i);
@@ -225,7 +234,7 @@
 
     state_ = State_Running;
 
-    LOG(WARNING) << "The jobs engine has started";
+    LOG(WARNING) << "The jobs engine has started with " << workers_.size() << " threads";
   }