From patchwork Tue Mar 22 13:16:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15507 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E1CAFC0F1B for ; Tue, 22 Mar 2022 13:16:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D1F0604E8; Tue, 22 Mar 2022 14:16:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647955003; bh=g9npiaJ1NLUxGnHgqKHo+sbhVxhONahh4QBM2jPes6U=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=p1qhJ+1rQO2o4Qh64ge0PmpmumelGAWq1RUkceK0yF+sKw+ha2NQdztbLFPnUOOLu 6vyJsZnaQJ6swtsYj3x9LCYZObqu7FkUuUR66x9aX4RDGGQ8/Zi3QhcjvF4uynxS7/ yXK/4T/Ql0AadFRXxlJ261/p8+3iJhlNn6BoVQKjtVLFsYoOr3GM05BFpMS5BLUb4c tJbXqeFJV8aI6ITR4ljNrfnM4zsXqrVsN3xHBrW5vOzzQXeVIw5u1eU+6Fc0dGq1b4 bo9y5haCeiuUEnlkP5q2/ozReB8hg3W0jlvTBe/6lUyyITJGfa4cZO8EXmSfqWvIDC jK2UGbPQsdeSQ== Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A9010604C5 for ; Tue, 22 Mar 2022 14:16:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="a8o564gn"; dkim-atps=neutral Received: by mail-wm1-x32d.google.com with SMTP id r64so10923943wmr.4 for ; Tue, 22 Mar 2022 06:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fnC/L+iITI19MxC5UkoX7mdIvfoQD2Z62GPX+M0fcUs=; b=a8o564gnXyng9PE1jo1M1mw5LW14UxFp306hpSMFKjHwc8zQSF+JtmmPy8bJ1Z2wf0 /DnuO9+FEEnYIKisr2rYrtTYmEdE5wsloD9MJm808q6ACJCz4rjrS3tOHh3HyAH4Mnig l/P5TcHASe5tiD2e7MhdTtUp/KOEgLgUEukf0B6A9ydme6YK6Hoj8AnfaPnEck+XCdRk a8NMncRnRj4s1jjwuzMQVHTURybalEx5a0E1b/dRO41cMMDLfOEEPLqiYfv90gwnjez3 qNuJIhLNiyklQZgX6Dk3SDQxaTQevrYehpGBdG6ETY+kE2lGJN7VN76VErW01ilxegH1 kIOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fnC/L+iITI19MxC5UkoX7mdIvfoQD2Z62GPX+M0fcUs=; b=BkaeTGvnkltT++HFmG/tHhJuQh+fKJuTUOphvE8u16dJL0HOHJn3ngndpcO5QYkJkk QMGHPwURq+gxZfHy6TOmrRn+o+o9txSsErnM6JzaqnvIsKUllVqDGXHcpp8HN1Vx3tvb J+QxPWvsa47ZNoJ2NRZakAz9+TvWnwv2vwciPMfql9OY5m3yqmxVnYMZxxL2+38JMcGH /SZQADRdnO4bKTdVU14QeWG+7gJpazdgAtiyGpx0QH4eb5moMr4tlELkwtGD01Vv0WD+ pAyOFild3psBxK6tcK9T/iSd3yKpzSUW2eOO5Li1rqTdLQ6B0jk7RyvG9M5mZeez0OoT Iynw== X-Gm-Message-State: AOAM532tRnVRXqIlD7pIMB/iMwi0UGHZdMH/+kROZ2mv9Qb+MEmw0axq tE/FUnL/6ONs9hkEz4qiDIWtQAC8cctMAQ== X-Google-Smtp-Source: ABdhPJwWZJUlmA43+vd2p02VDwKH18gABY+ar9DSxRQw2eBU0eE11X2i0uj4DZ+9vNocyjJPIczD9A== X-Received: by 2002:adf:fe10:0:b0:203:d794:93e6 with SMTP id n16-20020adffe10000000b00203d79493e6mr22337218wrr.588.1647954999195; Tue, 22 Mar 2022 06:16:39 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id n14-20020a7bcbce000000b0038c7776a300sm2293478wmi.0.2022.03.22.06.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 06:16:38 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 13:16:33 +0000 Message-Id: <20220322131635.2869526-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322131635.2869526-1-naush@raspberrypi.com> References: <20220322131635.2869526-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/3] utils: timer: Allow Timer::start to use utils::Duration 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-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an overload of the Timer::start member function to accept a utils::Duration type for the timer duration. Signed-off-by: Naushir Patuck --- include/libcamera/base/timer.h | 2 ++ src/libcamera/base/timer.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/base/timer.h b/include/libcamera/base/timer.h index 09f1d3229bd5..f42a8cfd4d6d 100644 --- a/include/libcamera/base/timer.h +++ b/include/libcamera/base/timer.h @@ -14,6 +14,7 @@ #include #include +#include namespace libcamera { @@ -27,6 +28,7 @@ public: void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); } void start(std::chrono::milliseconds duration); + void start(utils::Duration duration); void start(std::chrono::steady_clock::time_point deadline); void stop(); bool isRunning() const; diff --git a/src/libcamera/base/timer.cpp b/src/libcamera/base/timer.cpp index 187336e3a1a4..3ff526aea8ae 100644 --- a/src/libcamera/base/timer.cpp +++ b/src/libcamera/base/timer.cpp @@ -85,6 +85,20 @@ void Timer::start(std::chrono::milliseconds duration) start(utils::clock::now() + duration); } +/** + * \brief Start or restart the timer with a timeout of \a duration + * \param[in] duration The timer duration given by \a utils::Duration + * + * If the timer is already running it will be stopped and restarted. + * + * \context This function is \threadbound. + */ +void Timer::start(utils::Duration duration) +{ + auto msec = std::chrono::duration_cast(duration); + start(utils::clock::now() + msec); +} + /** * \brief Start or restart the timer with a \a deadline * \param[in] deadline The timer deadline