citra_meta: Move DetachedTasks construction to main.cpp

This commit is contained in:
PabloMK7 2026-01-19 14:30:13 +01:00 committed by OpenSauce
parent 64516e6420
commit 6634b8c9d9
8 changed files with 51 additions and 51 deletions

View file

@ -4,6 +4,9 @@
#include <iostream>
#include "common/detached_tasks.h"
#include "common/scope_exit.h"
#ifdef ENABLE_QT
#include "citra_qt/citra_qt.h"
#endif
@ -69,6 +72,9 @@ static bool CheckAndReportSSE42() {
#endif
int main(int argc, char* argv[]) {
Common::DetachedTasks detached_tasks;
SCOPE_EXIT({ detached_tasks.WaitForAllTasks(); });
#if CITRA_HAS_SSE42
if (!CheckAndReportSSE42()) {
return 1;
@ -84,8 +90,7 @@ int main(int argc, char* argv[]) {
}
if (launch_room) {
LaunchRoom(argc, argv, true);
return 0;
return LaunchRoom(argc, argv, true);
}
#endif
@ -98,13 +103,12 @@ int main(int argc, char* argv[]) {
}
if (!no_gui) {
LaunchQtFrontend(argc, argv);
return 0;
return LaunchQtFrontend(argc, argv);
}
#endif
#if ENABLE_SDL2_FRONTEND
LaunchSdlFrontend(argc, argv);
return LaunchSdlFrontend(argc, argv);
#else
std::cout << "Cannot use SDL frontend as it was disabled at compile time. Exiting."
<< std::endl;

View file

@ -80,7 +80,6 @@
#include "citra_qt/util/util.h"
#include "common/arch.h"
#include "common/common_paths.h"
#include "common/detached_tasks.h"
#include "common/dynamic_library/dynamic_library.h"
#include "common/file_util.h"
#include "common/literals.h"
@ -4240,14 +4239,12 @@ static Qt::HighDpiScaleFactorRoundingPolicy GetHighDpiRoundingPolicy() {
#endif
}
void LaunchQtFrontend(int argc, char* argv[]) {
int LaunchQtFrontend(int argc, char* argv[]) {
#ifdef __APPLE__
// Ensure that the linker doesn't optimize qt_swizzle.mm out of existence.
QtSwizzle::Dummy();
#endif
Common::DetachedTasks detached_tasks;
#if MICROPROFILE_ENABLED
MicroProfileOnThreadCreate("Frontend");
SCOPE_EXIT({ MicroProfileShutdown(); });
@ -4317,6 +4314,5 @@ void LaunchQtFrontend(int argc, char* argv[]) {
&GMainWindow::OnAppFocusStateChanged);
int result = app.exec();
detached_tasks.WaitForAllTasks();
exit(result);
return result;
}

View file

@ -90,7 +90,7 @@ namespace Service::FS {
enum class MediaType : u32;
}
void LaunchQtFrontend(int argc, char* argv[]);
int LaunchQtFrontend(int argc, char* argv[]);
class GMainWindow : public QMainWindow {
Q_OBJECT

View file

@ -19,7 +19,6 @@
#include "common/common_paths.h"
#include "common/common_types.h"
#include "common/detached_tasks.h"
#include "common/file_util.h"
#include "common/logging/backend.h"
#include "common/logging/log.h"
@ -160,8 +159,7 @@ static void InitializeLogging(const std::string& log_file) {
}
/// Application entry point
void LaunchRoom(int argc, char** argv, bool called_by_option) {
Common::DetachedTasks detached_tasks;
int LaunchRoom(int argc, char** argv, bool called_by_option) {
int option_index = 0;
char* endarg;
@ -251,20 +249,20 @@ void LaunchRoom(int argc, char** argv, bool called_by_option) {
break;
case 'h':
PrintHelp(argv[0]);
exit(0);
return 0;
case 'v':
PrintVersion();
exit(0);
return 0;
case 'e':
PrintRemovedOptionWarning(argv[0], "--enable-citra-mods/-e");
exit(255);
return 255;
case 'g':
PrintRemovedOptionWarning(argv[0], "--preferred-game/-g");
exit(255);
return 255;
case 0:
if (strcmp(long_options[option_index].name, "preferred-game-id") == 0) {
PrintRemovedOptionWarning(argv[0], "--preferred-game-id");
exit(255);
return 255;
}
}
}
@ -273,12 +271,12 @@ void LaunchRoom(int argc, char** argv, bool called_by_option) {
if (room_name.empty()) {
std::cout << "room name is empty!\n\n";
PrintHelp(argv[0]);
exit(-1);
return -1;
}
if (preferred_game.empty()) {
std::cout << "preferred application is empty!\n\n";
PrintHelp(argv[0]);
exit(-1);
return -1;
}
if (preferred_game_id == 0) {
std::cout
@ -289,12 +287,12 @@ void LaunchRoom(int argc, char** argv, bool called_by_option) {
std::cout << "max_members needs to be in the range 2 - "
<< Network::MaxConcurrentConnections << "!\n\n";
PrintHelp(argv[0]);
exit(-1);
return -1;
}
if (port > 65535) {
std::cout << "port needs to be in the range 0 - 65535!\n\n";
PrintHelp(argv[0]);
exit(-1);
return -1;
}
if (ban_list_file.empty()) {
std::cout << "Ban list file not set!\nThis should get set to load and save room ban "
@ -351,7 +349,7 @@ void LaunchRoom(int argc, char** argv, bool called_by_option) {
if (!room->Create(room_name, room_description, "", port, password, max_members, username,
preferred_game, preferred_game_id, std::move(verify_backend), ban_list)) {
std::cout << "Failed to create room: \n\n";
exit(-1);
return -1;
}
std::cout << "Room is open. Close with Q+Enter...\n\n";
auto announce_session = std::make_unique<Network::AnnounceMultiplayerSession>();
@ -377,5 +375,5 @@ void LaunchRoom(int argc, char** argv, bool called_by_option) {
room->Destroy();
}
Network::Shutdown();
detached_tasks.WaitForAllTasks();
return 0;
}

View file

@ -4,4 +4,4 @@
#pragma once
void LaunchRoom(int argc, char** argv, bool called_by_option);
int LaunchRoom(int argc, char** argv, bool called_by_option);

View file

@ -3,7 +3,12 @@
// Refer to the license.txt file included.
#include "citra_room/citra_room.h"
#include "common/detached_tasks.h"
#include "common/scope_exit.h"
int main(int argc, char* argv[]) {
Common::DetachedTasks detached_tasks;
SCOPE_EXIT({ detached_tasks.WaitForAllTasks(); });
LaunchRoom(argc, argv, false);
}

View file

@ -25,7 +25,6 @@
#include "SDL_messagebox.h"
#include "citra_meta/common_strings.h"
#include "common/common_paths.h"
#include "common/detached_tasks.h"
#include "common/file_util.h"
#include "common/logging/backend.h"
#include "common/logging/log.h"
@ -171,11 +170,10 @@ static void OnStatusMessageReceived(const Network::StatusMessageEntry& msg) {
}
/// Application entry point
void LaunchSdlFrontend(int argc, char** argv) {
int LaunchSdlFrontend(int argc, char** argv) {
Common::Log::Initialize();
Common::Log::SetColorConsoleBackendEnabled(true);
Common::Log::Start();
Common::DetachedTasks detached_tasks;
SdlConfig config;
int option_index = 0;
bool use_gdbstub = Settings::values.use_gdbstub.GetValue();
@ -192,7 +190,7 @@ void LaunchSdlFrontend(int argc, char** argv) {
if (argv_w == nullptr) {
LOG_CRITICAL(Frontend, "Failed to get command line arguments");
exit(-1);
return -1;
}
#endif
std::string filepath;
@ -238,12 +236,12 @@ void LaunchSdlFrontend(int argc, char** argv) {
errno = EINVAL;
if (errno != 0) {
perror("--gdbport");
exit(1);
return 1;
}
break;
case 'h':
PrintHelp(argv[0]);
exit(0);
return 0;
case 'i': {
const auto cia_progress = [](std::size_t written, std::size_t total) {
LOG_INFO(Frontend, "{:02d}%", (written * 100 / total));
@ -252,7 +250,7 @@ void LaunchSdlFrontend(int argc, char** argv) {
Service::AM::InstallStatus::Success)
errno = EINVAL;
if (errno != 0)
exit(1);
return 1;
break;
}
case 'p':
@ -273,7 +271,7 @@ void LaunchSdlFrontend(int argc, char** argv) {
if (!std::regex_match(str_arg, re)) {
std::cout << "Wrong format for option --multiplayer\n";
PrintHelp(argv[0]);
exit(0);
return 0;
}
std::smatch match;
@ -288,11 +286,11 @@ void LaunchSdlFrontend(int argc, char** argv) {
if (!std::regex_match(nickname, nickname_re)) {
std::cout
<< "Nickname is not valid. Must be 4 to 20 alphanumeric characters.\n";
exit(0);
return 0;
}
if (address.empty()) {
std::cout << "Address to room must not be empty.\n";
exit(0);
return 0;
}
break;
}
@ -300,7 +298,7 @@ void LaunchSdlFrontend(int argc, char** argv) {
const std::string version_string =
std::string("Azahar ") + Common::g_build_fullname;
ShowCommandOutput("Version", version_string);
exit(0);
return 0;
}
} else {
#ifdef _WIN32
@ -321,12 +319,12 @@ void LaunchSdlFrontend(int argc, char** argv) {
if (filepath.empty()) {
LOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
exit(-1);
return -1;
}
if (!movie_record.empty() && !movie_play.empty()) {
LOG_CRITICAL(Frontend, "Cannot both play and record a movie");
exit(-1);
return -1;
}
auto& system = Core::System::GetInstance();
@ -401,10 +399,10 @@ void LaunchSdlFrontend(int argc, char** argv) {
switch (load_result) {
case Core::System::ResultStatus::ErrorGetLoader:
LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filepath);
exit(-1);
return -1;
case Core::System::ResultStatus::ErrorLoader:
LOG_CRITICAL(Frontend, "Failed to load ROM!");
exit(-1);
return -1;
case Core::System::ResultStatus::ErrorLoader_ErrorEncrypted:
LOG_CRITICAL(Frontend,
"The application that you are trying to load must be decrypted before "
@ -412,16 +410,16 @@ void LaunchSdlFrontend(int argc, char** argv) {
"decrypting applications, please refer to: "
"https://web.archive.org/web/20240304210021/https://citra-emu.org/"
"wiki/dumping-game-cartridges/");
exit(-1);
return -1;
case Core::System::ResultStatus::ErrorLoader_ErrorInvalidFormat:
LOG_CRITICAL(Frontend, "Error while loading ROM: The ROM format is not supported.");
exit(-1);
return -1;
case Core::System::ResultStatus::ErrorNotInitialized:
LOG_CRITICAL(Frontend, "CPUCore not initialized");
exit(-1);
return -1;
case Core::System::ResultStatus::ErrorSystemMode:
LOG_CRITICAL(Frontend, "Failed to determine system mode!");
exit(-1);
return -1;
case Core::System::ResultStatus::Success:
break; // Expected case
default:
@ -441,7 +439,7 @@ void LaunchSdlFrontend(int argc, char** argv) {
Network::NoPreferredMac, password);
} else {
LOG_ERROR(Network, "Could not access RoomMember");
exit(0);
return 0;
}
}
@ -524,6 +522,5 @@ void LaunchSdlFrontend(int argc, char** argv) {
Common::Linux::StopGamemode();
#endif
detached_tasks.WaitForAllTasks();
exit(0);
return 0;
}

View file

@ -1,7 +1,7 @@
// Copyright Citra Emulator Project / Lime3DS Emulator Project
// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
void LaunchSdlFrontend(int argc, char** argv);
int LaunchSdlFrontend(int argc, char** argv);