DVDInterface: Modernize With CPUThreadGuard

This commit is contained in:
mitaclaw 2024-03-04 16:45:25 -08:00
parent 8f6fd912f7
commit fe61efcd7a
7 changed files with 39 additions and 32 deletions

View file

@ -635,7 +635,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(J
HostThreadLock guard; HostThreadLock guard;
const std::string path = GetJString(env, jFile); const std::string path = GetJString(env, jFile);
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str()); __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str());
Core::RunAsCPUThread([&path] { Core::System::GetInstance().GetDVDInterface().ChangeDisc(path); }); auto& system = Core::System::GetInstance();
system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, path);
} }
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env, JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env,

View file

@ -23,6 +23,7 @@
#include "Core/AchievementManager.h" #include "Core/AchievementManager.h"
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
#include "Core/Config/SessionSettings.h" #include "Core/Config/SessionSettings.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
#include "Core/DolphinAnalytics.h" #include "Core/DolphinAnalytics.h"
#include "Core/HW/AudioInterface.h" #include "Core/HW/AudioInterface.h"
@ -419,7 +420,7 @@ bool DVDInterface::IsDiscInside() const
void DVDInterface::AutoChangeDiscCallback(Core::System& system, u64 userdata, s64 cyclesLate) void DVDInterface::AutoChangeDiscCallback(Core::System& system, u64 userdata, s64 cyclesLate)
{ {
system.GetDVDInterface().AutoChangeDisc(); system.GetDVDInterface().AutoChangeDisc(Core::CPUThreadGuard{system});
} }
void DVDInterface::EjectDiscCallback(Core::System& system, u64 userdata, s64 cyclesLate) void DVDInterface::EjectDiscCallback(Core::System& system, u64 userdata, s64 cyclesLate)
@ -441,7 +442,7 @@ void DVDInterface::InsertDiscCallback(Core::System& system, u64 userdata, s64 cy
} }
// Must only be called on the CPU thread // Must only be called on the CPU thread
void DVDInterface::EjectDisc(EjectCause cause) void DVDInterface::EjectDisc(const Core::CPUThreadGuard& guard, EjectCause cause)
{ {
m_system.GetCoreTiming().ScheduleEvent(0, m_eject_disc); m_system.GetCoreTiming().ScheduleEvent(0, m_eject_disc);
if (cause == EjectCause::User) if (cause == EjectCause::User)
@ -449,7 +450,8 @@ void DVDInterface::EjectDisc(EjectCause cause)
} }
// Must only be called on the CPU thread // Must only be called on the CPU thread
void DVDInterface::ChangeDisc(const std::vector<std::string>& paths) void DVDInterface::ChangeDisc(const Core::CPUThreadGuard& guard,
const std::vector<std::string>& paths)
{ {
ASSERT_MSG(DISCIO, !paths.empty(), "Trying to insert an empty list of discs"); ASSERT_MSG(DISCIO, !paths.empty(), "Trying to insert an empty list of discs");
@ -459,11 +461,11 @@ void DVDInterface::ChangeDisc(const std::vector<std::string>& paths)
m_auto_disc_change_index = 0; m_auto_disc_change_index = 0;
} }
ChangeDisc(paths[0]); ChangeDisc(guard, paths[0]);
} }
// Must only be called on the CPU thread // Must only be called on the CPU thread
void DVDInterface::ChangeDisc(const std::string& new_path) void DVDInterface::ChangeDisc(const Core::CPUThreadGuard& guard, const std::string& new_path)
{ {
if (!m_disc_path_to_insert.empty()) if (!m_disc_path_to_insert.empty())
{ {
@ -471,7 +473,7 @@ void DVDInterface::ChangeDisc(const std::string& new_path)
return; return;
} }
EjectDisc(EjectCause::User); EjectDisc(guard, EjectCause::User);
m_disc_path_to_insert = new_path; m_disc_path_to_insert = new_path;
m_system.GetCoreTiming().ScheduleEvent(m_system.GetSystemTimers().GetTicksPerSecond(), m_system.GetCoreTiming().ScheduleEvent(m_system.GetSystemTimers().GetTicksPerSecond(),
@ -491,13 +493,13 @@ void DVDInterface::ChangeDisc(const std::string& new_path)
} }
// Must only be called on the CPU thread // Must only be called on the CPU thread
bool DVDInterface::AutoChangeDisc() bool DVDInterface::AutoChangeDisc(const Core::CPUThreadGuard& guard)
{ {
if (m_auto_disc_change_paths.empty()) if (m_auto_disc_change_paths.empty())
return false; return false;
m_auto_disc_change_index = (m_auto_disc_change_index + 1) % m_auto_disc_change_paths.size(); m_auto_disc_change_index = (m_auto_disc_change_index + 1) % m_auto_disc_change_paths.size();
ChangeDisc(m_auto_disc_change_paths[m_auto_disc_change_index]); ChangeDisc(guard, m_auto_disc_change_paths[m_auto_disc_change_index]);
return true; return true;
} }
@ -1096,7 +1098,7 @@ void DVDInterface::ExecuteCommand(ReplyType reply_type)
} }
else if (force_eject) else if (force_eject)
{ {
EjectDisc(EjectCause::Software); EjectDisc(Core::CPUThreadGuard{m_system}, EjectCause::Software);
} }
break; break;
} }

View file

@ -17,8 +17,9 @@
class PointerWrap; class PointerWrap;
namespace Core namespace Core
{ {
class CPUThreadGuard;
class System; class System;
} } // namespace Core
namespace CoreTiming namespace CoreTiming
{ {
struct EventType; struct EventType;
@ -140,10 +141,10 @@ public:
void SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc, void SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
std::optional<std::vector<std::string>> auto_disc_change_paths); std::optional<std::vector<std::string>> auto_disc_change_paths);
bool IsDiscInside() const; bool IsDiscInside() const;
void EjectDisc(EjectCause cause); // Must only be called on the CPU thread void EjectDisc(const Core::CPUThreadGuard& guard, EjectCause cause);
void ChangeDisc(const std::vector<std::string>& paths); // Must only be called on the CPU thread void ChangeDisc(const Core::CPUThreadGuard& guard, const std::vector<std::string>& paths);
void ChangeDisc(const std::string& new_path); // Must only be called on the CPU thread void ChangeDisc(const Core::CPUThreadGuard& guard, const std::string& new_path);
bool AutoChangeDisc(); // Must only be called on the CPU thread bool AutoChangeDisc(const Core::CPUThreadGuard& guard);
// This function returns true and calls SConfig::SetRunningGameMetadata(Volume&, Partition&) // This function returns true and calls SConfig::SetRunningGameMetadata(Volume&, Partition&)
// if both of the following conditions are true: // if both of the following conditions are true:

View file

@ -6,6 +6,7 @@
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
#include "Core/HW/DVD/DVDInterface.h" #include "Core/HW/DVD/DVDInterface.h"
#include "Core/HW/MMIO.h" #include "Core/HW/MMIO.h"
@ -176,7 +177,8 @@ void WiiIPC::RegisterMMIO(MMIO::Mapping* mmio, u32 base)
if (wii_ipc.m_gpio_out[GPIO::DO_EJECT]) if (wii_ipc.m_gpio_out[GPIO::DO_EJECT])
{ {
INFO_LOG_FMT(WII_IPC, "Ejecting disc due to GPIO write"); INFO_LOG_FMT(WII_IPC, "Ejecting disc due to GPIO write");
system.GetDVDInterface().EjectDisc(DVD::EjectCause::Software); system.GetDVDInterface().EjectDisc(Core::CPUThreadGuard{system},
DVD::EjectCause::Software);
} }
// SENSOR_BAR is checked by WiimoteEmu::CameraLogic // SENSOR_BAR is checked by WiimoteEmu::CameraLogic
// TODO: AVE, SLOT_LED // TODO: AVE, SLOT_LED
@ -212,7 +214,8 @@ void WiiIPC::RegisterMMIO(MMIO::Mapping* mmio, u32 base)
if (wii_ipc.m_gpio_out[GPIO::DO_EJECT]) if (wii_ipc.m_gpio_out[GPIO::DO_EJECT])
{ {
INFO_LOG_FMT(WII_IPC, "Ejecting disc due to GPIO write"); INFO_LOG_FMT(WII_IPC, "Ejecting disc due to GPIO write");
system.GetDVDInterface().EjectDisc(DVD::EjectCause::Software); system.GetDVDInterface().EjectDisc(Core::CPUThreadGuard{system},
DVD::EjectCause::Software);
} }
// SENSOR_BAR is checked by WiimoteEmu::CameraLogic // SENSOR_BAR is checked by WiimoteEmu::CameraLogic
// TODO: AVE, SLOT_LED // TODO: AVE, SLOT_LED

View file

@ -1254,13 +1254,12 @@ void MovieManager::PlayController(GCPadStatus* PadStatus, int controllerID)
if (m_pad_state.disc) if (m_pad_state.disc)
{ {
Core::RunAsCPUThread([this] { const Core::CPUThreadGuard guard(m_system);
if (!m_system.GetDVDInterface().AutoChangeDisc()) if (!m_system.GetDVDInterface().AutoChangeDisc(guard))
{ {
m_system.GetCPU().Break(); m_system.GetCPU().Break();
PanicAlertFmtT("Change the disc to {0}", m_disc_change_filename); PanicAlertFmtT("Change the disc to {0}", m_disc_change_filename);
} }
});
} }
if (m_pad_state.reset) if (m_pad_state.reset)

View file

@ -879,9 +879,8 @@ void GameList::ChangeDisc()
if (!game) if (!game)
return; return;
Core::RunAsCPUThread([file_path = game->GetFilePath()] { auto& system = Core::System::GetInstance();
Core::System::GetInstance().GetDVDInterface().ChangeDisc(file_path); system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, game->GetFilePath());
});
} }
QAbstractItemView* GameList::GetActiveView() const QAbstractItemView* GameList::GetActiveView() const

View file

@ -794,15 +794,17 @@ void MainWindow::ChangeDisc()
{ {
std::vector<std::string> paths = StringListToStdVector(PromptFileNames()); std::vector<std::string> paths = StringListToStdVector(PromptFileNames());
if (!paths.empty()) if (paths.empty())
Core::RunAsCPUThread( return;
[&paths] { Core::System::GetInstance().GetDVDInterface().ChangeDisc(paths); });
auto& system = Core::System::GetInstance();
system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, paths);
} }
void MainWindow::EjectDisc() void MainWindow::EjectDisc()
{ {
Core::RunAsCPUThread( auto& system = Core::System::GetInstance();
[] { Core::System::GetInstance().GetDVDInterface().EjectDisc(DVD::EjectCause::User); }); system.GetDVDInterface().EjectDisc(Core::CPUThreadGuard{system}, DVD::EjectCause::User);
} }
void MainWindow::OpenUserFolder() void MainWindow::OpenUserFolder()