diff options
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 7858b33..0d14b9b 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -604,11 +604,13 @@ QUuid QUuid::createUuid() randbits = r; } + // Seed the PRNG once per thread with a combination of current time, a + // stack address and a serial counter (since thread stack addresses are + // re-used). +#ifndef QT_BOOTSTRAPPED static QThreadStorage<int *> uuidseed; - if (!uuidseed.hasLocalData()) { - // Seed the PRNG once per thread with a combination of current time, a - // stack address and a serial counter (since thread stack addresses are - // re-used). + if (!uuidseed.hasLocalData()) + { int *pseed = new int; static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2); qsrand(*pseed = QDateTime::currentDateTime().toTime_t() @@ -616,6 +618,12 @@ QUuid QUuid::createUuid() + serial.fetchAndAddRelaxed(1)); uuidseed.setLocalData(pseed); } +#else + static bool seeded = false; + if (!seeded) + qsrand(QDateTime::currentDateTime().toTime_t() + + quintptr(&seeded)); +#endif int chunks = 16 / sizeof(uint); while (chunks--) { |