From 04d6495bf773a6bb0d4fa6980df22d3b81a605b0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 14 Feb 2017 01:26:25 +0100 Subject: Make some atomic counters zero-based A variable of static storage duration that is not zero-initialized takes up space in the DATA segment of the executable. By making the counters start at zero and adding the initial value afterwards, we move them over to the BSS segment, which does not take up space in the executable. Wrap atomics used across function boundaries into small functions, to avoid code duplication and to increase readability. Change-Id: Ida6ed316ecb8fe20da62a9577161349e14de5aed Reviewed-by: Thiago Macieira --- src/corelib/plugin/quuid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/plugin') diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index f11ac6548b..1a7073a069 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -968,10 +968,10 @@ QUuid QUuid::createUuid() if (!uuidseed.hasLocalData()) { int *pseed = new int; - static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2); + static QBasicAtomicInt serial; qsrand(*pseed = QDateTime::currentSecsSinceEpoch() + quintptr(&pseed) - + serial.fetchAndAddRelaxed(1)); + + 2 + serial.fetchAndAddRelaxed(1)); uuidseed.setLocalData(pseed); } #else -- cgit v1.2.3