eio
eio copied to clipboard
Nanoseconds precision clocks : system and mono
This PR add two nanoseconds precision clocks to eio
.
- system_clock () - A system, real-time wall clock. It gives time relative to unix epoch time.
- mono_clock () - A monotonic clock that increments continuously - including during system sleep and hibernation.
The OSes supported are Linux, MacOS, BSDs and Windows (The CI is for MacOS and Windows will be another PR).
Additionally, sleep_until
is now implemented using the given clock(either system or mono) and does not use Unix.gettimeofday
.
The PR doesn't change the representation of time from float
(fractional seconds) to minimize the diff. However, now that we can do nanoseconds precision, we could perhaps use nanoseconds as the default time measurement for the two clocks and provide a helper function to do nanoseconds to fractional seconds (as used by OCaml stdlib).
At the moment we use int64
to represent nanoseconds. I believe this is unboxed due to using @unboxed attribute in the external declaration. I didn't use Optint.t
since int64
is already unboxed.
@talex5 This PR is ready for next round of reviews. I am working on moving some of the monotonic clock functionality to mtime. However, that will probably be another PR.
Closing this in support of https://github.com/ocaml-multicore/eio/pull/308