summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-06-25 22:21:44 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-06-27 20:00:17 +0200
commit8da3eea4fb702c2dc369c1628e91a034569aa9f0 (patch)
treedfba3d5c551cbe4355f0cc3f11a783a5a2586dab /src/gui
parent6fa34930c23c7494a3f2703777f46794ff091e2b (diff)
Optimize some atomic counters
Define the static QAtomic at file scope to avoid GCC's pessimisation with function-static QAtomic (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79561), and make sure the initial value is 0, so it ends up in BSS, not TEXT. In QRhi..., don't create a static instance of the wrapper class, use a file- static atomic, too. This turns the class into a glorified namespace. Change-Id: I707f628e2b434330028077223071716d5704ba32 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/rhi/qrhi.cpp5
-rw-r--r--src/gui/rhi/qrhi_p_p.h4
-rw-r--r--src/gui/text/qfont.cpp4
3 files changed, 5 insertions, 8 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index dbad63c6d1..927de859dd 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -5192,10 +5192,11 @@ int QRhi::ubufAlignment() const
return d->ubufAlignment();
}
+static QBasicAtomicInteger<QRhiGlobalObjectIdGenerator::Type> counter = Q_BASIC_ATOMIC_INITIALIZER(0);
+
QRhiGlobalObjectIdGenerator::Type QRhiGlobalObjectIdGenerator::newId()
{
- static QRhiGlobalObjectIdGenerator inst;
- return ++inst.counter;
+ return counter.fetchAndAddRelaxed(1) + 1;
}
bool QRhiPassResourceTracker::isEmpty() const
diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h
index 4fd01d3ef2..83d521f441 100644
--- a/src/gui/rhi/qrhi_p_p.h
+++ b/src/gui/rhi/qrhi_p_p.h
@@ -52,7 +52,6 @@
#include "qrhiprofiler_p_p.h"
#include <QBitArray>
#include <QAtomicInt>
-#include <QAtomicInteger>
QT_BEGIN_NAMESPACE
@@ -484,9 +483,6 @@ public:
using Type = quint32;
#endif
static Type newId();
-
-private:
- QAtomicInteger<Type> counter;
};
class QRhiPassResourceTracker
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index 5555422b82..2a1d207702 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -2799,12 +2799,12 @@ void QFontCache::cleanup()
cache->setLocalData(0);
}
-QBasicAtomicInt font_cache_id = Q_BASIC_ATOMIC_INITIALIZER(1);
+static QBasicAtomicInt font_cache_id = Q_BASIC_ATOMIC_INITIALIZER(0);
QFontCache::QFontCache()
: QObject(), total_cost(0), max_cost(min_cost),
current_timestamp(0), fast(false), timer_id(-1),
- m_id(font_cache_id.fetchAndAddRelaxed(1))
+ m_id(font_cache_id.fetchAndAddRelaxed(1) + 1)
{
}