forked from qt-creator/qt-creator
Docker: Replace mutex+value with SynchronizedValue
Change-Id: Id7ca66be635abbb479602e040889c7ccfa889179 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user