{"id":2113,"url":"https://patchwork.libcamera.org/api/1.1/patches/2113/?format=json","web_url":"https://patchwork.libcamera.org/patch/2113/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20191006053226.8976-9-laurent.pinchart@ideasonboard.com>","date":"2019-10-06T05:32:25","name":"[libcamera-devel,8/9] libcamera: timer: Add start() method with absolute deadline","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"cf2ab6a6f134dc544e3f877b3247e48f8ddee6b3","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2113/mbox/","series":[{"id":522,"url":"https://patchwork.libcamera.org/api/1.1/series/522/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=522","date":"2019-10-06T05:32:17","name":"Timer fixes and enhancements","version":1,"mbox":"https://patchwork.libcamera.org/series/522/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2113/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2113/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AC0B06196F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Oct 2019 07:32:40 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(modemcable151.96-160-184.mc.videotron.ca [184.160.96.151])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E378B73E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Oct 2019 07:32:39 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1570339960;\n\tbh=fzp/Klj2MQpQRsxLIaDQdaRrGuikhrbtdXkb7CRSdAo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=ve9zUSNb9RHXdovg5cx0kRij8l1zA8UMPm0rJo1I5Jx4lrpJFPfCb9p/SRAYaIqKV\n\t9f2YMAbKVxZ2KF1sZnRSPKxXfiW/wa5Gofm93kxkh39W8ErjXX634OFBtLk4ExqKl1\n\t7w/BCznl3QQoC23STCRAFYvbXbDmjpdXKoK03c+U=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sun,  6 Oct 2019 08:32:25 +0300","Message-Id":"<20191006053226.8976-9-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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 8/9] libcamera: timer: Add start() method\n\twith absolute deadline","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sun, 06 Oct 2019 05:32:40 -0000"},"content":"The Timer class is started using a timer duration. To help callers that\nrequire waiting for an absolute deadline, add a start() overload that\ntakes a std::chrono::steady_clock::time_point value. This will be used\nby IPAs.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/timer.h |  1 +\n src/libcamera/timer.cpp   | 22 +++++++++++++++++++---\n 2 files changed, 20 insertions(+), 3 deletions(-)","diff":"diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h\nindex 3540efb41b6f..34e7b8ac8e87 100644\n--- a/include/libcamera/timer.h\n+++ b/include/libcamera/timer.h\n@@ -25,6 +25,7 @@ public:\n \n \tvoid start(unsigned int msec) { start(std::chrono::milliseconds(msec)); }\n \tvoid start(std::chrono::milliseconds duration);\n+\tvoid start(std::chrono::steady_clock::time_point deadline);\n \tvoid stop();\n \tbool isRunning() const;\n \ndiff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp\nindex 8749d66c8662..705ce60b8fbd 100644\n--- a/src/libcamera/timer.cpp\n+++ b/src/libcamera/timer.cpp\n@@ -37,6 +37,11 @@ LOG_DEFINE_CATEGORY(Timer)\n  * stop(), and once it times out or is stopped, can be started again with\n  * start().\n  *\n+ * The timer deadline is specified as either a duration in milliseconds or an\n+ * absolute time point. If the deadline is set to the past or the current time,\n+ * the timer will time out immediately when execution returns to the event\n+ * loop of the timer's thread.\n+ *\n  * Timers run in the thread they belong to, and thus emit the \\a ref timeout\n  * signal from that thread. To avoid race conditions they must not be started\n  * or stopped from a different thread, attempts to do so will be rejected and\n@@ -74,17 +79,28 @@ Timer::~Timer()\n  * the timer is already running it will be stopped and restarted.\n  */\n void Timer::start(std::chrono::milliseconds duration)\n+{\n+\tstart(utils::clock::now() + duration);\n+}\n+\n+/**\n+ * \\brief Start or restart the timer with a \\a deadline\n+ * \\param[in] deadline The timer deadline\n+ *\n+ * This method shall be called from the thread the timer is associated with. If\n+ * the timer is already running it will be stopped and restarted.\n+ */\n+void Timer::start(std::chrono::steady_clock::time_point deadline)\n {\n \tif (Thread::current() != thread()) {\n \t\tLOG(Timer, Error) << \"Timer can't be started from another thread\";\n \t\treturn;\n \t}\n \n-\tdeadline_ = utils::clock::now() + duration;\n+\tdeadline_ = deadline;\n \n \tLOG(Timer, Debug)\n-\t\t<< \"Starting timer \" << this << \" with duration \"\n-\t\t<< duration.count() << \": deadline \"\n+\t\t<< \"Starting timer \" << this << \": deadline \"\n \t\t<< utils::time_point_to_string(deadline_);\n \n \tif (isRunning())\n","prefixes":["libcamera-devel","8/9"]}