[partition] Lock the bootloader model during reset

- Try to avoid races between resetting the model and getting
   data from it for the UI.
This commit is contained in:
Adriaan de Groot 2019-04-01 07:36:18 -04:00
parent b03d72952b
commit 752a922bde
2 changed files with 18 additions and 4 deletions

View File

@ -69,6 +69,16 @@ BootLoaderModel::update()
{ {
beginResetModel(); beginResetModel();
blockSignals( true ); blockSignals( true );
updateInternal();
blockSignals( false );
endResetModel();
}
void
BootLoaderModel::updateInternal()
{
QMutexLocker lock(&m_lock);
clear(); clear();
createMbrItems(); createMbrItems();
@ -113,14 +123,13 @@ BootLoaderModel::update()
createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false ) createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false )
); );
} }
blockSignals( false );
endResetModel();
} }
QVariant QVariant
BootLoaderModel::data( const QModelIndex& index, int role ) const BootLoaderModel::data( const QModelIndex& index, int role ) const
{ {
QMutexLocker lock(&m_lock);
if ( role == Qt::DisplayRole ) if ( role == Qt::DisplayRole )
{ {
QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString(); QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString();

View File

@ -19,8 +19,9 @@
#ifndef BOOTLOADERMODEL_H #ifndef BOOTLOADERMODEL_H
#define BOOTLOADERMODEL_H #define BOOTLOADERMODEL_H
#include <QStandardItemModel>
#include <QList> #include <QList>
#include <QMutex>
#include <QStandardItemModel>
class Device; class Device;
@ -51,10 +52,14 @@ public:
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override; QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
using DeviceList = QList< Device* >;
private: private:
QList< Device* > m_devices; DeviceList m_devices;
mutable QMutex m_lock;
void createMbrItems(); void createMbrItems();
void updateInternal();
}; };
#endif /* BOOTLOADERMODEL_H */ #endif /* BOOTLOADERMODEL_H */