From 32cbd65b41ffd444819c5bcf988ca1f5f1cfe415 Mon Sep 17 00:00:00 2001 From: Ratan Gupta Date: Wed, 7 Mar 2018 16:03:53 +0530 Subject: Timer: Fix the timer expire property. Presently when the call back associated with timer gets called then the expire property becomes true, which is correct as it tells the timer has expired and calls the callback. On the other hand it doesn't set the expire property to false when it starts the timer. This commit sets the expire property to false when startTimer function gets called. Change-Id: I0bb4fe3c375b2a73d214ba9ccbdf25f223b11449 Signed-off-by: Ratan Gupta --- timer.cpp | 4 +++- timer.hpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/timer.cpp b/timer.cpp index 4e8fd9a..06965de 100644 --- a/timer.cpp +++ b/timer.cpp @@ -51,13 +51,14 @@ int Timer::timeoutHandler(sd_event_source* eventSource, auto timer = static_cast(userData); timer->expired = true; + log("Timer expired"); // Call optional user call back function if available if(timer->userCallBack) { timer->userCallBack(); } - log("Timer expired"); + sd_event_source_set_enabled(eventSource, SD_EVENT_OFF); return 0; } @@ -80,6 +81,7 @@ int Timer::startTimer(std::chrono::microseconds timeValue) { // Disable the timer setTimer(SD_EVENT_OFF); + expired = false; // Get the current MONOTONIC time and add the delta auto expireTime = getTime() + timeValue; diff --git a/timer.hpp b/timer.hpp index 6a59c0d..e39d85c 100644 --- a/timer.hpp +++ b/timer.hpp @@ -67,7 +67,7 @@ class Timer * * This is set to true when the timeoutHandler is called into */ - bool expired = false; + bool expired = true; /** @brief Initializes the timer object with infinite * expiration time and sets up the callback handler -- cgit v1.2.1