Docker: Replace mutex+value with SynchronizedValue

Change-Id: Id7ca66be635abbb479602e040889c7ccfa889179
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2025-02-19 07:54:03 +01:00
parent 691e08c63e
commit 881f15da6b
2 changed files with 9 additions and 10 deletions

View File

@@ -1385,19 +1385,19 @@ DockerDeviceFactory::DockerDeviceFactory()
});
setConstructionFunction([this] {
auto device = DockerDevice::create();
QMutexLocker lk(&m_deviceListMutex);
m_existingDevices.push_back(device);
m_existingDevices.writeLocked()->push_back(device);
return device;
});
}
void DockerDeviceFactory::shutdownExistingDevices()
{
QMutexLocker lk(&m_deviceListMutex);
for (const auto &weakDevice : m_existingDevices) {
if (std::shared_ptr<DockerDevice> device = weakDevice.lock())
device->shutdown();
}
m_existingDevices.read([](const std::vector<std::weak_ptr<DockerDevice>> &devices) {
for (const std::weak_ptr<DockerDevice> &weakDevice : devices) {
if (std::shared_ptr<DockerDevice> device = weakDevice.lock())
device->shutdown();
}
});
}
expected_str<QPair<Utils::OsType, Utils::OsArch>> DockerDevicePrivate::osTypeAndArch() const

View File

@@ -8,7 +8,7 @@
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/devicesupport/idevicefactory.h>
#include <QMutex>
#include <utils/synchronizedvalue.h>
namespace Docker::Internal {
@@ -92,8 +92,7 @@ public:
void shutdownExistingDevices();
private:
QMutex m_deviceListMutex;
std::vector<std::weak_ptr<DockerDevice>> m_existingDevices;
Utils::SynchronizedValue<std::vector<std::weak_ptr<DockerDevice>>> m_existingDevices;
};
} // namespace Docker::Internal