summary refs log tree commit diff
path: root/pkgs/development/libraries/mesa/darwin-clock-gettime.patch
blob: 94e90a1c5871c8ad0dc921f79aa25ac6608d1080 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h
index 45cb6075e6..62937311b9 100644
--- a/include/c11/threads_posix.h
+++ b/include/c11/threads_posix.h
@@ -36,6 +36,11 @@
 #include <sched.h>
 #include <stdint.h> /* for intptr_t */
 
+#ifdef __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
+
 /*
 Configuration macro:
 
@@ -383,12 +388,25 @@ tss_set(tss_t key, void *val)
 /*-------------------- 7.25.7 Time functions --------------------*/
 // 7.25.6.1
 #ifndef HAVE_TIMESPEC_GET
+
 static inline int
 timespec_get(struct timespec *ts, int base)
 {
     if (!ts) return 0;
     if (base == TIME_UTC) {
+#ifdef __MACH__
+        if (ts != NULL) {
+            clock_serv_t cclock;
+            mach_timespec_t mts;
+            host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+            clock_get_time(cclock, &mts);
+            mach_port_deallocate(mach_task_self(), cclock);
+            ts->tv_sec = mts.tv_sec;
+            ts->tv_nsec = mts.tv_nsec;
+        }
+#else
         clock_gettime(CLOCK_REALTIME, ts);
+#endif
         return base;
     }
     return 0;
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 1208ebb315..e1378fb1f0 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -65,6 +65,11 @@
 #include "util/u_vector.h"
 #include "mapi/glapi/glapi.h"
 
+#ifdef __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
+
 #define NUM_ATTRIBS 12
 
 static void
@@ -3092,7 +3097,17 @@ dri2_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
 
             /* We override the clock to monotonic when creating the condition
              * variable. */
+#ifdef __MACH__
+            clock_serv_t cclock;
+            mach_timespec_t mts;
+            host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+            clock_get_time(cclock, &mts);
+            mach_port_deallocate(mach_task_self(), cclock);
+            current.tv_sec = mts.tv_sec;
+            current.tv_nsec = mts.tv_nsec;
+#else
             clock_gettime(CLOCK_MONOTONIC, &current);
+#endif
 
             /* calculating when to expire */
             expire.tv_nsec = timeout % 1000000000L;