summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-11-24 00:16:15 +0100
committerCarl Hetherington <cth@carlh.net>2021-11-28 21:12:14 +0100
commitd41a59b6ef7a8c935f182d498ae4df0bdd66ba02 (patch)
tree5c2ceaf73b74fba1c5daaeec483a3aff054ca444 /src/lib
parent07b21bb92a8d54c6c03de9aadc63ab93b65d9bc5 (diff)
Simplify and fix job scheduler, especially with respect to the priority system.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/job_manager.cc72
-rw-r--r--src/lib/job_manager.h1
2 files changed, 19 insertions, 54 deletions
diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc
index d8c0b02f2..608df7ef0 100644
--- a/src/lib/job_manager.cc
+++ b/src/lib/job_manager.cc
@@ -159,39 +159,30 @@ JobManager::scheduler ()
boost::mutex::scoped_lock lm (_mutex);
- while (true) {
- bool have_new = false;
- bool have_running = false;
- for (auto i: _jobs) {
- if (i->running()) {
- have_running = true;
- }
- if (i->is_new()) {
- have_new = true;
- }
- }
-
- if ((!have_running && have_new) || _terminate) {
- break;
- }
-
- _empty_condition.wait (lm);
- }
-
if (_terminate) {
break;
}
+ bool have_running = false;
for (auto i: _jobs) {
- if (i->is_new()) {
- _connections.push_back (i->FinishedImmediate.connect(bind(&JobManager::job_finished, this)));
- i->start ();
+ if (have_running && i->running()) {
+ i->pause_by_priority();
+ } else if (!have_running && (i->is_new() || i->paused_by_priority())) {
+ if (i->is_new()) {
+ _connections.push_back (i->FinishedImmediate.connect(bind(&JobManager::job_finished, this)));
+ i->start ();
+ } else {
+ i->resume ();
+ }
emit (boost::bind (boost::ref (ActiveJobsChanged), _last_active_job, i->json_name()));
_last_active_job = i->json_name ();
- /* Only start one job at once */
- break;
+ have_running = true;
+ } else if (!have_running && i->running()) {
+ have_running = true;
}
}
+
+ _empty_condition.wait (lm);
}
}
@@ -319,35 +310,9 @@ JobManager::increase_priority (shared_ptr<Job> job)
}
if (changed) {
- priority_changed ();
- }
-}
-
-
-void
-JobManager::priority_changed ()
-{
- {
- boost::mutex::scoped_lock lm (_mutex);
-
- bool first = true;
- for (auto i: _jobs) {
- if (first) {
- if (i->is_new ()) {
- i->start ();
- } else if (i->paused_by_priority ()) {
- i->resume ();
- }
- first = false;
- } else {
- if (i->running ()) {
- i->pause_by_priority ();
- }
- }
- }
+ _empty_condition.notify_all ();
+ emit (boost::bind(boost::ref(JobsReordered)));
}
-
- emit (boost::bind(boost::ref(JobsReordered)));
}
@@ -370,7 +335,8 @@ JobManager::decrease_priority (shared_ptr<Job> job)
}
if (changed) {
- priority_changed ();
+ _empty_condition.notify_all ();
+ emit (boost::bind(boost::ref(JobsReordered)));
}
}
diff --git a/src/lib/job_manager.h b/src/lib/job_manager.h
index ff5800aa8..71db33fd6 100644
--- a/src/lib/job_manager.h
+++ b/src/lib/job_manager.h
@@ -96,7 +96,6 @@ private:
~JobManager ();
void scheduler ();
void start ();
- void priority_changed ();
void job_finished ();
mutable boost::mutex _mutex;