diff Core/JobsEngine/JobsEngine.cpp @ 2665:389d050a2e66 jobs

fix deadlock, speed up unit tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 Jun 2018 13:51:31 +0200
parents 34dc57f4a7d2
children d26dd081df97
line wrap: on
line diff
--- a/Core/JobsEngine/JobsEngine.cpp	Thu Jun 07 21:37:40 2018 +0200
+++ b/Core/JobsEngine/JobsEngine.cpp	Fri Jun 08 13:51:31 2018 +0200
@@ -120,7 +120,7 @@
 
     while (engine->IsRunning())
     {
-      boost::this_thread::sleep(boost::posix_time::milliseconds(200));
+      boost::this_thread::sleep(boost::posix_time::milliseconds(engine->threadSleep_));
       engine->GetRegistry().ScheduleRetries();
     }
   }
@@ -135,7 +135,7 @@
 
     while (engine->IsRunning())
     {
-      JobsRegistry::RunningJob running(engine->GetRegistry(), 100);
+      JobsRegistry::RunningJob running(engine->GetRegistry(), engine->threadSleep_);
 
       if (running.IsValid())
       {
@@ -156,6 +156,7 @@
 
   JobsEngine::JobsEngine() :
     state_(State_Setup),
+    threadSleep_(200),
     workers_(1)
   {
   }
@@ -184,7 +185,21 @@
 
     workers_.resize(count);
   }
-    
+
+
+  void JobsEngine::SetThreadSleep(unsigned int sleep)
+  {
+    boost::mutex::scoped_lock lock(stateMutex_);
+      
+    if (state_ != State_Setup)
+    {
+      // Can only be invoked before calling "Start()"
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+
+    threadSleep_ = sleep;
+  }
+
 
   void JobsEngine::Start()
   {