Re: [libgpiod][PATCH] bindings: cxx: fix event timestamp calculation for 32bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 9, 2020 at 3:40 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
>
> Use appropriate C++ chrono library functions to convert the event
> timestamp from a struct timespec to ::std::chrono::nanoseconds to
> ensure correct conversion independent of platform.
>
> Reported-by: Florian Evers <florian-evers@xxxxxx>
> Signed-off-by: Kent Gibson <warthog618@xxxxxxxxx>
> ---
>
> Florian suggests a C cast before the multiply, but using the C++ library
> to do all the work, which removes the 1000000000 as well, seems the more
> correct way to go to me.
>
> I don't have a 32bit setup handy to test this, so perhaps Florian could
> check if it works for him?
>
> Cheers,
> Kent.
>
>  bindings/cxx/line.cpp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp
> index 11deae6..b71b6db 100644
> --- a/bindings/cxx/line.cpp
> +++ b/bindings/cxx/line.cpp
> @@ -215,8 +215,9 @@ line_event line::make_line_event(const ::gpiod_line_event& event) const noexcept
>         else if (event.event_type == GPIOD_LINE_EVENT_FALLING_EDGE)
>                 ret.event_type = line_event::FALLING_EDGE;
>
> -       ret.timestamp = ::std::chrono::nanoseconds(
> -                               event.ts.tv_nsec + (event.ts.tv_sec * 1000000000));
> +       ret.timestamp = ::std::chrono::duration_cast<::std::chrono::nanoseconds>(
> +                                       ::std::chrono::seconds(event.ts.tv_sec))
> +                               + ::std::chrono::nanoseconds(event.ts.tv_nsec);
>
>         ret.source = *this;
>
> --
> 2.28.0
>

Patch applied, thanks!

Bartosz



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux