summaryrefslogtreecommitdiffstats
path: root/src/control
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2020-07-06 09:25:04 +0200
committerUwe Klotz <uklotz@mixxx.org>2020-07-06 10:45:13 +0200
commitf1b1cdc655fc693c8b643ef0948d7991c43faccd (patch)
tree2447f7d72efc8ddb82f220de47443a314a4b4f3a /src/control
parent3b05a477824ec58864ab656d1d56d17ec78021d0 (diff)
Split get/take of existing/leaked controls into separate functions
Diffstat (limited to 'src/control')
-rw-r--r--src/control/control.cpp32
-rw-r--r--src/control/control.h10
2 files changed, 27 insertions, 15 deletions
diff --git a/src/control/control.cpp b/src/control/control.cpp
index 0e3a2aceed..99f72ce37f 100644
--- a/src/control/control.cpp
+++ b/src/control/control.cpp
@@ -153,21 +153,35 @@ QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl(
}
// static
-void ControlDoublePrivate::getControls(
- QList<QSharedPointer<ControlDoublePrivate>>* pControlList,
- bool detachLeakedControls) {
- pControlList->clear();
+QList<QSharedPointer<ControlDoublePrivate>> ControlDoublePrivate::getAllInstances() {
+ QList<QSharedPointer<ControlDoublePrivate>> result;
MMutexLocker locker(&s_qCOHashMutex);
- pControlList->reserve(s_qCOHash.size());
- for (auto it = s_qCOHash.constBegin(); it != s_qCOHash.constEnd(); ++it) {
+ result.reserve(s_qCOHash.size());
+ for (auto it = s_qCOHash.begin(); it != s_qCOHash.end(); ++it) {
auto pControl = it.value().lock();
if (pControl) {
- pControlList->push_back(pControl);
+ result.append(std::move(pControl));
+ } else {
+ // The weak pointer has become invalid and can be cleaned up
+ s_qCOHash.erase(it);
}
}
- if (detachLeakedControls) {
- s_qCOHash.clear();
+ return result;
+}
+
+// static
+QList<QSharedPointer<ControlDoublePrivate>> ControlDoublePrivate::takeAllInstances() {
+ QList<QSharedPointer<ControlDoublePrivate>> result;
+ MMutexLocker locker(&s_qCOHashMutex);
+ result.reserve(s_qCOHash.size());
+ for (auto it = s_qCOHash.begin(); it != s_qCOHash.end(); ++it) {
+ auto pControl = it.value().lock();
+ if (pControl) {
+ result.append(std::move(pControl));
+ }
}
+ s_qCOHash.clear();
+ return result;
}
void ControlDoublePrivate::deleteCreatorCO() {
diff --git a/src/control/control.h b/src/control/control.h
index 96b9ddada3..5ff49bcd4b 100644
--- a/src/control/control.h
+++ b/src/control/control.h
@@ -52,12 +52,10 @@ class ControlDoublePrivate : public QObject {
bool bPersist = false,
double defaultValue = 0.0);
- // Adds all ControlDoublePrivate that currently exist to pControlList
- static void getControls(
- QList<QSharedPointer<ControlDoublePrivate> >* pControlsList,
- bool detachLeakedControls = false);
-
- static QHash<ConfigKey, ConfigKey> getControlAliases();
+ // Returns a list of all existing instances.
+ static QList<QSharedPointer<ControlDoublePrivate>> getAllInstances();
+ // Clears all existing instances and returns them as a list.
+ static QList<QSharedPointer<ControlDoublePrivate>> takeAllInstances();
static QHash<ConfigKey, ConfigKey> getControlAliases() {
// Implicitly shared classes can safely be copied across threads