libcamera: timer: Don't reset deadline after time out

Users of the Timer class may benefit from retrieving the timer deadline
after it times out. This is currently not possible as the deadline is
reset to 0 when the timer times out or is stopped. Fix this by not
resetting the deadline, and adding a new running_ field to the Timer
class to implement isRunning().

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>
This commit is contained in:
Laurent Pinchart
2019-10-06 07:03:34 +03:00
parent e85f42110f
commit 36c35345fa
2 changed files with 5 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ private:
void registerTimer();
void unregisterTimer();
bool running_;
std::chrono::steady_clock::time_point deadline_;
};

View File

@@ -43,7 +43,7 @@ LOG_DEFINE_CATEGORY(Timer)
* \param[in] parent The parent Object
*/
Timer::Timer(Object *parent)
: Object(parent)
: Object(parent), running_(false)
{
}
@@ -89,17 +89,17 @@ void Timer::start(std::chrono::milliseconds duration)
void Timer::stop()
{
unregisterTimer();
deadline_ = utils::time_point();
}
void Timer::registerTimer()
{
thread()->eventDispatcher()->registerTimer(this);
running_ = true;
}
void Timer::unregisterTimer()
{
running_ = false;
thread()->eventDispatcher()->unregisterTimer(this);
}
@@ -109,7 +109,7 @@ void Timer::unregisterTimer()
*/
bool Timer::isRunning() const
{
return deadline_ != utils::time_point();
return running_;
}
/**