using boost::optional;
using boost::function;
-#define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, LogEntry::TYPE_ERROR);
-#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
+#define LOG_ERROR_NC(...) if (_film) { _film->log()->log (__VA_ARGS__, LogEntry::TYPE_ERROR); }
+#define LOG_GENERAL(...) if (_film) { _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL); }
/** @param film Associated film, or 0 */
Job::Job (shared_ptr<const Film> film)
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);
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)));
}
void
Job::set_progress_unknown ()
{
+ check_for_interruption_or_pause ();
set_progress_common (optional<float> ());
}