Cleanup: remove unnecessary variable.
[dcpomatic.git] / src / lib / job_manager.cc
index 608df7ef0af9063729824f7c3967d6d76b7a02fe..2b4e872998f72478614557014fe241a2d320d7f1 100644 (file)
@@ -30,6 +30,7 @@
 #include "film.h"
 #include "job.h"
 #include "job_manager.h"
+#include "util.h"
 #include <boost/thread.hpp>
 
 
@@ -294,50 +295,34 @@ JobManager::analyse_subtitles (
 void
 JobManager::increase_priority (shared_ptr<Job> job)
 {
-       bool changed = false;
-
        {
                boost::mutex::scoped_lock lm (_mutex);
-               auto last = _jobs.end ();
-               for (auto i = _jobs.begin(); i != _jobs.end(); ++i) {
-                       if (*i == job && last != _jobs.end()) {
-                               swap (*i, *last);
-                               changed = true;
-                               break;
-                       }
-                       last = i;
+               auto iter = std::find(_jobs.begin(), _jobs.end(), job);
+               if (iter == _jobs.begin() || iter == _jobs.end()) {
+                       return;
                }
+               swap(*iter, *std::prev(iter));
        }
 
-       if (changed) {
-               _empty_condition.notify_all ();
-               emit (boost::bind(boost::ref(JobsReordered)));
-       }
+       _empty_condition.notify_all();
+       emit(boost::bind(boost::ref(JobsReordered)));
 }
 
 
 void
 JobManager::decrease_priority (shared_ptr<Job> job)
 {
-       bool changed = false;
-
        {
                boost::mutex::scoped_lock lm (_mutex);
-               for (auto i = _jobs.begin(); i != _jobs.end(); ++i) {
-                       auto next = i;
-                       ++next;
-                       if (*i == job && next != _jobs.end()) {
-                               swap (*i, *next);
-                               changed = true;
-                               break;
-                       }
+               auto iter = std::find(_jobs.begin(), _jobs.end(), job);
+               if (iter == _jobs.end() || std::next(iter) == _jobs.end()) {
+                       return;
                }
+               swap(*iter, *std::next(iter));
        }
 
-       if (changed) {
-               _empty_condition.notify_all ();
-               emit (boost::bind(boost::ref(JobsReordered)));
-       }
+       _empty_condition.notify_all();
+       emit(boost::bind(boost::ref(JobsReordered)));
 }
 
 
@@ -346,7 +331,7 @@ JobManager::pause ()
 {
        boost::mutex::scoped_lock lm (_mutex);
 
-       if (_paused) {
+       if (_paused_job) {
                return;
        }
 
@@ -355,8 +340,6 @@ JobManager::pause ()
                        _paused_job = i;
                }
        }
-
-       _paused = true;
 }
 
 
@@ -364,14 +347,11 @@ void
 JobManager::resume ()
 {
        boost::mutex::scoped_lock lm (_mutex);
-       if (!_paused) {
-               return;
-       }
 
-       if (_paused_job) {
-               _paused_job->resume ();
+       if (!_paused_job) {
+               return;
        }
 
-       _paused_job.reset ();
-       _paused = false;
+       _paused_job->resume();
+       _paused_job.reset();
 }