QWindowsFontDatabase: drop an usage of an atomic type

UniqueFontData has an atomic refcount internally. I guess this was
deemed necessary because font engines living in different threads may
call refUniqueFont / derefUniqueFont and the refcount has to be thread
safe. Those functions now are mutex protected (as they access the same
map), so we don't also need atomicity for the refcounter.

Change-Id: Ic223a12f4a61b7dcc567b3a5dcbe367eaa916004
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2023-09-13 12:54:46 +02:00
parent 0f0ab90cf6
commit cadae8b6e6
2 changed files with 5 additions and 5 deletions

View File

@ -846,9 +846,9 @@ QT_WARNING_POP
Q_ASSERT_X(false, Q_FUNC_INFO, "Unhandled font engine.");
}
UniqueFontData uniqueData;
UniqueFontData uniqueData{};
uniqueData.handle = fontHandle;
uniqueData.refCount.ref();
++uniqueData.refCount;
{
const std::scoped_lock lock(m_uniqueFontDataMutex);
m_uniqueFontData[uniqueFamilyName] = uniqueData;
@ -1150,7 +1150,7 @@ void QWindowsFontDatabase::derefUniqueFont(const QString &uniqueFont)
const std::scoped_lock lock(m_uniqueFontDataMutex);
const auto it = m_uniqueFontData.find(uniqueFont);
if (it != m_uniqueFontData.end()) {
if (!it->refCount.deref()) {
if (--it->refCount == 0) {
RemoveFontMemResourceEx(it->handle);
m_uniqueFontData.erase(it);
}
@ -1162,7 +1162,7 @@ void QWindowsFontDatabase::refUniqueFont(const QString &uniqueFont)
const std::scoped_lock lock(m_uniqueFontDataMutex);
const auto it = m_uniqueFontData.find(uniqueFont);
if (it != m_uniqueFontData.end())
it->refCount.ref();
++it->refCount;
}
QStringList QWindowsFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const

View File

@ -87,7 +87,7 @@ private:
struct UniqueFontData {
HANDLE handle;
QAtomicInt refCount;
int refCount;
};
QMutex m_uniqueFontDataMutex; // protects m_uniqueFontData