Skip to content

Commit 1e62683

Browse files
Andreyogld3dspencer-lunarg
authored andcommitted
Use the clock_gettime() function instead of the obsolescent gettimeofday() function.
clock_gettime() can be used for macos since MacOS 10.12 Sierra, instaead of instead of the obsolescent gettimeofday() function. see POSIX documenation https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html
1 parent ed33199 commit 1e62683

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

cube/gettime.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@
2626

2727
#include <windows.h>
2828

29-
#elif defined(__unix__) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__ANDROID__) || defined(__EPOC32__) || defined(__QNX__)
29+
#elif defined(__unix__) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__ANDROID__) || defined(__EPOC32__) || defined(__QNX__) || defined(__APPLE__)
3030

3131
#include <time.h>
3232

33-
#elif defined(__APPLE__)
34-
35-
#include <sys/time.h>
36-
3733
#endif
3834

3935
uint64_t getTimeInNanoseconds(void) {
@@ -55,7 +51,7 @@ uint64_t getTimeInNanoseconds(void) {
5551
return count.QuadPart / (freq.QuadPart / ns_in_s);
5652
}
5753

58-
#elif defined(__unix__) || defined(__linux) || defined(__linux__) || defined(__ANDROID__) || defined(__QNX__)
54+
#elif defined(__unix__) || defined(__linux) || defined(__linux__) || defined(__ANDROID__) || defined(__QNX__) || defined(__APPLE__)
5955
struct timespec currTime;
6056
clock_gettime(CLOCK_MONOTONIC, &currTime);
6157
return (uint64_t)currTime.tv_sec * ns_in_s + (uint64_t)currTime.tv_nsec;
@@ -66,11 +62,6 @@ uint64_t getTimeInNanoseconds(void) {
6662
clock_gettime(CLOCK_REALTIME, &currTime);
6763
return (uint64_t)currTime.tv_sec * ns_in_s + (uint64_t)currTime.tv_nsec;
6864

69-
#elif defined(__APPLE__)
70-
struct timeval currTime;
71-
gettimeofday(&currTime, NULL);
72-
return (uint64_t)currTime.tv_sec * ns_in_s + (uint64_t)currTime.tv_usec * ns_in_us;
73-
7465
#else
7566
#error getTimeInNanoseconds Not implemented for target OS
7667
#endif

0 commit comments

Comments
 (0)