[{"id":2804,"web_url":"https://patchwork.libcamera.org/comment/2804/","msgid":"<20191006193438.zpe3n6r4ls4ngacp@uno.localdomain>","date":"2019-10-06T19:34:38","subject":"Re: [libcamera-devel] [PATCH 8/9] libcamera: timer: Add start()\n\tmethod with absolute deadline","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Sun, Oct 06, 2019 at 08:32:25AM +0300, Laurent Pinchart wrote:\n> The Timer class is started using a timer duration. To help callers that\n> require waiting for an absolute deadline, add a start() overload that\n> takes a std::chrono::steady_clock::time_point value. This will be used\n> by IPAs.\n>\n> Signed-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(-)\n>\n> diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h\n> index 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>\n> diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp\n> index 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\n'to the past of the current time' or\n'to the past or to the current time' ?\n\notherwise\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\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> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8511A60E1E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Oct 2019 21:32:53 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 0CEE3FF802;\n\tSun,  6 Oct 2019 19:32:52 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Sun, 6 Oct 2019 21:34:38 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191006193438.zpe3n6r4ls4ngacp@uno.localdomain>","References":"<20191006053226.8976-1-laurent.pinchart@ideasonboard.com>\n\t<20191006053226.8976-9-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"66x4qlfdhnfyv46r\"","Content-Disposition":"inline","In-Reply-To":"<20191006053226.8976-9-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 8/9] libcamera: timer: Add start()\n\tmethod with 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 19:32:53 -0000"}},{"id":2812,"web_url":"https://patchwork.libcamera.org/comment/2812/","msgid":"<20191007031400.GJ4740@pendragon.ideasonboard.com>","date":"2019-10-07T03:14:00","subject":"Re: [libcamera-devel] [PATCH 8/9] libcamera: timer: Add start()\n\tmethod with absolute deadline","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Sun, Oct 06, 2019 at 09:34:38PM +0200, Jacopo Mondi wrote:\n> On Sun, Oct 06, 2019 at 08:32:25AM +0300, Laurent Pinchart wrote:\n> > The Timer class is started using a timer duration. To help callers that\n> > require waiting for an absolute deadline, add a start() overload that\n> > takes a std::chrono::steady_clock::time_point value. This will be used\n> > by IPAs.\n> >\n> > Signed-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(-)\n> >\n> > diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h\n> > index 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> >\n> > diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp\n> > index 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> \n> 'to the past of the current time' or\n> 'to the past or to the current time' ?\n\nThe second option. I'll change that.\n\n> otherwise\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \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())","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 A5E826157C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Oct 2019 05:14:03 +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 CD5FFDD;\n\tMon,  7 Oct 2019 05:14:02 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1570418043;\n\tbh=RB0pTM0uVHZRDaaQ6pMLm/6rghm5v2KqeyS99KZcwug=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=cTd3HEzcyxAgh4WdLkat82K5Z6wF9oItup21k2/cWfBjxp05ANgTezBvZvgM+FytL\n\ttU559LyOVggwVkwXBPMTUDXefFVWBfKXyhhWoxfihx2e9szxNjstk0rAe+ENN5X9Bs\n\tjeJdNfmPsxorkNyipbeam0uRJTOPWcYFX3aerZXw=","Date":"Mon, 7 Oct 2019 06:14:00 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191007031400.GJ4740@pendragon.ideasonboard.com>","References":"<20191006053226.8976-1-laurent.pinchart@ideasonboard.com>\n\t<20191006053226.8976-9-laurent.pinchart@ideasonboard.com>\n\t<20191006193438.zpe3n6r4ls4ngacp@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191006193438.zpe3n6r4ls4ngacp@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 8/9] libcamera: timer: Add start()\n\tmethod with 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":"Mon, 07 Oct 2019 03:14:03 -0000"}}]