From: Helmut Grohne <helmut.grohne@intenta.de>
To: Jack Winch <sunt.un.morcov@gmail.com>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Bartosz Golaszewski <bartekgola@gmail.com>
Subject: Re: [libgpiod] cxx bindings: time_point vs duration
Date: Thu, 22 Oct 2020 08:39:35 +0200 [thread overview]
Message-ID: <20201022063935.GA23978@laureti-dev> (raw)
In-Reply-To: <CAFhCfDa7Yy2a9-ddk0nZmNidar_-H_ONTU93Cb+YatcEGy3NbQ@mail.gmail.com>
On Wed, Oct 21, 2020 at 03:57:34PM +0200, Jack Winch wrote:
> > I don't thing nanosecond resolution is
> > guarantueed, but maybe this is good enough and you can just use
> > steady_clock? That would certainly be most welcome by consuming client
> > code.
>
> You are correct - nanosecond resolution is not guaranteed. It is
> completely up to the standard library implementation. Which is why I,
> personally, would steer away from making the proposed change to struct
> line_event . The timestamp resolution is currently well defined in
> the existing implementation and changing this may not be desirable for
> users. If you really want a std::time_point, then you can construct
> one from a std::duration object. See
> https://en.cppreference.com/w/cpp/chrono/time_point/time_point.
You're arguing that a std::chrono::steady_clock::time_point is not a
good match due to its undefined ratio. That can be fixed by using a
clock with a well-defined ratio.
The key here is that while you can easily convert your duration to a
time_point, a duration is conceptually the wrong thing to use. The field
does not contain a duration, but a time_point. Using a clock would give
the user the ability to compare returned timestamps to the current time
as the underlying clock provides that functionality.
So regardless of whether steady_clock is the right clock to use here, a
duration clearly is not. If you are not satisfied with the resolution
guarantuee of steady_clock, just make your own clock. Doing so results
in a lot of type safety. For instance, if you accidentally compute a
difference between a system_clock::time_point and a gpiod timestamp,
using a duration would just work whereas a time_point would result in a
compilation failure.
Helmut
next prev parent reply other threads:[~2020-10-22 6:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-15 8:38 [libgpiod] cxx bindings: time_point vs duration Helmut Grohne
2020-10-15 9:26 ` Bartosz Golaszewski
2020-10-15 9:35 ` Helmut Grohne
2020-10-15 10:05 ` Bartosz Golaszewski
2020-10-15 10:57 ` Helmut Grohne
2020-10-15 11:43 ` Bartosz Golaszewski
2020-10-15 12:13 ` Helmut Grohne
2020-10-15 12:16 ` Bartosz Golaszewski
2020-10-21 13:57 ` Jack Winch
2020-10-21 14:35 ` Jack Winch
2020-10-21 15:14 ` Bartosz Golaszewski
2020-10-21 15:44 ` Jack Winch
2020-10-22 6:39 ` Helmut Grohne [this message]
2020-10-22 9:09 ` Jack Winch
2020-10-22 9:35 ` Bartosz Golaszewski
2020-10-22 9:47 ` Jack Winch
2020-10-22 11:55 ` Bartosz Golaszewski
2020-10-22 12:22 ` Jack Winch
2020-10-23 16:22 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201022063935.GA23978@laureti-dev \
--to=helmut.grohne@intenta.de \
--cc=bartekgola@gmail.com \
--cc=brgl@bgdev.pl \
--cc=linux-gpio@vger.kernel.org \
--cc=sunt.un.morcov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).