diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-10-06 06:42:09 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-10-07 06:14:49 +0300 |
commit | 9d250417a2583c2cad663fe3d8a93959182e3b2b (patch) | |
tree | d87f00c05f70cb53c1383df3fcfb6b77319fb564 /src | |
parent | ada18bf65a1c343b6994bfd9f23b39aae8d9a9c5 (diff) |
libcamera: timer: Add start() method with absolute deadline
The Timer class is started using a timer duration. To help callers that
require waiting for an absolute deadline, add a start() overload that
takes a std::chrono::steady_clock::time_point value. This will be used
by IPAs.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/timer.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index 8749d66c..ddb20954 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -37,6 +37,11 @@ LOG_DEFINE_CATEGORY(Timer) * stop(), and once it times out or is stopped, can be started again with * start(). * + * The timer deadline is specified as either a duration in milliseconds or an + * absolute time point. If the deadline is set to the current time or to the + * past, the timer will time out immediately when execution returns to the + * event loop of the timer's thread. + * * Timers run in the thread they belong to, and thus emit the \a ref timeout * signal from that thread. To avoid race conditions they must not be started * or stopped from a different thread, attempts to do so will be rejected and @@ -75,16 +80,27 @@ Timer::~Timer() */ void Timer::start(std::chrono::milliseconds duration) { + start(utils::clock::now() + duration); +} + +/** + * \brief Start or restart the timer with a \a deadline + * \param[in] deadline The timer deadline + * + * This method shall be called from the thread the timer is associated with. If + * the timer is already running it will be stopped and restarted. + */ +void Timer::start(std::chrono::steady_clock::time_point deadline) +{ if (Thread::current() != thread()) { LOG(Timer, Error) << "Timer can't be started from another thread"; return; } - deadline_ = utils::clock::now() + duration; + deadline_ = deadline; LOG(Timer, Debug) - << "Starting timer " << this << " with duration " - << duration.count() << ": deadline " + << "Starting timer " << this << ": deadline " << utils::time_point_to_string(deadline_); if (isRunning()) |