summaryrefslogtreecommitdiff
path: root/src/os_mac.h
diff options
context:
space:
mode:
authorPaul Ollis <paul@cleversheep.org>2022-06-05 16:55:54 +0100
committerBram Moolenaar <Bram@vim.org>2022-06-05 16:55:54 +0100
commit6574577cacd393ab7591fc776ea060eebc939e55 (patch)
treef583ca9957280e7086b8d14ef44127302829fd40 /src/os_mac.h
parent1d97db3d987c05af88c30ad20f537bcf3024f9c1 (diff)
downloadvim-git-6574577cacd393ab7591fc776ea060eebc939e55.tar.gz
patch 8.2.5057: using gettimeofday() for timeout is very inefficientv8.2.5057
Problem: Using gettimeofday() for timeout is very inefficient. Solution: Set a platform dependent timer. (Paul Ollis, closes #10505)
Diffstat (limited to 'src/os_mac.h')
-rw-r--r--src/os_mac.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/os_mac.h b/src/os_mac.h
index dbc0086e0..f6ed1216c 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