X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fjob.cc;h=a83249e798feba99abafc2a09f1393eb8cf5dc18;hb=5e6588090b65217e180a35bac494ede030406858;hp=43b5fb7e13f50d3672eac81434b0a9e2409f5ee6;hpb=9b98a07cb61fd66fd73f9f58468100ec9b7eddd3;p=dcpomatic.git diff --git a/src/lib/job.cc b/src/lib/job.cc index 43b5fb7e1..a83249e79 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -51,7 +51,6 @@ using namespace dcpomatic; /** @param film Associated film, or 0 */ Job::Job (shared_ptr film) : _film (film) - , _thread (0) , _state (NEW) , _start_time (0) , _sub_start_time (0) @@ -63,26 +62,25 @@ Job::Job (shared_ptr film) Job::~Job () { - stop_thread (); +#ifdef DCPOMATIC_DEBUG + /* Any subclass should have called stop_thread in its destructor */ + assert (!_thread.joinable()); +#endif } void Job::stop_thread () { - if (_thread) { - _thread->interrupt (); - /* We can't use DCPOMATIC_ASSERT here as it may throw an exception */ - if (_thread->joinable ()) { - try { - _thread->join (); - } catch (...) { - /* Too late to do anything about this */ - } - } + if (!_thread.joinable()) { + return; } - delete _thread; - _thread = 0; + _thread.interrupt (); + try { + _thread.join (); + } catch (...) { + /* Too late to do anything about this */ + } } /** Start the job in a separate thread, returning immediately */ @@ -92,9 +90,9 @@ Job::start () set_state (RUNNING); _start_time = time (0); _sub_start_time = time (0); - _thread = new boost::thread (boost::bind (&Job::run_wrapper, this)); + _thread = boost::thread (boost::bind(&Job::run_wrapper, this)); #ifdef DCPOMATIC_LINUX - pthread_setname_np (_thread->native_handle(), "job-wrapper"); + pthread_setname_np (_thread.native_handle(), "job-wrapper"); #endif } @@ -180,12 +178,6 @@ Job::run_wrapper () set_progress (1); set_state (FINISHED_ERROR); - } catch (dcp::MissingAssetError& e) { - - set_error (e.message(), e.path().string()); - set_progress (1); - set_state (FINISHED_ERROR); - } catch (dcp::DCPReadError& e) { set_error (e.message(), e.detail().get_value_or("")); @@ -521,7 +513,7 @@ Job::remaining_time () const void Job::cancel () { - if (!_thread) { + if (!_thread.joinable()) { return; } @@ -529,11 +521,8 @@ Job::cancel () resume (); } - _thread->interrupt (); - DCPOMATIC_ASSERT (_thread->joinable ()); - _thread->join (); - delete _thread; - _thread = 0; + _thread.interrupt (); + _thread.join (); } /** @return true if the job was paused, false if it was not running */