From 5723d8d8518ad1cc0fef8bcc34a47671ab959fb3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 4 Nov 2021 23:43:54 +0100 Subject: [PATCH] Add Job::seconds_since_last_progress_update(). --- src/lib/job.cc | 16 ++++++++++++++++ src/lib/job.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/lib/job.cc b/src/lib/job.cc index cb2120de1..4c8199bdc 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -361,6 +361,22 @@ Job::check_for_interruption_or_pause () } } + +optional +Job::seconds_since_last_progress_update () const +{ + boost::mutex::scoped_lock lm (_progress_mutex); + if (!_last_progress_update) { + return {}; + } + + struct timeval now; + gettimeofday (&now, 0); + + return seconds(now) - seconds(*_last_progress_update); +} + + /** Set the progress of the current part of the job. * @param p Progress (from 0 to 1) * @param force Do not ignore this update, even if it hasn't been long since the last one. diff --git a/src/lib/job.h b/src/lib/job.h index 96f0acbe5..b44fd1365 100644 --- a/src/lib/job.h +++ b/src/lib/job.h @@ -81,6 +81,7 @@ public: void set_progress (float, bool force = false); void sub (std::string); boost::optional progress () const; + boost::optional seconds_since_last_progress_update () const; std::shared_ptr film () const { return _film; -- 2.30.2