mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-13 11:25:02 -05:00
random: don't special case clock usage on macOS
clock_gettime(), CLOCK_MONOTONIC and CLOCK_REALTIME are all available for use on macOS (now that we require macOS >=10.12). Use them rather than the deprecated mach_timespec_t time API. master: 2019-12-23T20:49:43Z Feeding 216 bytes of dynamic environment data into RNG 2019-12-23T20:50:43Z Feeding 216 bytes of dynamic environment data into RNG this commit: 2019-12-23T20:32:41Z Feeding 232 bytes of dynamic environment data into RNG 2019-12-23T20:33:42Z Feeding 232 bytes of dynamic environment data into RNG
This commit is contained in:
parent
8a56f79d49
commit
dc9305b616
1 changed files with 0 additions and 14 deletions
|
@ -237,8 +237,6 @@ void RandAddDynamicEnv(CSHA512& hasher)
|
||||||
GetSystemTimeAsFileTime(&ftime);
|
GetSystemTimeAsFileTime(&ftime);
|
||||||
hasher << ftime;
|
hasher << ftime;
|
||||||
#else
|
#else
|
||||||
# ifndef __MACH__
|
|
||||||
// On non-MacOS systems, use various clock_gettime() calls.
|
|
||||||
struct timespec ts = {};
|
struct timespec ts = {};
|
||||||
# ifdef CLOCK_MONOTONIC
|
# ifdef CLOCK_MONOTONIC
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
@ -251,18 +249,6 @@ void RandAddDynamicEnv(CSHA512& hasher)
|
||||||
# ifdef CLOCK_BOOTTIME
|
# ifdef CLOCK_BOOTTIME
|
||||||
clock_gettime(CLOCK_BOOTTIME, &ts);
|
clock_gettime(CLOCK_BOOTTIME, &ts);
|
||||||
hasher << ts;
|
hasher << ts;
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
// On MacOS use mach_absolute_time (number of CPU ticks since boot) as a replacement for CLOCK_MONOTONIC,
|
|
||||||
// and clock_get_time for CALENDAR_CLOCK as a replacement for CLOCK_REALTIME.
|
|
||||||
hasher << mach_absolute_time();
|
|
||||||
// From https://gist.github.com/jbenet/1087739
|
|
||||||
clock_serv_t cclock;
|
|
||||||
mach_timespec_t mts = {};
|
|
||||||
if (host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock) == KERN_SUCCESS && clock_get_time(cclock, &mts) == KERN_SUCCESS) {
|
|
||||||
hasher << mts;
|
|
||||||
mach_port_deallocate(mach_task_self(), cclock);
|
|
||||||
}
|
|
||||||
# endif
|
# endif
|
||||||
// gettimeofday is available on all UNIX systems, but only has microsecond precision.
|
// gettimeofday is available on all UNIX systems, but only has microsecond precision.
|
||||||
struct timeval tv = {};
|
struct timeval tv = {};
|
||||||
|
|
Loading…
Add table
Reference in a new issue