feat: stop testing

This commit is contained in:
arm64v8a
2023-08-24 16:16:19 +09:00
parent 3d59c63067
commit 912f9a2bed
6 changed files with 40 additions and 1 deletions

View File

@@ -56,6 +56,7 @@ void MainWindow::setup_grpc() {
// 测速
inline bool speedtesting = false;
inline QList<QThread *> speedtesting_threads = {};
void MainWindow::speedtest_current_group(int mode) {
auto profiles = get_selected_or_group();
@@ -63,6 +64,16 @@ void MainWindow::speedtest_current_group(int mode) {
auto group = NekoGui::profileManager->CurrentGroup();
if (group->archive) return;
// menu_stop_testing
if (mode == 114514) {
while (!speedtesting_threads.isEmpty()) {
auto t = speedtesting_threads.takeFirst();
if (t != nullptr) t->exit();
}
speedtesting = false;
return;
}
#ifndef NKR_NO_GRPC
if (speedtesting) {
MessageBoxWarning(software_name, "The last speed test did not exit completely, please wait. If it persists, please restart the program.");
@@ -117,13 +128,20 @@ void MainWindow::speedtest_current_group(int mode) {
lock_return.lock();
for (int i = 0; i < threadN; i++) {
runOnNewThread([&] {
speedtesting_threads << QObject::thread();
forever {
//
lock_write.lock();
if (profiles_test.isEmpty()) {
threadN_finished++;
if (threadN == threadN_finished) lock_return.unlock();
if (threadN == threadN_finished) {
// quit control thread
lock_return.unlock();
}
lock_write.unlock();
// quit of this thread
speedtesting_threads.removeAll(QObject::thread());
return;
}
auto profile = profiles_test.takeFirst();