summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qrandom.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-10-18 15:58:59 -0700
committerThiago Macieira <thiago.macieira@intel.com>2017-11-11 08:11:09 +0000
commit86d91d2bf8e7ac7a75f88f0e4886140abc06fd4c (patch)
tree6badede9ca348f82c544d5eaa51baa9d149e35b1 /src/corelib/global/qrandom.h
parent08bf28de03f16e5b014b23e228dfc3cfc2ac7feb (diff)
QRandomGenerator: optimize the global() and system() storage
We store both in a single memory structure, instead of two local statics. By construction, we also ensure that the global PRNG mutex is in a different cacheline from the global PRNG state itself. Finally, we don't store the full system QRandomGenerator, since we only need the type member from it. Change-Id: Icaa86fc7b54d4b368c0efffd14eecc48ff05ec27 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/global/qrandom.h')
-rw-r--r--src/corelib/global/qrandom.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/corelib/global/qrandom.h b/src/corelib/global/qrandom.h
index c31c9afddb..bde64646a4 100644
--- a/src/corelib/global/qrandom.h
+++ b/src/corelib/global/qrandom.h
@@ -163,8 +163,8 @@ public:
static Q_DECL_CONSTEXPR result_type min() { return (std::numeric_limits<result_type>::min)(); }
static Q_DECL_CONSTEXPR result_type max() { return (std::numeric_limits<result_type>::max)(); }
- static inline QRandomGenerator *system();
- static inline QRandomGenerator *global();
+ static inline Q_DECL_CONST_FUNCTION QRandomGenerator *system();
+ static inline Q_DECL_CONST_FUNCTION QRandomGenerator *global();
static inline QRandomGenerator securelySeeded();
protected:
@@ -175,12 +175,12 @@ private:
Q_CORE_EXPORT void _fillRange(void *buffer, void *bufferEnd);
friend class QRandomGenerator64;
- struct SystemGeneratorBase {};
struct SystemGenerator;
+ struct SystemAndGlobalGenerators;
typedef std::mt19937 RandomEngine;
union Storage {
- SystemGeneratorBase sys;
+ uint dummy;
#ifdef Q_COMPILER_UNRESTRICTED_UNIONS
RandomEngine twister;
RandomEngine &engine() { return twister; }
@@ -193,7 +193,7 @@ private:
Q_STATIC_ASSERT_X(std::is_trivially_destructible<RandomEngine>::value,
"std::mersenne_twister not trivially destructible as expected");
- Storage();
+ Q_DECL_CONSTEXPR Storage();
};
uint type;
Storage storage;
@@ -237,8 +237,8 @@ public:
static Q_DECL_CONSTEXPR result_type min() { return (std::numeric_limits<result_type>::min)(); }
static Q_DECL_CONSTEXPR result_type max() { return (std::numeric_limits<result_type>::max)(); }
- static Q_CORE_EXPORT QRandomGenerator64 *system();
- static Q_CORE_EXPORT QRandomGenerator64 *global();
+ static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 *system();
+ static Q_DECL_CONST_FUNCTION Q_CORE_EXPORT QRandomGenerator64 *global();
static Q_CORE_EXPORT QRandomGenerator64 securelySeeded();
#endif // Q_QDOC
};