BOOST_FOREACH.
[dcpomatic.git] / src / lib / job_manager.cc
index c40178f418a8960914193245f8fbebe557eead97..1724879d0656ffe38b0a6962374a1489744af377 100644 (file)
 #include "analyse_subtitles_job.h"
 #include "film.h"
 #include <boost/thread.hpp>
-#include <boost/foreach.hpp>
 #include <iostream>
 
 using std::string;
 using std::list;
 using std::cout;
-using boost::shared_ptr;
-using boost::weak_ptr;
+using std::shared_ptr;
+using std::weak_ptr;
 using boost::function;
-using boost::dynamic_pointer_cast;
+using std::dynamic_pointer_cast;
 using boost::optional;
 using boost::bind;
 
@@ -62,7 +61,9 @@ JobManager::start ()
 
 JobManager::~JobManager ()
 {
-       BOOST_FOREACH (boost::signals2::connection& i, _connections) {
+       boost::this_thread::disable_interruption dis;
+
+       for (auto& i: _connections) {
                i.disconnect ();
        }
 
@@ -72,13 +73,9 @@ JobManager::~JobManager ()
                _empty_condition.notify_all ();
        }
 
-       if (_scheduler.joinable()) {
-               try {
-                       _scheduler.join();
-               } catch (...) {
-
-               }
-       }
+       try {
+               _scheduler.join();
+       } catch (...) {}
 }
 
 shared_ptr<Job>
@@ -134,7 +131,7 @@ bool
 JobManager::errors () const
 {
        boost::mutex::scoped_lock lm (_mutex);
-       BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+       for (auto i: _jobs) {
                if (i->finished_in_error ()) {
                        return true;
                }
@@ -153,7 +150,7 @@ JobManager::scheduler ()
                while (true) {
                        bool have_new = false;
                        bool have_running = false;
-                       BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+                       for (auto i: _jobs) {
                                if (i->running()) {
                                        have_running = true;
                                }
@@ -173,7 +170,7 @@ JobManager::scheduler ()
                        break;
                }
 
-               BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+               for (auto i: _jobs) {
                        if (i->is_new()) {
                                _connections.push_back (i->FinishedImmediate.connect(bind(&JobManager::job_finished, this)));
                                i->start ();
@@ -228,9 +225,9 @@ JobManager::analyse_audio (
        {
                boost::mutex::scoped_lock lm (_mutex);
 
-               BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+               for (auto i: _jobs) {
                        shared_ptr<AnalyseAudioJob> a = dynamic_pointer_cast<AnalyseAudioJob> (i);
-                       if (a && a->path() == film->audio_analysis_path(playlist)) {
+                       if (a && a->path() == film->audio_analysis_path(playlist) && !i->finished_cancelled()) {
                                i->when_finished (connection, ready);
                                return;
                        }
@@ -263,7 +260,7 @@ JobManager::analyse_subtitles (
        {
                boost::mutex::scoped_lock lm (_mutex);
 
-               BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+               for (auto i: _jobs) {
                        shared_ptr<AnalyseSubtitlesJob> a = dynamic_pointer_cast<AnalyseSubtitlesJob> (i);
                        if (a && a->path() == film->subtitle_analysis_path(content)) {
                                i->when_finished (connection, ready);
@@ -317,7 +314,7 @@ JobManager::priority_changed ()
                boost::mutex::scoped_lock lm (_mutex);
 
                bool first = true;
-               BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+               for (auto i: _jobs) {
                        if (first) {
                                if (i->is_new ()) {
                                        i->start ();
@@ -368,7 +365,7 @@ JobManager::pause ()
                return;
        }
 
-       BOOST_FOREACH (shared_ptr<Job> i, _jobs) {
+       for (auto i: _jobs) {
                if (i->pause_by_user()) {
                        _paused_job = i;
                }