patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Problem: Using gettimeofday() for timeout is very inefficient.
Solution: Set a platform dependent timer. (Paul Ollis, closes #10505)
diff --git a/src/os_mac.h b/src/os_mac.h
index dbc0086..f6ed121 100644
--- a/src/os_mac.h
+++ b/src/os_mac.h
@@ -6,6 +6,9 @@
* Do ":help credits" in Vim to see a list of people who contributed.
*/
+#ifndef OS_MAC__H
+#define OS_MAC__H
+
// Before Including the MacOS specific files,
// let's set the OPAQUE_TOOLBOX_STRUCTS to 0 so we
// can access the internal structures.
@@ -266,3 +269,52 @@
// A Mac constant causing big problem to syntax highlighting
#define UNKNOWN_CREATOR '\?\?\?\?'
+
+#ifdef FEAT_RELTIME
+
+# include <dispatch/dispatch.h>
+
+# if !defined(MAC_OS_X_VERSION_10_12) || \
+ (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12)
+typedef int clockid_t;
+# endif
+# ifndef CLOCK_REALTIME
+# define CLOCK_REALTIME 0
+# endif
+# ifndef CLOCK_MONOTONIC
+# define CLOCK_MONOTONIC 1
+# endif
+
+struct itimerspec
+{
+ struct timespec it_interval; // timer period
+ struct timespec it_value; // initial expiration
+};
+
+struct sigevent;
+
+struct macos_timer
+{
+ dispatch_queue_t tim_queue;
+ dispatch_source_t tim_timer;
+ void (*tim_func)(union sigval);
+ void *tim_arg;
+};
+
+typedef struct macos_timer *timer_t;
+
+extern int timer_create(
+ clockid_t clockid,
+ struct sigevent *sevp,
+ timer_t *timerid);
+
+extern int timer_delete(timer_t timerid);
+
+extern int timer_settime(
+ timer_t timerid, int flags,
+ const struct itimerspec *new_value,
+ struct itimerspec *unused);
+
+#endif // FEAT_RELTIME
+
+#endif // OS_MAC__H