diff options
Diffstat (limited to 'src/nvim/os/time.c')
| -rw-r--r-- | src/nvim/os/time.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 31ef1a0cd6..4dd0614fe2 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -9,6 +9,7 @@ #include <uv.h> +#include "nvim/assert.h" #include "nvim/os/time.h" #include "nvim/os/input.h" #include "nvim/event/loop.h" @@ -22,6 +23,7 @@ static uv_cond_t delay_cond; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/time.c.generated.h" #endif + /// Initializes the time module void time_init(void) { @@ -29,15 +31,32 @@ void time_init(void) uv_cond_init(&delay_cond); } -/// Obtain a high-resolution timer value +/// Gets a high-resolution (nanosecond), monotonically-increasing time relative +/// to an arbitrary time in the past. +/// +/// Not related to the time of day and therefore not subject to clock drift. /// -/// @return a timer value, not related to the time of day and not subject -/// to clock drift. The value is expressed in nanoseconds. +/// @return Relative time value with nanosecond precision. uint64_t os_hrtime(void) + FUNC_ATTR_WARN_UNUSED_RESULT { return uv_hrtime(); } +/// Gets a millisecond-resolution, monotonically-increasing time relative to an +/// arbitrary time in the past. +/// +/// Not related to the time of day and therefore not subject to clock drift. +/// The value is cached by the loop, it will not change until the next +/// loop-tick (unless uv_update_time is called). +/// +/// @return Relative time value with millisecond precision. +uint64_t os_now(void) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + return uv_now(&main_loop.uv); +} + /// Sleeps for `ms` milliseconds. /// /// @param ms Number of milliseconds to sleep |
