From 44170cc85cc2ff4298265a58e07ef2d9004a4c3d Mon Sep 17 00:00:00 2001 From: Be Date: Fri, 17 Sep 2021 14:06:27 -0500 Subject: use Qt5/6 QMutex & QMutexLocker compatibility macros --- src/controllers/controllermanager.cpp | 11 ++--- src/engine/cachingreader/cachingreaderworker.cpp | 5 ++- src/engine/controls/cuecontrol.cpp | 52 +++++++++++------------- src/engine/controls/cuecontrol.h | 7 +--- src/engine/engineworkerscheduler.cpp | 7 ++-- src/errordialoghandler.cpp | 9 ++-- src/library/scanner/scannerglobal.h | 9 ++-- src/mixer/playerinfo.cpp | 13 +++--- src/mixer/playermanager.cpp | 45 ++++++++++---------- src/mixer/playermanager.h | 7 +--- src/track/cue.cpp | 41 ++++++++++--------- src/track/keyutils.cpp | 12 +++--- src/track/track.cpp | 4 +- src/util/logging.cpp | 7 ++-- src/util/mutex.h | 5 ++- src/util/sandbox.cpp | 10 ++--- src/util/sandbox.h | 7 +--- src/util/statsmanager.cpp | 5 ++- src/util/tapfilter.cpp | 3 +- src/vinylcontrol/vinylcontrolprocessor.cpp | 16 ++++---- src/vinylcontrol/vinylcontrolprocessor.h | 11 ++--- src/waveform/waveform.h | 24 +++++------ src/widget/wlibrary.cpp | 10 ++--- src/widget/wlibrary.h | 9 ++-- 24 files changed, 158 insertions(+), 171 deletions(-) (limited to 'src') diff --git a/src/controllers/controllermanager.cpp b/src/controllers/controllermanager.cpp index 48472ae69f..606a45132a 100644 --- a/src/controllers/controllermanager.cpp +++ b/src/controllers/controllermanager.cpp @@ -8,6 +8,7 @@ #include "controllers/midi/portmidienumerator.h" #include "moc_controllermanager.cpp" #include "util/cmdlineargs.h" +#include "util/qtmutex.h" #include "util/time.h" #include "util/trace.h" #ifdef __HSS1394__ @@ -162,7 +163,7 @@ void ControllerManager::slotShutdown() { // Clear m_enumerators before deleting the enumerators to prevent other code // paths from accessing them. - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); QList enumerators = m_enumerators; m_enumerators.clear(); locker.unlock(); @@ -177,7 +178,7 @@ void ControllerManager::slotShutdown() { } void ControllerManager::updateControllerList() { - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); if (m_enumerators.isEmpty()) { qWarning() << "updateControllerList called but no enumerators have been added!"; return; @@ -199,14 +200,14 @@ void ControllerManager::updateControllerList() { } QList ControllerManager::getControllers() const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); return m_controllers; } QList ControllerManager::getControllerList(bool bOutputDevices, bool bInputDevices) { qDebug() << "ControllerManager::getControllerList"; - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); QList controllers = m_controllers; locker.unlock(); @@ -294,7 +295,7 @@ void ControllerManager::slotSetUpDevices() { } void ControllerManager::maybeStartOrStopPolling() { - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); QList controllers = m_controllers; locker.unlock(); diff --git a/src/engine/cachingreader/cachingreaderworker.cpp b/src/engine/cachingreader/cachingreaderworker.cpp index 3a9fd507a2..515b8d7e9c 100644 --- a/src/engine/cachingreader/cachingreaderworker.cpp +++ b/src/engine/cachingreader/cachingreaderworker.cpp @@ -11,6 +11,7 @@ #include "util/compatibility.h" #include "util/event.h" #include "util/logger.h" +#include "util/qtmutex.h" namespace { @@ -78,7 +79,7 @@ ReaderStatusUpdate CachingReaderWorker::processReadRequest( // WARNING: Always called from a different thread (GUI) void CachingReaderWorker::newTrack(TrackPointer pTrack) { { - QMutexLocker locker(&m_newTrackMutex); + const auto locker = lockMutex(&m_newTrackMutex); m_pNewTrack = pTrack; m_newTrackAvailable = true; } @@ -96,7 +97,7 @@ void CachingReaderWorker::run() { if (m_newTrackAvailable) { TrackPointer pLoadTrack; { // locking scope - QMutexLocker locker(&m_newTrackMutex); + const auto locker = lockMutex(&m_newTrackMutex); pLoadTrack = m_pNewTrack; m_pNewTrack.reset(); m_newTrackAvailable = false; diff --git a/src/engine/controls/cuecontrol.cpp b/src/engine/controls/cuecontrol.cpp index ffd16e752b..a41068631b 100644 --- a/src/engine/controls/cuecontrol.cpp +++ b/src/engine/controls/cuecontrol.cpp @@ -84,12 +84,8 @@ CueControl::CueControl(const QString& group, m_pStopButton(ControlObject::getControl(ConfigKey(group, "stop"))), m_bypassCueSetByPlay(false), m_iNumHotCues(NUM_HOT_CUES), - m_pCurrentSavedLoopControl(nullptr) -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - , - m_trackMutex(QMutex::Recursive) -#endif -{ + m_pCurrentSavedLoopControl(nullptr), + m_trackMutex(QT_RECURSIVE_MUTEX_INIT) { // To silence a compiler warning about CUE_MODE_PIONEER. Q_UNUSED(CUE_MODE_PIONEER); createControls(); @@ -418,7 +414,7 @@ void CueControl::detachCue(HotcueControl* pControl) { // via seekOnLoad(). There is the theoretical and pending issue of a delayed control // command intended for the old track that might be performed instead. void CueControl::trackLoaded(TrackPointer pNewTrack) { - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); if (m_pLoadedTrack) { disconnect(m_pLoadedTrack.get(), nullptr, this, nullptr); @@ -532,12 +528,12 @@ void CueControl::seekOnLoad(mixxx::audio::FramePos seekOnLoadPosition) { } void CueControl::cueUpdated() { - //QMutexLocker lock(&m_mutex); + //auto lock = lockMutex(&m_mutex); // We should get a trackCuesUpdated call anyway, so do nothing. } void CueControl::loadCuesFromTrack() { - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); if (!m_pLoadedTrack) { return; } @@ -752,7 +748,7 @@ void CueControl::hotcueSet(HotcueControl* pControl, double value, HotcueSetMode return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); if (!m_pLoadedTrack) { return; } @@ -1095,7 +1091,7 @@ void CueControl::hotcueClear(HotcueControl* pControl, double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); if (!m_pLoadedTrack) { return; } @@ -1111,7 +1107,7 @@ void CueControl::hotcueClear(HotcueControl* pControl, double value) { void CueControl::hotcuePositionChanged( HotcueControl* pControl, double value) { - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); if (!m_pLoadedTrack) { return; } @@ -1198,7 +1194,7 @@ void CueControl::cueSet(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const mixxx::audio::FramePos position = getQuantizedCurrentPosition(); TrackPointer pLoadedTrack = m_pLoadedTrack; lock.unlock(); @@ -1229,7 +1225,7 @@ void CueControl::cueGoto(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); // Seek to cue point const auto mainCuePosition = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( @@ -1251,7 +1247,7 @@ void CueControl::cueGotoAndPlay(double value) { } cueGoto(value); - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); // Start playing if not already // End previewing to not jump back if a sticking finger on a cue @@ -1466,7 +1462,7 @@ void CueControl::cueDefault(double v) { } void CueControl::pause(double v) { - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); //qDebug() << "CueControl::pause()" << v; if (v > 0.0) { m_pPlay->set(0.0); @@ -1474,7 +1470,7 @@ void CueControl::pause(double v) { } void CueControl::playStutter(double v) { - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); //qDebug() << "playStutter" << v; if (v > 0.0) { if (m_pPlay->toBool()) { @@ -1496,7 +1492,7 @@ void CueControl::introStartSet(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const mixxx::audio::FramePos position = getQuantizedCurrentPosition(); if (!position.isValid()) { @@ -1555,7 +1551,7 @@ void CueControl::introStartClear(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const auto introEndPosition = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( m_pIntroEndPosition->get()); @@ -1596,7 +1592,7 @@ void CueControl::introEndSet(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const mixxx::audio::FramePos position = getQuantizedCurrentPosition(); if (!position.isValid()) { @@ -1655,7 +1651,7 @@ void CueControl::introEndClear(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const auto introStart = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( m_pIntroStartPosition->get()); @@ -1681,7 +1677,7 @@ void CueControl::introEndActivate(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const auto introEnd = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( m_pIntroEndPosition->get()); @@ -1699,7 +1695,7 @@ void CueControl::outroStartSet(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const mixxx::audio::FramePos position = getQuantizedCurrentPosition(); if (!position.isValid()) { @@ -1758,7 +1754,7 @@ void CueControl::outroStartClear(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const auto outroEnd = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( m_pOutroEndPosition->get()); @@ -1784,7 +1780,7 @@ void CueControl::outroStartActivate(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const auto outroStart = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( m_pOutroStartPosition->get()); @@ -1802,7 +1798,7 @@ void CueControl::outroEndSet(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const mixxx::audio::FramePos position = getQuantizedCurrentPosition(); if (!position.isValid()) { @@ -1861,7 +1857,7 @@ void CueControl::outroEndClear(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const auto outroStart = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( m_pOutroStartPosition->get()); @@ -1887,7 +1883,7 @@ void CueControl::outroEndActivate(double value) { return; } - QMutexLocker lock(&m_trackMutex); + auto lock = lockMutex(&m_trackMutex); const auto outroEnd = mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid( m_pOutroEndPosition->get()); diff --git a/src/engine/controls/cuecontrol.h b/src/engine/controls/cuecontrol.h index bcaf81629e..2d26732f91 100644 --- a/src/engine/controls/cuecontrol.h +++ b/src/engine/controls/cuecontrol.h @@ -12,6 +12,7 @@ #include "track/cue.h" #include "track/track_decl.h" #include "util/parented_ptr.h" +#include "util/qtmutex.h" #define NUM_HOT_CUES 37 @@ -348,11 +349,7 @@ class CueControl : public EngineControl { QMap m_controlMap; // Must be locked when using the m_pLoadedTrack and it's properties -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - QRecursiveMutex m_trackMutex; -#else - QMutex m_trackMutex; -#endif + QT_RECURSIVE_MUTEX m_trackMutex; TrackPointer m_pLoadedTrack; // is written from an engine worker thread friend class HotcueControlTest; diff --git a/src/engine/engineworkerscheduler.cpp b/src/engine/engineworkerscheduler.cpp index 9f3a3ad7f6..120ff794ad 100644 --- a/src/engine/engineworkerscheduler.cpp +++ b/src/engine/engineworkerscheduler.cpp @@ -5,6 +5,7 @@ #include "engine/engineworker.h" #include "moc_engineworkerscheduler.cpp" #include "util/event.h" +#include "util/qtmutex.h" EngineWorkerScheduler::EngineWorkerScheduler(QObject* pParent) : m_bWakeScheduler(false), @@ -24,7 +25,7 @@ void EngineWorkerScheduler::workerReady() { void EngineWorkerScheduler::addWorker(EngineWorker* pWorker) { DEBUG_ASSERT(pWorker); - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); m_workers.push_back(pWorker); } @@ -43,14 +44,14 @@ void EngineWorkerScheduler::run() { while (!m_bQuit) { Event::start(tag); { - QMutexLocker lock(&m_mutex); + const auto locker = lockMutex(&m_mutex); for(const auto& pWorker: m_workers) { pWorker->wakeIfReady(); } } Event::end(tag); { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); if (!m_bQuit) { // Wait for next runWorkers() call m_waitCondition.wait(&m_mutex); // unlock mutex and wait diff --git a/src/errordialoghandler.cpp b/src/errordialoghandler.cpp index abea6f618e..276e898632 100644 --- a/src/errordialoghandler.cpp +++ b/src/errordialoghandler.cpp @@ -8,6 +8,7 @@ #include "moc_errordialoghandler.cpp" #include "util/assert.h" +#include "util/qtmutex.h" #include "util/versionstore.h" ErrorDialogProperties::ErrorDialogProperties() @@ -115,7 +116,7 @@ bool ErrorDialogHandler::requestErrorDialog(ErrorDialogProperties* props) { } // Skip if a dialog with the same key is already displayed - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); bool keyExists = m_dialogKeys.contains(props->getKey()); locker.unlock(); if (keyExists) { @@ -163,7 +164,7 @@ void ErrorDialogHandler::errorDialog(ErrorDialogProperties* pProps) { // This deletes the msgBox automatically, avoiding a memory leak pMsgBox->setAttribute(Qt::WA_DeleteOnClose, true); - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); // To avoid duplicate dialogs on the same error m_dialogKeys.append(props->m_key); @@ -201,7 +202,7 @@ void ErrorDialogHandler::errorDialog(ErrorDialogProperties* pProps) { } void ErrorDialogHandler::boxClosed(const QString& key, QMessageBox* msgBox) { - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); locker.unlock(); QMessageBox::StandardButton whichStdButton = msgBox->standardButton(msgBox->clickedButton()); @@ -215,7 +216,7 @@ void ErrorDialogHandler::boxClosed(const QString& key, QMessageBox* msgBox) { return; } - QMutexLocker locker2(&m_mutex); + const auto locker2 = lockMutex(&m_mutex); if (m_dialogKeys.contains(key)) { if (!m_dialogKeys.removeOne(key)) { qWarning() << "Error dialog key removal from list failed!"; diff --git a/src/library/scanner/scannerglobal.h b/src/library/scanner/scannerglobal.h index ed89f03118..18aaa4ad45 100644 --- a/src/library/scanner/scannerglobal.h +++ b/src/library/scanner/scannerglobal.h @@ -12,6 +12,7 @@ #include "util/cache.h" #include "util/fileaccess.h" #include "util/performancetimer.h" +#include "util/qtmutex.h" #include "util/task.h" class ScannerGlobal { @@ -56,7 +57,7 @@ class ScannerGlobal { bool testAndMarkDirectoryScanned(const QDir& dir) { const QString canonicalPath(dir.canonicalPath()); - QMutexLocker locker(&m_directoriesScannedMutex); + const auto locker = lockMutex(&m_directoriesScannedMutex); if (m_directoriesScanned.contains(canonicalPath)) { return true; } else { @@ -66,7 +67,7 @@ class ScannerGlobal { } void addUnhashedDir(const mixxx::FileAccess& dirAccess) { - QMutexLocker locker(&m_directoriesUnhashedMutex); + const auto locker = lockMutex(&m_directoriesUnhashedMutex); m_directoriesUnhashed.append(dirAccess); } @@ -78,7 +79,7 @@ class ScannerGlobal { // TODO(rryan) test whether tasks should create their own QRegExp. bool isAudioFileSupported(const QString& fileName) const { - QMutexLocker locker(&m_supportedExtensionsMatcherMutex); + const auto locker = lockMutex(&m_supportedExtensionsMatcherMutex); return m_supportedExtensionsMatcher.indexIn(fileName) != -1; } @@ -88,7 +89,7 @@ class ScannerGlobal { // TODO(rryan) test whether tasks should create their own QRegExp. bool isCoverFileSupported(const QString& fileName) const { - QMutexLocker locker(&m_supportedCoverExtensionsMatcherMutex); + const auto locker = lockMutex(&m_supportedCoverExtensionsMatcherMutex); return m_supportedCoverExtensionsMatcher.indexIn(fileName) != -1; } diff --git a/src/mixer/playerinfo.cpp b/src/mixer/playerinfo.cpp index 8d0aa4a31a..3b8085e2dd 100644 --- a/src/mixer/playerinfo.cpp +++ b/src/mixer/playerinfo.cpp @@ -9,6 +9,7 @@ #include "mixer/playermanager.h" #include "moc_playerinfo.cpp" #include "track/track.h" +#include "util/qtmutex.h" namespace { @@ -52,14 +53,14 @@ void PlayerInfo::destroy() { } TrackPointer PlayerInfo::getTrackInfo(const QString& group) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); return m_loadedTrackMap.value(group); } void PlayerInfo::setTrackInfo(const QString& group, const TrackPointer& pTrack) { TrackPointer pOld; { // Scope - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); pOld = m_loadedTrackMap.value(group); m_loadedTrackMap.insert(group, pTrack); } @@ -77,7 +78,7 @@ void PlayerInfo::setTrackInfo(const QString& group, const TrackPointer& pTrack) } bool PlayerInfo::isTrackLoaded(const TrackPointer& pTrack) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); QMapIterator it(m_loadedTrackMap); while (it.hasNext()) { it.next(); @@ -89,13 +90,13 @@ bool PlayerInfo::isTrackLoaded(const TrackPointer& pTrack) const { } QMap PlayerInfo::getLoadedTracks() { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); QMap ret = m_loadedTrackMap; return ret; } bool PlayerInfo::isFileLoaded(const QString& track_location) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); QMapIterator it(m_loadedTrackMap); while (it.hasNext()) { it.next(); @@ -115,7 +116,7 @@ void PlayerInfo::timerEvent(QTimerEvent* pTimerEvent) { } void PlayerInfo::updateCurrentPlayingDeck() { - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); double maxVolume = 0; int maxDeck = -1; diff --git a/src/mixer/playermanager.cpp b/src/mixer/playermanager.cpp index cce731dbaa..a3340cd210 100644 --- a/src/mixer/playermanager.cpp +++ b/src/mixer/playermanager.cpp @@ -43,10 +43,7 @@ PlayerManager::PlayerManager(UserSettingsPointer pConfig, SoundManager* pSoundManager, EffectsManager* pEffectsManager, EngineMaster* pEngine) - : -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - m_mutex(QMutex::Recursive), -#endif + : m_mutex(QT_RECURSIVE_MUTEX_INIT), m_pConfig(pConfig), m_pSoundManager(pSoundManager), m_pEffectsManager(pEffectsManager), @@ -84,7 +81,7 @@ PlayerManager::PlayerManager(UserSettingsPointer pConfig, PlayerManager::~PlayerManager() { kLogger.debug() << "Destroying"; - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); m_pSamplerBank->saveSamplerBankToPath( m_pConfig->getSettingsPath() + "/samplers.xml"); @@ -113,7 +110,7 @@ PlayerManager::~PlayerManager() { } void PlayerManager::bindToLibrary(Library* pLibrary) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); connect(pLibrary, &Library::loadTrackToPlayer, this, &PlayerManager::slotLoadTrackToPlayer); connect(pLibrary, &Library::loadTrack, @@ -279,7 +276,7 @@ unsigned int PlayerManager::numPreviewDecks() { } void PlayerManager::slotChangeNumDecks(double v) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); int num = (int)v; VERIFY_OR_DEBUG_ASSERT(num <= kMaxNumberOfDecks) { @@ -309,7 +306,7 @@ void PlayerManager::slotChangeNumDecks(double v) { } void PlayerManager::slotChangeNumSamplers(double v) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); int num = (int)v; if (num < m_samplers.size()) { // The request was invalid -- don't set the value. @@ -324,7 +321,7 @@ void PlayerManager::slotChangeNumSamplers(double v) { } void PlayerManager::slotChangeNumPreviewDecks(double v) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); int num = (int)v; if (num < m_previewDecks.size()) { // The request was invalid -- don't set the value. @@ -338,7 +335,7 @@ void PlayerManager::slotChangeNumPreviewDecks(double v) { } void PlayerManager::slotChangeNumMicrophones(double v) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); int num = (int)v; if (num < m_microphones.size()) { // The request was invalid -- don't set the value. @@ -352,7 +349,7 @@ void PlayerManager::slotChangeNumMicrophones(double v) { } void PlayerManager::slotChangeNumAuxiliaries(double v) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); int num = (int)v; if (num < m_auxiliaries.size()) { // The request was invalid -- don't set the value. @@ -366,7 +363,7 @@ void PlayerManager::slotChangeNumAuxiliaries(double v) { } void PlayerManager::addDeck() { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); double count = m_pCONumDecks->get() + 1; slotChangeNumDecks(count); } @@ -446,7 +443,7 @@ void PlayerManager::loadSamplers() { } void PlayerManager::addSampler() { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); double count = m_pCONumSamplers->get() + 1; slotChangeNumSamplers(count); } @@ -480,7 +477,7 @@ void PlayerManager::addSamplerInner() { } void PlayerManager::addPreviewDeck() { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); slotChangeNumPreviewDecks(m_pCONumPreviewDecks->get() + 1); } @@ -513,7 +510,7 @@ void PlayerManager::addPreviewDeckInner() { } void PlayerManager::addMicrophone() { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); slotChangeNumMicrophones(m_pCONumMicrophones->get() + 1); } @@ -535,7 +532,7 @@ void PlayerManager::addMicrophoneInner() { } void PlayerManager::addAuxiliary() { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); slotChangeNumAuxiliaries(m_pCONumAuxiliaries->get() + 1); } @@ -558,7 +555,7 @@ BaseTrackPlayer* PlayerManager::getPlayer(const QString& group) const { } BaseTrackPlayer* PlayerManager::getPlayer(const ChannelHandle& handle) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); if (m_players.contains(handle)) { return m_players[handle]; @@ -567,7 +564,7 @@ BaseTrackPlayer* PlayerManager::getPlayer(const ChannelHandle& handle) const { } Deck* PlayerManager::getDeck(unsigned int deck) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); VERIFY_OR_DEBUG_ASSERT(deck > 0 && deck <= numDecks()) { qWarning() << "getDeck() called with invalid number:" << deck; return nullptr; @@ -576,7 +573,7 @@ Deck* PlayerManager::getDeck(unsigned int deck) const { } PreviewDeck* PlayerManager::getPreviewDeck(unsigned int libPreviewPlayer) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); if (libPreviewPlayer < 1 || libPreviewPlayer > numPreviewDecks()) { kLogger.warning() << "Warning getPreviewDeck() called with invalid index: " << libPreviewPlayer; @@ -586,7 +583,7 @@ PreviewDeck* PlayerManager::getPreviewDeck(unsigned int libPreviewPlayer) const } Sampler* PlayerManager::getSampler(unsigned int sampler) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); if (sampler < 1 || sampler > numSamplers()) { kLogger.warning() << "Warning getSampler() called with invalid index: " << sampler; @@ -596,7 +593,7 @@ Sampler* PlayerManager::getSampler(unsigned int sampler) const { } Microphone* PlayerManager::getMicrophone(unsigned int microphone) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); if (microphone < 1 || microphone >= static_cast(m_microphones.size())) { kLogger.warning() << "Warning getMicrophone() called with invalid index: " << microphone; @@ -606,7 +603,7 @@ Microphone* PlayerManager::getMicrophone(unsigned int microphone) const { } Auxiliary* PlayerManager::getAuxiliary(unsigned int auxiliary) const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); if (auxiliary < 1 || auxiliary > static_cast(m_auxiliaries.size())) { kLogger.warning() << "Warning getAuxiliary() called with invalid index: " << auxiliary; @@ -685,7 +682,7 @@ void PlayerManager::slotLoadToSampler(const QString& location, int sampler) { } void PlayerManager::slotLoadTrackIntoNextAvailableDeck(TrackPointer pTrack) { - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); QList::iterator it = m_decks.begin(); while (it != m_decks.end()) { Deck* pDeck = *it; @@ -704,7 +701,7 @@ void PlayerManager::slotLoadTrackIntoNextAvailableDeck(TrackPointer pTrack) { } void PlayerManager::slotLoadTrackIntoNextAvailableSampler(TrackPointer pTrack) { - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); QList::iterator it = m_samplers.begin(); while (it != m_samplers.end()) { Sampler* pSampler = *it; diff --git a/src/mixer/playermanager.h b/src/mixer/playermanager.h index 661579e0ca..f1bba67615 100644 --- a/src/mixer/playermanager.h +++ b/src/mixer/playermanager.h @@ -11,6 +11,7 @@ #include "track/track_decl.h" #include "util/parented_ptr.h" #include "util/performancetimer.h" +#include "util/qtmutex.h" class Auxiliary; class BaseTrackPlayer; @@ -251,11 +252,7 @@ class PlayerManager : public QObject, public PlayerManagerInterface { void addAuxiliaryInner(); // Used to protect access to PlayerManager state across threads. -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - mutable QRecursiveMutex m_mutex; -#else - mutable QMutex m_mutex; -#endif + mutable QT_RECURSIVE_MUTEX m_mutex; PerformanceTimer m_cloneTimer; QString m_lastLoadedPlayer; diff --git a/src/track/cue.cpp b/src/track/cue.cpp index 74c7e52148..9b50216ec3 100644 --- a/src/track/cue.cpp +++ b/src/track/cue.cpp @@ -9,6 +9,7 @@ #include "util/assert.h" #include "util/color/color.h" #include "util/color/predefinedcolorpalettes.h" +#include "util/qtmutex.h" namespace { @@ -111,7 +112,7 @@ Cue::Cue( mixxx::CueInfo Cue::getCueInfo( mixxx::audio::SampleRate sampleRate) const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return mixxx::CueInfo( m_type, positionFramesToMillis(m_startPosition, sampleRate), @@ -122,12 +123,12 @@ mixxx::CueInfo Cue::getCueInfo( } DbId Cue::getId() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_dbId; } void Cue::setId(DbId cueId) { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); m_dbId = cueId; // Neither mark as dirty nor do emit the updated() signal. // This function is only called after adding the Cue object @@ -138,12 +139,12 @@ void Cue::setId(DbId cueId) { } mixxx::CueType Cue::getType() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_type; } void Cue::setType(mixxx::CueType type) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); if (m_type == type) { return; } @@ -154,12 +155,12 @@ void Cue::setType(mixxx::CueType type) { } mixxx::audio::FramePos Cue::getPosition() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_startPosition; } void Cue::setStartPosition(mixxx::audio::FramePos position) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); if (m_startPosition == position) { return; } @@ -170,7 +171,7 @@ void Cue::setStartPosition(mixxx::audio::FramePos position) { } void Cue::setEndPosition(mixxx::audio::FramePos position) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); if (m_endPosition == position) { return; } @@ -183,7 +184,7 @@ void Cue::setEndPosition(mixxx::audio::FramePos position) { void Cue::setStartAndEndPosition( mixxx::audio::FramePos startPosition, mixxx::audio::FramePos endPosition) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); if (m_startPosition == startPosition && m_endPosition == endPosition) { return; @@ -196,12 +197,12 @@ void Cue::setStartAndEndPosition( } Cue::StartAndEndPositions Cue::getStartAndEndPosition() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return {m_startPosition, m_endPosition}; } void Cue::shiftPositionFrames(mixxx::audio::FrameDiff_t frameOffset) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); if (m_startPosition.isValid()) { m_startPosition += frameOffset; } @@ -214,7 +215,7 @@ void Cue::shiftPositionFrames(mixxx::audio::FrameDiff_t frameOffset) { } mixxx::audio::FrameDiff_t Cue::getLengthFrames() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); if (!m_endPosition.isValid()) { return 0; } @@ -225,17 +226,17 @@ mixxx::audio::FrameDiff_t Cue::getLengthFrames() const { } int Cue::getHotCue() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_iHotCue; } QString Cue::getLabel() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_label; } void Cue::setLabel(const QString& label) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); if (m_label == label) { return; } @@ -246,12 +247,12 @@ void Cue::setLabel(const QString& label) { } mixxx::RgbColor Cue::getColor() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_color; } void Cue::setColor(mixxx::RgbColor color) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); if (m_color == color) { return; } @@ -262,16 +263,16 @@ void Cue::setColor(mixxx::RgbColor color) { } bool Cue::isDirty() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_bDirty; } void Cue::setDirty(bool dirty) { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); m_bDirty = dirty; } mixxx::audio::FramePos Cue::getEndPosition() const { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); return m_endPosition; } diff --git a/src/track/keyutils.cpp b/src/track/keyutils.cpp index 595ed75c18..6189d3bb12 100644 --- a/src/track/keyutils.cpp +++ b/src/track/keyutils.cpp @@ -1,11 +1,13 @@ -#include +#include "track/keyutils.h" + #include #include #include #include +#include -#include "track/keyutils.h" #include "util/math.h" +#include "util/qtmutex.h" #define MUSIC_FLAT_UTF8 "\xe299ad" #define MUSIC_SHARP_UTF8 "\xe299af" @@ -182,7 +184,7 @@ QString KeyUtils::keyDebugName(ChromaticKey key) { // static void KeyUtils::setNotation(const QMap& notation) { - QMutexLocker locker(&s_notationMutex); + const auto locker = lockMutex(&s_notationMutex); s_notation = notation; s_reverseNotation.clear(); @@ -206,7 +208,7 @@ QString KeyUtils::keyToString(ChromaticKey key, if (notation == KeyNotation::Custom) { // The default value for notation is KeyUtils::KeyNotation::Custom, so this executes when the function is // called without a notation specified after KeyUtils::setNotation has set up s_notation. - QMutexLocker locker(&s_notationMutex); + const auto locker = lockMutex(&s_notationMutex); auto it = s_notation.constFind(key); if (it != s_notation.constEnd()) { return it.value(); @@ -255,7 +257,7 @@ ChromaticKey KeyUtils::guessKeyFromText(const QString& text) { // Try using the user's custom notation. { - QMutexLocker locker(&s_notationMutex); + const auto locker = lockMutex(&s_notationMutex); auto it = s_reverseNotation.constFind(text); if (it != s_reverseNotation.constEnd()) { return it.value(); diff --git a/src/track/track.cpp b/src/track/track.cpp index d99c36f35a..44ce41fc1c 100644 --- a/src/track/track.cpp +++ b/src/track/track.cpp @@ -327,11 +327,11 @@ void Track::setReplayGain(const mixxx::ReplayGain& replayGain) { } void Track::adjustReplayGainFromPregain(double gain) { - QMutexLocker lock(&m_qMutex); + auto locked = lockMutex(&m_qMutex); mixxx::ReplayGain replayGain = m_record.getMetadata().getTrackInfo().getReplayGain(); replayGain.setRatio(gain * replayGain.getRatio()); if (compareAndSet(m_record.refMetadata().refTrackInfo().ptrReplayGain(), replayGain)) { - markDirtyAndUnlock(&lock); + markDirtyAndUnlock(&locked); emit replayGainAdjusted(replayGain); } } diff --git a/src/util/logging.cpp b/src/util/logging.cpp index 051b110e62..fe64be0fb5 100644 --- a/src/util/logging.cpp +++ b/src/util/logging.cpp @@ -17,6 +17,7 @@ #include "controllers/controllerdebug.h" #include "util/assert.h" #include "util/cmdlineargs.h" +#include "util/qtmutex.h" namespace { @@ -124,7 +125,7 @@ inline void writeToFile( QChar('\n'); QByteArray formattedMessage = formattedMessageStr.toLocal8Bit(); - QMutexLocker locked(&s_mutexLogfile); + const auto locked = lockMutex(&s_mutexLogfile); // Writing to a closed QFile could cause an infinite recursive loop // by logging to qWarning! if (s_logfile.isOpen()) { @@ -151,7 +152,7 @@ inline void writeToStdErr( formattedMessageStr.replace(kThreadNamePattern, threadName) .toLocal8Bit(); - QMutexLocker locked(&s_mutexStdErr); + const auto locked = lockMutex(&s_mutexStdErr); const std::size_t written = fwrite( formattedMessage.constData(), sizeof(char), formattedMessage.size(), stderr); Q_UNUSED(written); @@ -393,7 +394,7 @@ void Logging::shutdown() { // Even though we uninstalled the message handler, other threads may have // already entered it. - QMutexLocker locker(&s_mutexLogfile); + const auto locker = lockMutex(&s_mutexLogfile); if (s_logfile.isOpen()) { s_logfile.close(); } diff --git a/src/util/mutex.h b/src/util/mutex.h index 37cd1f1a4d..c7eef850b9 100644 --- a/src/util/mutex.h +++ b/src/util/mutex.h @@ -5,9 +5,10 @@ // See: http://clang.llvm.org/docs/ThreadSafetyAnalysis.html #include -#include #include +#include +#include "util/qtmutex.h" #include "util/thread_annotations.h" class CAPABILITY("mutex") MMutex { @@ -57,7 +58,7 @@ class SCOPED_CAPABILITY MMutexLocker { inline void unlock() RELEASE() { m_locker.unlock(); } private: - QMutexLocker m_locker; + QT_MUTEX_LOCKER m_locker; }; class SCOPED_CAPABILITY MWriteLocker { diff --git a/src/util/sandbox.cpp b/src/util/sandbox.cpp index 245d7a3ad9..abb04e9d68 100644 --- a/src/util/sandbox.cpp +++ b/src/util/sandbox.cpp @@ -47,14 +47,14 @@ void Sandbox::checkSandboxed() { } void Sandbox::setPermissionsFilePath(const QString& permissionsFile) { - QMutexLocker locker(&s_mutex); + const auto locker = lockMutex(&s_mutex); s_pSandboxPermissions = QSharedPointer>( new ConfigObject(permissionsFile)); } // static void Sandbox::shutdown() { - QMutexLocker locker(&s_mutex); + const auto locker = lockMutex(&s_mutex); QSharedPointer> pSandboxPermissions = s_pSandboxPermissions; s_pSandboxPermissions.clear(); if (pSandboxPermissions) { @@ -173,7 +173,7 @@ bool Sandbox::createSecurityToken(const QString& canonicalPath, if (!enabled()) { return false; } - QMutexLocker locker(&s_mutex); + const auto locker = lockMutex(&s_mutex); if (s_pSandboxPermissions == nullptr) { return false; } @@ -238,7 +238,7 @@ SecurityTokenPointer Sandbox::openSecurityToken(mixxx::FileInfo* pFileInfo, bool return nullptr; } - QMutexLocker locker(&s_mutex); + const auto locker = lockMutex(&s_mutex); if (!s_pSandboxPermissions) { return nullptr; } @@ -303,7 +303,7 @@ SecurityTokenPointer Sandbox::openSecurityTokenForDir(const QDir& dir, bool crea return nullptr; } - QMutexLocker locker(&s_mutex); + const auto locker = lockMutex(&s_mutex); if (!s_pSandboxPermissions) { return nullptr; } diff --git a/src/util/sandbox.h b/src/util/sandbox.h index c06389e369..8187fc296f 100644 --- a/src/util/sandbox.h +++ b/src/util/sandbox.h @@ -9,6 +9,7 @@ #include "preferences/configobject.h" #include "util/fileinfo.h" +#include "util/qtmutex.h" #ifdef Q_OS_MAC #include @@ -68,11 +69,7 @@ class Sandbox { // Creates a security token. s_mutex is not needed for this method. static bool createSecurityToken(const QString& canonicalPath, bool isDirectory); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - static QRecursiveMutex s_mutex; -#else - static QMutex s_mutex; -#endif + static QT_RECURSIVE_MUTEX s_mutex; static bool s_bInSandbox; static QSharedPointer> s_pSandboxPermissions; static QHash s_activeTokens; diff --git a/src/util/statsmanager.cpp b/src/util/statsmanager.cpp index b771a2ed8c..fb349d314f 100644 --- a/src/util/statsmanager.cpp +++ b/src/util/statsmanager.cpp @@ -9,6 +9,7 @@ #include "moc_statsmanager.cpp" #include "util/cmdlineargs.h" #include "util/compatibility.h" +#include "util/qtmutex.h" // In practice we process stats pipes about once a minute @1ms latency. const int kStatsPipeSize = 1 << 10; @@ -164,7 +165,7 @@ void StatsManager::writeTimeline(const QString& filename) { } void StatsManager::onStatsPipeDestroyed(StatsPipe* pPipe) { - QMutexLocker locker(&m_statsPipeLock); + const auto locker = lockMutex(&m_statsPipeLock); processIncomingStatReports(); m_statsPipes.removeAll(pPipe); } @@ -175,7 +176,7 @@ StatsPipe* StatsManager::getStatsPipeForThread() { } StatsPipe* pResult = new StatsPipe(this); m_threadStatsPipes.setLocalData(pResult); - QMutexLocker locker(&m_statsPipeLock); + const auto locker = lockMutex(&m_statsPipeLock); m_statsPipes.push_back(pResult); return pResult; } diff --git a/src/util/tapfilter.cpp b/src/util/tapfilter.cpp index e5235d239f..4b3234d848 100644 --- a/src/util/tapfilter.cpp +++ b/src/util/tapfilter.cpp @@ -1,6 +1,7 @@ #include "util/tapfilter.h" #include "moc_tapfilter.cpp" +#include "util/qtmutex.h" TapFilter::TapFilter(QObject* pParent, int filterLength, mixxx::Duration maxInterval) : QObject(pParent), @@ -13,7 +14,7 @@ TapFilter::~TapFilter() { } void TapFilter::tap() { - QMutexLocker locker(&m_mutex); + auto locker = lockMutex(&m_mutex); mixxx::Duration elapsed = m_timer.restart(); if (elapsed <= m_maxInterval) { double averageLength = m_mean.insert(elapsed.toDoubleMillis()); diff --git a/src/vinylcontrol/vinylcontrolprocessor.cpp b/src/vinylcontrol/vinylcontrolprocessor.cpp index 742507142c..a44309ca4a 100644 --- a/src/vinylcontrol/vinylcontrolprocessor.cpp +++ b/src/vinylcontrol/vinylcontrolprocessor.cpp @@ -20,9 +20,7 @@ VinylControlProcessor::VinylControlProcessor(QObject* pParent, UserSettingsPoint m_pConfig(pConfig), m_pToggle(new ControlPushButton(ConfigKey(VINYL_PREF_KEY, "Toggle"))), m_pWorkBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)), -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - m_processorsLock(QMutex::Recursive), -#endif + m_processorsLock(QT_RECURSIVE_MUTEX_INIT), m_processors(kMaximumVinylControlInputs, NULL), m_signalQualityFifo(SIGNAL_QUALITY_FIFO_SIZE), m_bReportSignalQuality(false), @@ -50,7 +48,7 @@ VinylControlProcessor::~VinylControlProcessor() { SampleUtil::free(m_pWorkBuffer); { - QMutexLocker locker(&m_processorsLock); + const auto locker = lockMutex(&m_processorsLock); for (int i = 0; i < kMaximumVinylControlInputs; ++i) { VinylControl* pProcessor = m_processors.at(i); m_processors[i] = NULL; @@ -91,7 +89,7 @@ void VinylControlProcessor::run() { } for (int i = 0; i < kMaximumVinylControlInputs; ++i) { - QMutexLocker locker(&m_processorsLock); + auto locker = lockMutex(&m_processorsLock); VinylControl* pProcessor = m_processors[i]; locker.unlock(); FIFO* pSamplePipe = m_samplePipes[i]; @@ -140,7 +138,7 @@ void VinylControlProcessor::run() { void VinylControlProcessor::reloadConfig() { for (int i = 0; i < kMaximumVinylControlInputs; ++i) { - QMutexLocker locker(&m_processorsLock); + auto locker = lockMutex(&m_processorsLock); VinylControl* pCurrent = m_processors[i]; if (pCurrent == nullptr) { @@ -172,7 +170,7 @@ void VinylControlProcessor::onInputConfigured(const AudioInput& input) { VinylControl *pNew = new VinylControlXwax( m_pConfig, kVCGroup.arg(index + 1)); - QMutexLocker locker(&m_processorsLock); + auto locker = lockMutex(&m_processorsLock); VinylControl* pCurrent = m_processors.at(index); m_processors.replace(index, pNew); locker.unlock(); @@ -194,7 +192,7 @@ void VinylControlProcessor::onInputUnconfigured(const AudioInput& input) { return; } - QMutexLocker locker(&m_processorsLock); + auto locker = lockMutex(&m_processorsLock); VinylControl* pVC = m_processors.at(index); m_processors.replace(index, NULL); locker.unlock(); @@ -261,7 +259,7 @@ void VinylControlProcessor::toggleDeck(double value) { // -1 means we haven't found a proxy that's enabled int enabled = -1; - QMutexLocker locker(&m_processorsLock); + QT_RECURSIVE_MUTEX_LOCKER locker(&m_processorsLock); for (int i = 0; i < m_processors.size(); ++i) { VinylControl* pProcessor = m_processors.at(i); diff --git a/src/vinylcontrol/vinylcontrolprocessor.h b/src/vinylcontrol/vinylcontrolprocessor.h index 91673109f3..6184a08944 100644 --- a/src/vinylcontrol/vinylcontrolprocessor.h +++ b/src/vinylcontrol/vinylcontrolprocessor.h @@ -1,15 +1,16 @@ #pragma once +#include #include #include #include -#include #include #include "preferences/usersettings.h" +#include "soundio/soundmanagerutil.h" #include "util/fifo.h" +#include "util/qtmutex.h" #include "vinylcontrol/vinylsignalquality.h" -#include "soundio/soundmanagerutil.h" class VinylControl; class ControlPushButton; @@ -72,11 +73,7 @@ class VinylControlProcessor : public QThread, public AudioDestination { CSAMPLE* m_pWorkBuffer; QWaitCondition m_samplesAvailableSignal; QMutex m_waitForSampleMutex; -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - QRecursiveMutex m_processorsLock; -#else - QMutex m_processorsLock; -#endif + QT_RECURSIVE_MUTEX m_processorsLock; QVector m_processors; FIFO m_signalQualityFifo; volatile bool m_bReportSignalQuality; diff --git a/src/waveform/waveform.h b/src/waveform/waveform.h index e9df058148..f6019e57b5 100644 --- a/src/waveform/waveform.h +++ b/src/waveform/waveform.h @@ -1,16 +1,16 @@ #pragma once -#include - -#include -#include -#include #include -#include +#include +#include #include +#include +#include +#include #include "util/class.h" #include "util/compatibility.h" +#include "util/qtmutex.h" enum FilterIndex { Low = 0, Mid = 1, High = 2, FilterCount = 3}; enum ChannelIndex { Left = 0, Right = 1, ChannelCount = 2}; @@ -43,32 +43,32 @@ class Waveform { virtual ~Waveform(); int getId() const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); return m_id; } void setId(int id) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); m_id = id; } QString getVersion() const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); return m_version; } void setVersion(const QString& version) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); m_version = version; } QString getDescription() const { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); return m_description; } void setDescription(const QString& description) { - QMutexLocker locker(&m_mutex); + const auto locker = lockMutex(&m_mutex); m_description = description; } diff --git a/src/widget/wlibrary.cpp b/src/widget/wlibrary.cpp index 9c95ec7e8e..89b92ddb6a 100644 --- a/src/widget/wlibrary.cpp +++ b/src/widget/wlibrary.cpp @@ -12,9 +12,7 @@ WLibrary::WLibrary(QWidget* parent) : QStackedWidget(parent), WBaseWidget(this), -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - m_mutex(QMutex::Recursive), -#endif + m_mutex(QT_RECURSIVE_MUTEX_INIT), m_trackTableBackgroundColorOpacity(kDefaultTrackTableBackgroundColorOpacity), m_bShowButtonText(true) { } @@ -35,7 +33,7 @@ void WLibrary::setup(const QDomNode& node, const SkinContext& context) { } bool WLibrary::registerView(const QString& name, QWidget* view) { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); if (m_viewMap.contains(name)) { return false; } @@ -51,7 +49,7 @@ bool WLibrary::registerView(const QString& name, QWidget* view) { } void WLibrary::switchToView(const QString& name) { - QMutexLocker lock(&m_mutex); + const auto lock = lockMutex(&m_mutex); //qDebug() << "WLibrary::switchToView" << name; WTrackTableView* ttView = qobject_cast( @@ -88,7 +86,7 @@ void WLibrary::switchToView(const QString& name) { } void WLibrary::search(const QString& name) { - QMutexLocker lock(&m_mutex); + auto lock = lockMutex(&m_mutex); QWidget* current = currentWidget(); LibraryView* view = dynamic_cast(current); if (view == nullptr) { diff --git a/src/widget/wlibrary.h b/src/widget/wlibrary.h index 9875a0e066..33602b942f 100644 --- a/src/widget/wlibrary.h +++ b/src/widget/wlibrary.h @@ -1,13 +1,14 @@ #pragma once +#include #include #include #include #include -#include #include "library/libraryview.h" #include "skin/legacy/skincontext.h" +#include "util/qtmutex.h" #include "widget/wbasewidget.h" class KeyboardEventFilter; @@ -54,11 +55,7 @@ class WLibrary : public QStackedWidget, public WBaseWidget { bool event(QEvent* pEvent) override; private: -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - QRecursiveMutex m_mutex; -#else - QMutex m_mutex; -#endif + QT_RECURSIVE_MUTEX m_mutex; QMap m_viewMap; double m_trackTableBackgroundColorOpacity; bool m_bShowButtonText; -- cgit v1.2.3