diff src/os_mac.h @ 29071:b90bca860b5a v8.2.5057

patch 8.2.5057: using gettimeofday() for timeout is very inefficient Commit: https://github.com/vim/vim/commit/6574577cacd393ab7591fc776ea060eebc939e55 Author: Paul Ollis <paul@cleversheep.org> Date: Sun Jun 5 16:55:54 2022 +0100 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 https://github.com/vim/vim/issues/10505)
author Bram Moolenaar <Bram@vim.org>
date Sun, 05 Jun 2022 18:00:08 +0200
parents fc859aea8cec
children 9781c150eddd
line wrap: on
line diff
--- 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