d1vanov/libquentier

Use QAtomicInt::loadAcquire and QAtomicInt::storeRelease instead of load and store for Qt >= 5.14

Closed this issue · 1 comments

Currently the following warning is generated:

/home/dmitry/workspace/MyOpenSourceProjects/libquentier-master/src/note_editor/SpellCheckerDictionariesFinder.cpp: In member function ‘virtual void quentier::SpellCheckerDictionariesFinder::run()’:
/home/dmitry/workspace/MyOpenSourceProjects/libquentier-master/src/note_editor/SpellCheckerDictionariesFinder.cpp:55:53: warning: ‘T QBasicAtomicInteger<T>::load() const [with T = int]’ is deprecated: Use loadRelaxed [-Wdeprecated-declarations]
     if (!m_pStopFlag.isNull() && (m_pStopFlag->load() != 0)) {                 \
                                                     ^
/home/dmitry/workspace/MyOpenSourceProjects/libquentier-master/src/note_editor/SpellCheckerDictionariesFinder.cpp:73:9: note: in expansion of macro ‘CHECK_AND_STOP’
         CHECK_AND_STOP()
         ^~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qatomic.h:46:0,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1302,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QtGlobal:1,
                 from /home/dmitry/workspace/MyOpenSourceProjects/libquentier-master/headers/quentier/utility/Macros.h:22,
                 from /home/dmitry/workspace/MyOpenSourceProjects/libquentier-master/src/note_editor/SpellCheckerDictionariesFinder.h:22,
                 from /home/dmitry/workspace/MyOpenSourceProjects/libquentier-master/src/note_editor/SpellCheckerDictionariesFinder.cpp:19:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qbasicatomic.h:103:55: note: declared here
     QT_DEPRECATED_VERSION_X_5_14("Use loadRelaxed") T load() const noexcept { return loadRelaxed(); }
                                                       ^~~~

Need to add ifdefs like this:

#ifdef QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (!m_pStopFlag.isNull() && (m_pStopFlag->loadAcquire() != 0)) {
#else
if (!m_pStopFlag.isNull() && (m_pStopFlag->load() != 0)) {
#endif

or similarly, maybe have less code within ifdef branches. Similar thing with store and storeRelease although I don't remember exactly where it is used within the codebase, probably somewhere nearby.

Turned out, things are even simpler: loadAcquire has been available long before Qt 5.14 so I just replaced load with loadAcquired. And it turned out I haven't implemented the proper cancellation of SpellCheckerDictionariesFinder, so there's no store call anywhere in the codebase yet. Will do it later.