mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-08-15 14:43:19 +00:00
Get rid of recursive mutex.
This commit is contained in:
parent
7f01b153b3
commit
27f25d5878
@ -166,23 +166,26 @@ bool ModelList::lessThan(const ModelInfo* a, const ModelInfo* b)
|
|||||||
|
|
||||||
void ModelList::addModel(const QString &filename)
|
void ModelList::addModel(const QString &filename)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_mutex);
|
const bool hasModel = contains(filename);
|
||||||
Q_ASSERT(!m_modelMap.contains(filename));
|
Q_ASSERT(!hasModel);
|
||||||
if (m_modelMap.contains(filename)) {
|
if (hasModel) {
|
||||||
qWarning() << "ERROR: model list already contains" << filename;
|
qWarning() << "ERROR: model list already contains" << filename;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), m_models.size(), m_models.size());
|
beginInsertRows(QModelIndex(), m_models.size(), m_models.size());
|
||||||
|
int modelSizeAfter = 0;
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
ModelInfo *info = new ModelInfo;
|
ModelInfo *info = new ModelInfo;
|
||||||
info->filename = filename;
|
info->filename = filename;
|
||||||
m_models.append(info);
|
m_models.append(info);
|
||||||
m_modelMap.insert(filename, info);
|
m_modelMap.insert(filename, info);
|
||||||
endInsertRows();
|
|
||||||
|
|
||||||
std::stable_sort(m_models.begin(), m_models.end(), ModelList::lessThan);
|
std::stable_sort(m_models.begin(), m_models.end(), ModelList::lessThan);
|
||||||
emit dataChanged(index(0, 0), index(m_models.size() - 1, 0));
|
modelSizeAfter = m_models.size();
|
||||||
|
}
|
||||||
|
endInsertRows();
|
||||||
|
emit dataChanged(index(0, 0), index(modelSizeAfter - 1, 0));
|
||||||
emit userDefaultModelListChanged();
|
emit userDefaultModelListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,6 +274,11 @@ QVariant ModelList::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
void ModelList::updateData(const QString &filename, int role, const QVariant &value)
|
void ModelList::updateData(const QString &filename, int role, const QVariant &value)
|
||||||
{
|
{
|
||||||
|
int modelSize;
|
||||||
|
bool updateInstalled;
|
||||||
|
bool updateIncomplete;
|
||||||
|
int index;
|
||||||
|
{
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
if (!m_modelMap.contains(filename)) {
|
if (!m_modelMap.contains(filename)) {
|
||||||
qWarning() << "ERROR: cannot update as model map does not contain" << filename;
|
qWarning() << "ERROR: cannot update as model map does not contain" << filename;
|
||||||
@ -278,7 +286,7 @@ void ModelList::updateData(const QString &filename, int role, const QVariant &va
|
|||||||
}
|
}
|
||||||
|
|
||||||
ModelInfo *info = m_modelMap.value(filename);
|
ModelInfo *info = m_modelMap.value(filename);
|
||||||
const int index = m_models.indexOf(info);
|
index = m_models.indexOf(info);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
qWarning() << "ERROR: cannot update as model list does not contain" << filename;
|
qWarning() << "ERROR: cannot update as model list does not contain" << filename;
|
||||||
return;
|
return;
|
||||||
@ -343,16 +351,18 @@ void ModelList::updateData(const QString &filename, int role, const QVariant &va
|
|||||||
QFileInfo fileInfo(info->dirpath + info->filename);
|
QFileInfo fileInfo(info->dirpath + info->filename);
|
||||||
if (info->installed != fileInfo.exists()) {
|
if (info->installed != fileInfo.exists()) {
|
||||||
info->installed = fileInfo.exists();
|
info->installed = fileInfo.exists();
|
||||||
emit dataChanged(createIndex(index, 0), createIndex(index, 0), {InstalledRole});
|
updateInstalled = true;
|
||||||
}
|
}
|
||||||
QFileInfo incompleteInfo(incompleteDownloadPath(info->filename));
|
QFileInfo incompleteInfo(incompleteDownloadPath(info->filename));
|
||||||
if (info->isIncomplete != incompleteInfo.exists()) {
|
if (info->isIncomplete != incompleteInfo.exists()) {
|
||||||
info->isIncomplete = incompleteInfo.exists();
|
info->isIncomplete = incompleteInfo.exists();
|
||||||
emit dataChanged(createIndex(index, 0), createIndex(index, 0), {IncompleteRole});
|
updateIncomplete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stable_sort(m_models.begin(), m_models.end(), ModelList::lessThan);
|
std::stable_sort(m_models.begin(), m_models.end(), ModelList::lessThan);
|
||||||
emit dataChanged(createIndex(0, 0), createIndex(m_models.size() - 1, 0));
|
modelSize = m_models.size();
|
||||||
|
}
|
||||||
|
emit dataChanged(createIndex(0, 0), createIndex(modelSize - 1, 0));
|
||||||
emit userDefaultModelListChanged();
|
emit userDefaultModelListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ private:
|
|||||||
static bool lessThan(const ModelInfo* a, const ModelInfo* b);
|
static bool lessThan(const ModelInfo* a, const ModelInfo* b);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QRecursiveMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
InstalledModels *m_installedModels;
|
InstalledModels *m_installedModels;
|
||||||
DownloadableModels *m_downloadableModels;
|
DownloadableModels *m_downloadableModels;
|
||||||
QList<ModelInfo*> m_models;
|
QList<ModelInfo*> m_models;
|
||||||
|
Loading…
Reference in New Issue
Block a user