From patchwork Sun Oct 6 05:32:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2107 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F6476196C for ; Sun, 6 Oct 2019 07:32:36 +0200 (CEST) Received: from pendragon.ideasonboard.com (modemcable151.96-160-184.mc.videotron.ca [184.160.96.151]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C96873E for ; Sun, 6 Oct 2019 07:32:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1570339955; bh=j1pj0IqYbtPk/mpshRjLG/+gpVQWXI+q/1SuPr2TdyE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VYp9PMFladsZQWUcPyi2fQ3akmFbp6+By79aNSM9RhmRzQrwKPgOzhGDjFz9yivG0 FDP56OncQJ4VtKD4H2CzoNTz5Heo/1oNe1ieGo244o9fRBv6YDMVI2kvNkoyw8nIAt xBYJLKF96uzYVCCEAYINp8wzl4fdy149y+vYtVMc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 6 Oct 2019 08:32:19 +0300 Message-Id: <20191006053226.8976-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191006053226.8976-1-laurent.pinchart@ideasonboard.com> References: <20191006053226.8976-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/9] libcamera: timer: Don't reset deadline after time out X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Oct 2019 05:32:36 -0000 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 Reviewed-by: Jacopo Mondi --- include/libcamera/timer.h | 1 + src/libcamera/timer.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h index 09f426a59993..3540efb41b6f 100644 --- a/include/libcamera/timer.h +++ b/include/libcamera/timer.h @@ -39,6 +39,7 @@ private: void registerTimer(); void unregisterTimer(); + bool running_; std::chrono::steady_clock::time_point deadline_; }; diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp index 34410bab0fb0..8c74e1015e43 100644 --- a/src/libcamera/timer.cpp +++ b/src/libcamera/timer.cpp @@ -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_; } /**