-
- Downloads
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:Nadav Har'El <nyh@cloudius-systems.com> Signed-off-by:
Pekka Enberg <penberg@cloudius-systems.com>
Loading
Please register or sign in to comment