Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/controllers/controllermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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<ControllerEnumerator*> enumerators = m_enumerators;
m_enumerators.clear();
locker.unlock();
Expand All @@ -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;
Expand All @@ -199,14 +200,14 @@ void ControllerManager::updateControllerList() {
}

QList<Controller*> ControllerManager::getControllers() const {
QMutexLocker locker(&m_mutex);
const auto locker = lockMutex(&m_mutex);
return m_controllers;
}

QList<Controller*> ControllerManager::getControllerList(bool bOutputDevices, bool bInputDevices) {
qDebug() << "ControllerManager::getControllerList";

QMutexLocker locker(&m_mutex);
auto locker = lockMutex(&m_mutex);
QList<Controller*> controllers = m_controllers;
locker.unlock();

Expand Down Expand Up @@ -294,7 +295,7 @@ void ControllerManager::slotSetUpDevices() {
}

void ControllerManager::maybeStartOrStopPolling() {
QMutexLocker locker(&m_mutex);
auto locker = lockMutex(&m_mutex);
QList<Controller*> controllers = m_controllers;
locker.unlock();

Expand Down
5 changes: 3 additions & 2 deletions src/engine/cachingreader/cachingreaderworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "util/compatibility.h"
#include "util/event.h"
#include "util/logger.h"
#include "util/qtmutex.h"

namespace {

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
52 changes: 24 additions & 28 deletions src/engine/controls/cuecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -1466,15 +1462,15 @@ 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);
}
}

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()) {
Expand All @@ -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()) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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()) {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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()) {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
7 changes: 2 additions & 5 deletions src/engine/controls/cuecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -348,11 +349,7 @@ class CueControl : public EngineControl {
QMap<QObject*, int> 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;
Expand Down
7 changes: 4 additions & 3 deletions src/engine/engineworkerscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
}

Expand All @@ -43,14 +44,14 @@ void EngineWorkerScheduler::run() {
while (!m_bQuit) {
Event::start(tag);
{
QMutexLocker lock(&m_mutex);
const auto locker = lockMutex(&m_mutex);
Comment thread
uklotzde marked this conversation as resolved.
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
Expand Down
9 changes: 5 additions & 4 deletions src/errordialoghandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "moc_errordialoghandler.cpp"
#include "util/assert.h"
#include "util/qtmutex.h"
#include "util/versionstore.h"

ErrorDialogProperties::ErrorDialogProperties()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand All @@ -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!";
Expand Down
Loading