X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fjob.cc;h=91581eb49550db343718606c5ede43ab249f6774;hb=09c79795becef84621fc1ab411ee72f3d7bea950;hp=784defc91736074e53292fdbcdb4c306341d7d6f;hpb=0ec7c9d0b1f3ea58ffe17dd70bea04ad702d164b;p=dcpomatic.git diff --git a/src/lib/job.cc b/src/lib/job.cc index 784defc91..91581eb49 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include "i18n.h" @@ -39,9 +40,11 @@ using std::list; using std::cout; using boost::shared_ptr; using boost::optional; +using boost::function; #define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_ERROR); +/** @param film Associated film, or 0 */ Job::Job (shared_ptr film) : _film (film) , _thread (0) @@ -57,6 +60,7 @@ Job::~Job () { if (_thread) { _thread->interrupt (); + DCPOMATIC_ASSERT (_thread->joinable ()); _thread->join (); } @@ -131,7 +135,7 @@ Job::run_wrapper () } catch (std::bad_alloc& e) { - set_error (_("Out of memory"), _("There was not enough memory to do this.")); + set_error (_("Out of memory"), _("There was not enough memory to do this. If you are running a 32-bit operating system try reducing the number of encoding threads in the General tab of Preferences.")); set_progress (1); set_state (FINISHED_ERROR); @@ -321,7 +325,9 @@ Job::set_error (string s, string d) LOG_ERROR_NC (s); LOG_ERROR_NC (d); - _film->log()->log (String::compose ("Error in job: %1 (%2)", s, d), Log::TYPE_ERROR); + if (_film) { + _film->log()->log (String::compose ("Error in job: %1 (%2)", s, d), Log::TYPE_ERROR); + } boost::mutex::scoped_lock lm (_state_mutex); _error_summary = s; _error_details = d; @@ -414,7 +420,10 @@ Job::cancel () } _thread->interrupt (); + DCPOMATIC_ASSERT (_thread->joinable ()); _thread->join (); + delete _thread; + _thread = 0; } void @@ -434,3 +443,14 @@ Job::resume () _pause_changed.notify_all (); } } + +void +Job::when_finished (boost::signals2::connection& connection, function finished) +{ + boost::mutex::scoped_lock lm (_state_mutex); + if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) { + finished (); + } else { + connection = Finished.connect (finished); + } +}