X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fjob_manager.cc;h=9105976280dd3b7d5ab58f81a362bdb72dcf5a9d;hb=43b4e55710271c797b5d251c891047ed4da20e10;hp=562c887de9b57479c75f702928ac2ae6aec5d313;hpb=9dd38ef2f05b24ba669acb9805e0914ac227fff2;p=dcpomatic.git diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc index 562c887de..910597628 100644 --- a/src/lib/job_manager.cc +++ b/src/lib/job_manager.cc @@ -26,13 +26,16 @@ #include "job_manager.h" #include "job.h" #include "cross.h" +#include "ui_signaller.h" -using namespace std; -using namespace boost; +using std::string; +using std::list; +using boost::shared_ptr; JobManager* JobManager::_instance = 0; JobManager::JobManager () + : _last_active_jobs (false) { boost::thread (boost::bind (&JobManager::scheduler, this)); } @@ -87,23 +90,39 @@ JobManager::errors () const return false; } - void JobManager::scheduler () { while (1) { + + bool active_jobs = false; + { boost::mutex::scoped_lock lm (_mutex); for (list >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) { - if ((*i)->is_new()) { - shared_ptr r = (*i)->required (); - if (!r || r->finished_ok ()) { - (*i)->start (); - /* Only start one job at once */ - break; - } + if (!(*i)->finished ()) { + active_jobs = true; + } + + if ((*i)->running ()) { + /* Something is already happening */ + break; } + + if ((*i)->is_new()) { + (*i)->start (); + + /* Only start one job at once */ + break; + } + } + } + + if (active_jobs != _last_active_jobs) { + _last_active_jobs = active_jobs; + if (ui_signaller) { + ui_signaller->emit (boost::bind (boost::ref (ActiveJobsChanged), active_jobs)); } }