Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-09-20 13:10:19 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-20 13:10:25 +0300
commit07b482c2ffdf88c6930b621bb0b18c3a5d0c0130 (patch)
tree8970707a878d1ffcd9a99a6321794c5884505613
parent1e3c5fdb85cd27e37c658bf5f9277065d3f7ba13 (diff)
UUID: fix seeding the RNG clock on macOS
On Apple machines, call `clock_gettime()` instead of `timespec_get()`. macOS only introduced `timespec_get()` in version 10.15 (introduced approx two years ago, so in 2019), even though the function is from C11.
-rw-r--r--source/blender/blenlib/intern/uuid.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc
index 247928893f3..5d4f7e1a520 100644
--- a/source/blender/blenlib/intern/uuid.cc
+++ b/source/blender/blenlib/intern/uuid.cc
@@ -39,7 +39,16 @@ UUID BLI_uuid_generate_random()
static_assert(std::mt19937_64::max() == 0xffffffffffffffffLL);
struct timespec ts;
+#ifdef __APPLE__
+ /* `timespec_get()` is only available on macOS 10.15+, so until that's the minimum version
+ * supported by Blender, use another function to get the timespec.
+ *
+ * `clock_gettime()` is only available on POSIX, so not on Windows; Linux uses the newer C++11
+ * function `timespec_get()` as well. */
+ clock_gettime(CLOCK_REALTIME, &ts);
+#else
timespec_get(&ts, TIME_UTC);
+#endif
/* XOR the nanosecond and second fields, just in case the clock only has seconds resolution. */
uint64_t seed = ts.tv_nsec;
seed ^= ts.tv_sec;