at v206 2.6 kB view raw
1diff -Naur libdrm-2.4.26-orig/intel/intel_bufmgr_gem.c libdrm-2.4.26/intel/intel_bufmgr_gem.c 2--- libdrm-2.4.26-orig/intel/intel_bufmgr_gem.c 2011-04-01 10:30:51.000000000 -0400 3+++ libdrm-2.4.26/intel/intel_bufmgr_gem.c 2011-08-29 02:17:20.000000000 -0400 4@@ -51,6 +51,7 @@ 5 #include <sys/stat.h> 6 #include <sys/types.h> 7 #include <stdbool.h> 8+#include <sys/time.h> 9 10 #include "errno.h" 11 #include "libdrm_lists.h" 12@@ -987,9 +988,9 @@ 13 if (atomic_dec_and_test(&bo_gem->refcount)) { 14 drm_intel_bufmgr_gem *bufmgr_gem = 15 (drm_intel_bufmgr_gem *) bo->bufmgr; 16- struct timespec time; 17+ struct timeval time; 18 19- clock_gettime(CLOCK_MONOTONIC, &time); 20+ gettimeofday(&time, NULL); 21 22 pthread_mutex_lock(&bufmgr_gem->lock); 23 drm_intel_gem_bo_unreference_final(bo, time.tv_sec); 24diff -Naur libdrm-2.4.26-orig/xf86drm.c libdrm-2.4.26/xf86drm.c 25--- libdrm-2.4.26-orig/xf86drm.c 2011-03-21 09:39:24.000000000 -0400 26+++ libdrm-2.4.26/xf86drm.c 2011-08-29 02:17:49.000000000 -0400 27@@ -51,6 +51,9 @@ 28 #include <sys/mman.h> 29 #include <sys/time.h> 30 #include <stdarg.h> 31+#if defined(__APPLE__) && defined(__MACH__) 32+#include <mach/mach_time.h> 33+#endif 34 35 /* Not all systems have MAP_FAILED defined */ 36 #ifndef MAP_FAILED 37@@ -1941,20 +1944,43 @@ 38 */ 39 int drmWaitVBlank(int fd, drmVBlankPtr vbl) 40 { 41+#if defined(__APPLE__) && defined(__MACH__) 42+ uint64_t start, end, elapsed, elapsedNano; 43+ static const uint64_t maxElapsed = 2000000000; 44+ static mach_timebase_info_data_t timebaseInfo; 45+ if ( timebaseInfo.denom == 0 ) { 46+ (void) mach_timebase_info(&timebaseInfo); 47+ } 48+#else 49 struct timespec timeout, cur; 50+#endif 51 int ret; 52 53+#if defined(__APPLE__) && defined(__MACH__) 54+ start = mach_absolute_time(); 55+#else 56 ret = clock_gettime(CLOCK_MONOTONIC, &timeout); 57 if (ret < 0) { 58 fprintf(stderr, "clock_gettime failed: %s\n", strerror(ret)); 59 goto out; 60 } 61 timeout.tv_sec++; 62+#endif 63 64 do { 65 ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl); 66 vbl->request.type &= ~DRM_VBLANK_RELATIVE; 67 if (ret && errno == EINTR) { 68+#if defined(__APPLE__) && defined(__MACH__) 69+ end = mach_absolute_time(); 70+ elapsed = end - start; 71+ elapsedNano = elapsed * timebaseInfo.numer / timebaseInfo.denom; 72+ if (elapsedNano > maxElapsed) { 73+ errno = EBUSY; 74+ ret = -1; 75+ break; 76+ } 77+#else 78 clock_gettime(CLOCK_MONOTONIC, &cur); 79 /* Timeout after 1s */ 80 if (cur.tv_sec > timeout.tv_sec + 1 || 81@@ -1964,6 +1990,7 @@ 82 ret = -1; 83 break; 84 } 85+#endif 86 } 87 } while (ret && errno == EINTR); 88