Provide some guardrails for thread count.

This commit is contained in:
Adam Treat
2023-07-10 16:52:32 -04:00
committed by AT
parent a190041c6e
commit 99cd555743
3 changed files with 8 additions and 7 deletions

View File

@@ -8,7 +8,7 @@
#include <QStandardPaths>
#include <QUrl>
static int default_threadCount = 0;
static int default_threadCount = std::min(4, (int32_t) std::thread::hardware_concurrency());
static bool default_saveChats = false;
static bool default_saveChatGPTChats = true;
static bool default_serverChat = false;
@@ -349,7 +349,10 @@ int MySettings::threadCount() const
{
QSettings setting;
setting.sync();
return setting.value("threadCount", default_threadCount).toInt();
int c = setting.value("threadCount", default_threadCount).toInt();
c = std::max(c, 1);
c = std::min(c, QThread::idealThreadCount());
return c;
}
void MySettings::setThreadCount(int c)
@@ -357,6 +360,8 @@ void MySettings::setThreadCount(int c)
if (threadCount() == c)
return;
c = std::max(c, 1);
c = std::min(c, QThread::idealThreadCount());
QSettings setting;
setting.setValue("threadCount", c);
setting.sync();