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

View File

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