diff OrthancServer/Scheduler/ServerScheduler.cpp @ 995:8c67382f44a7 lua-scripting

limit number of jobs in the scheduler
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Jul 2014 15:58:53 +0200
parents c9cdd53a6b31
children db18c071fbd7
line wrap: on
line diff
--- a/OrthancServer/Scheduler/ServerScheduler.cpp	Wed Jul 02 14:42:49 2014 +0200
+++ b/OrthancServer/Scheduler/ServerScheduler.cpp	Thu Jul 03 15:58:53 2014 +0200
@@ -98,11 +98,13 @@
       if (info.watched_)
       {
         watchedJobStatus_[jobId] = JobStatus_Success;
-        jobFinished_.notify_all();
+        watchedJobFinished_.notify_all();
       }
 
       LOG(INFO) << "Job successfully finished (" << info.description_ << ")";
       jobs_.erase(jobId);
+
+      availableJob_.Release();
     }
   }
 
@@ -119,11 +121,13 @@
       if (info.watched_)
       {
         watchedJobStatus_[jobId] = JobStatus_Failure;
-        jobFinished_.notify_all();
+        watchedJobFinished_.notify_all();
       }
 
       LOG(ERROR) << "Job has failed (" << info.description_ << ")";
       jobs_.erase(jobId);
+
+      availableJob_.Release();
     }
   }
 
@@ -166,6 +170,8 @@
   void ServerScheduler::SubmitInternal(ServerJob& job,
                                        bool watched)
   {
+    availableJob_.Acquire();
+
     boost::mutex::scoped_lock lock(mutex_);
 
     JobInfo info;
@@ -189,7 +195,7 @@
   }
 
 
-  ServerScheduler::ServerScheduler()
+  ServerScheduler::ServerScheduler(unsigned int maxJobs) : availableJob_(maxJobs)
   {
     finish_ = false;
     worker_ = boost::thread(Worker, this);
@@ -254,7 +260,7 @@
         
       while (watchedJobStatus_[jobId] == JobStatus_Running)
       {
-        jobFinished_.wait(lock);
+        watchedJobFinished_.wait(lock);
       }
 
       status = watchedJobStatus_[jobId];