fix compilation on older mac systems without CLOCK_MONOTONIC
This commit is contained in:
parent
a16d95375f
commit
cc951affac
10
src/init.c
10
src/init.c
@ -115,8 +115,10 @@ mi_stats_t _mi_stats_main = { MI_STATS_NULL };
|
|||||||
Initialization of random numbers
|
Initialization of random numbers
|
||||||
----------------------------------------------------------- */
|
----------------------------------------------------------- */
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <mach/mach_time.h>
|
||||||
#else
|
#else
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
@ -145,10 +147,12 @@ uintptr_t _mi_random_init(uintptr_t seed /* can be zero */) {
|
|||||||
uintptr_t x = (uintptr_t)((void*)&_mi_random_init);
|
uintptr_t x = (uintptr_t)((void*)&_mi_random_init);
|
||||||
x ^= seed;
|
x ^= seed;
|
||||||
// xor with high res time
|
// xor with high res time
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32)
|
||||||
LARGE_INTEGER pcount;
|
LARGE_INTEGER pcount;
|
||||||
QueryPerformanceCounter(&pcount);
|
QueryPerformanceCounter(&pcount);
|
||||||
x ^= (uintptr_t)(pcount.QuadPart);
|
x ^= (uintptr_t)(pcount.QuadPart);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
x ^= (uintptr_t)mach_absolute_time();
|
||||||
#else
|
#else
|
||||||
struct timespec time;
|
struct timespec time;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||||
@ -156,7 +160,7 @@ uintptr_t _mi_random_init(uintptr_t seed /* can be zero */) {
|
|||||||
x ^= (uintptr_t)time.tv_nsec;
|
x ^= (uintptr_t)time.tv_nsec;
|
||||||
#endif
|
#endif
|
||||||
// and do a few randomization steps
|
// and do a few randomization steps
|
||||||
uintptr_t max = ((x ^ (x >> 7)) & 0x0F) + 1;
|
uintptr_t max = ((x ^ (x >> 17)) & 0x0F) + 1;
|
||||||
for (uintptr_t i = 0; i < max; i++) {
|
for (uintptr_t i = 0; i < max; i++) {
|
||||||
x = _mi_random_shuffle(x);
|
x = _mi_random_shuffle(x);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user