1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-21 05:25:38 +00:00
nixpkgs/pkgs/development/libraries/mesa/darwin-clock-gettime.patch

77 lines
2.2 KiB
Diff
Raw Normal View History

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;