From 230cef34626cd627a18e2d521123a15abf2569e7 Mon Sep 17 00:00:00 2001
From: Vladimir Davydov <vdavydov.dev@gmail.com>
Date: Fri, 18 Aug 2017 18:15:03 +0300
Subject: [PATCH] libev: export ev_monotonic_now() and ev_monotonic_time()

ev_now()/ev_time() are affected by system time changes, which makes them
impractical for calculating timeouts. Introduce ev_monotonic_now() and
ev_monotonic_time() which work exactly as ev_now()/ev_time(), but use
monotonic clock instead of realtime.

Needed for #2527
---
 third_party/libev/ev.c | 12 ++++++++++++
 third_party/libev/ev.h |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/third_party/libev/ev.c b/third_party/libev/ev.c
index c9b0ca4e94..6a26485919 100644
--- a/third_party/libev/ev.c
+++ b/third_party/libev/ev.c
@@ -1902,6 +1902,18 @@ ev_now (EV_P) EV_THROW
 }
 #endif
 
+ev_tstamp
+ev_monotonic_now (EV_P) EV_THROW
+{
+  return mn_now;
+}
+
+ev_tstamp
+ev_monotonic_time (void) EV_THROW
+{
+  return get_clock();
+}
+
 void
 ev_sleep (ev_tstamp delay) EV_THROW
 {
diff --git a/third_party/libev/ev.h b/third_party/libev/ev.h
index 6c0e59cafd..d42e2df476 100644
--- a/third_party/libev/ev.h
+++ b/third_party/libev/ev.h
@@ -606,6 +606,9 @@ ev_is_default_loop (void) EV_THROW
 
 #endif /* multiplicity */
 
+EV_API_DECL ev_tstamp ev_monotonic_time (void) EV_THROW;
+EV_API_DECL ev_tstamp ev_monotonic_now (EV_P) EV_THROW;
+
 /* destroy event loops, also works for the default loop */
 EV_API_DECL void ev_loop_destroy (EV_P);
 
-- 
GitLab