Skip to content
Snippets Groups Projects
Commit 692a2a9c authored by Nadav Har'El's avatar Nadav Har'El Committed by Pekka Enberg
Browse files

time.cc: generalize the std::chrono -> timespec conversion


The code "file_ts" converting a std::chrono::duration into a struct timespec,
was unnecessarily constrained to take as input a std::chrono::nanoseconds,
whereas it can actually work with durations of any resolution (the
duration_cast will convert it to the correct units), so this patch makes
this generalization which, I think, makes the code clearer.

At first I decided to move this general function into <osv/clock.hh> and
make it a bit more friendly (returning a timespec, instead of writing into
one), but at the end, I decided not to move it. typespec is a dangerous
type because though it does specify the clock's resolution (always
nanoseconds) it doesn't specify the clock's epoch, so one can make mistakes
like calling clock_gettime(CLOCK_MONOTONIC), and pass the returned timespec
to pthread_cond_timedwait, which expects CLOCK_REALTIME not CLOCK_MONOTONIC.
So we should avoid timespec whenever we can, and I don't think we'll need
the fill_ts() function anywhere outside time.cc.

Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent ad941117
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment