Speed up response to a request to pause a job.
authorCarl Hetherington <cth@carlh.net>
Fri, 30 Sep 2016 10:35:18 +0000 (11:35 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 30 Sep 2016 10:35:18 +0000 (11:35 +0100)
src/lib/job.cc
src/lib/job.h

index 51deca4044b0a4debc300fed8dfab54ac44cd2d8..1676928632164410582e179c97d5e3c5e7842c33 100644 (file)
@@ -279,12 +279,27 @@ Job::elapsed_sub_time () const
        return time (0) - _sub_start_time;
 }
 
+/** Check to see if this job has been interrupted or paused */
+void
+Job::check_for_interruption_or_pause ()
+{
+       boost::this_thread::interruption_point ();
+
+       boost::mutex::scoped_lock lm (_state_mutex);
+       while (_state == PAUSED) {
+               emit (boost::bind (boost::ref (Progress)));
+               _pause_changed.wait (lm);
+       }
+}
+
 /** Set the progress of the current part of the job.
  *  @param p Progress (from 0 to 1)
  */
 void
 Job::set_progress (float p, bool force)
 {
+       check_for_interruption_or_pause ();
+
        if (!force) {
                /* Check for excessively frequent progress reporting */
                boost::mutex::scoped_lock lm (_progress_mutex);
@@ -306,18 +321,11 @@ Job::set_progress (float p, bool force)
 void
 Job::set_progress_common (optional<float> p)
 {
-       boost::mutex::scoped_lock lm (_progress_mutex);
-       _progress = p;
-       boost::this_thread::interruption_point ();
-
-       boost::mutex::scoped_lock lm2 (_state_mutex);
-       while (_state == PAUSED) {
-               _pause_changed.wait (lm2);
+       {
+               boost::mutex::scoped_lock lm (_progress_mutex);
+               _progress = p;
        }
 
-       lm.unlock ();
-       lm2.unlock ();
-
        emit (boost::bind (boost::ref (Progress)));
 }
 
@@ -378,6 +386,7 @@ Job::set_error (string s, string d)
 void
 Job::set_progress_unknown ()
 {
+       check_for_interruption_or_pause ();
        set_progress_common (optional<float> ());
 }
 
index 804755ef829413850e3b5ffc120ab3a19ab2c2a3..660ddaa132715dc7e4f4dba1cb647344492de441 100644 (file)
@@ -103,6 +103,7 @@ protected:
        void set_state (State);
        void set_error (std::string s, std::string d);
        int elapsed_sub_time () const;
+       void check_for_interruption_or_pause ();
 
        boost::shared_ptr<const Film> _film;