fix_for_xcode8_clock_gettime
This commit is contained in:
parent
1855e36179
commit
ed697fa4ad
@ -67,6 +67,7 @@
|
||||
|
||||
#include "../pipe/pipe.h"
|
||||
|
||||
/* clock_gettime is not implemented on OSX prior to 10.12 */
|
||||
#ifdef __MACH__
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
@ -74,7 +75,11 @@
|
||||
#define CLOCK_REALTIME 0
|
||||
#define CLOCK_MONOTONIC 0
|
||||
|
||||
int clock_gettime(int clk_id, struct timespec *t)
|
||||
/* clock_gettime is not implemented on OSX prior to 10.12 */
|
||||
int _mach_clock_gettime(int clk_id, struct timespec *t);
|
||||
|
||||
int
|
||||
_mach_clock_gettime(int clk_id, struct timespec *t)
|
||||
{
|
||||
UINT64 time;
|
||||
double seconds;
|
||||
@ -89,6 +94,25 @@ int clock_gettime(int clk_id, struct timespec *t)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if clock_gettime is declared, then __CLOCK_AVAILABILITY will be defined */
|
||||
#ifdef __CLOCK_AVAILABILITY
|
||||
/* If we compiled with Mac OSX 10.12 or later, then clock_gettime will be declared
|
||||
* * but it may be NULL at runtime. So we need to check before using it. */
|
||||
int _mach_safe_clock_gettime(int clk_id, struct timespec *t);
|
||||
|
||||
int
|
||||
_mach_safe_clock_gettime(int clk_id, struct timespec *t) {
|
||||
if( clock_gettime ) {
|
||||
return clock_gettime(clk_id, t);
|
||||
}
|
||||
return _mach_clock_gettime(clk_id, t);
|
||||
}
|
||||
|
||||
#define clock_gettime _mach_safe_clock_gettime
|
||||
#else
|
||||
#define clock_gettime _mach_clock_gettime
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user