Merge pull request #12616 from mitaclaw/dvd-interface-cpu-thread-guard
DVDInterface: Modernize With CPUThreadGuard
This commit is contained in:
commit
c964d552c9
|
@ -635,7 +635,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(J
|
|||
HostThreadLock guard;
|
||||
const std::string path = GetJString(env, jFile);
|
||||
__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,
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "Core/AchievementManager.h"
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Config/SessionSettings.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "Core/DolphinAnalytics.h"
|
||||
#include "Core/HW/AudioInterface.h"
|
||||
|
@ -419,7 +420,7 @@ bool DVDInterface::IsDiscInside() const
|
|||
|
||||
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)
|
||||
|
@ -441,7 +442,7 @@ void DVDInterface::InsertDiscCallback(Core::System& system, u64 userdata, s64 cy
|
|||
}
|
||||
|
||||
// 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);
|
||||
if (cause == EjectCause::User)
|
||||
|
@ -449,7 +450,8 @@ void DVDInterface::EjectDisc(EjectCause cause)
|
|||
}
|
||||
|
||||
// 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");
|
||||
|
||||
|
@ -459,11 +461,11 @@ void DVDInterface::ChangeDisc(const std::vector<std::string>& paths)
|
|||
m_auto_disc_change_index = 0;
|
||||
}
|
||||
|
||||
ChangeDisc(paths[0]);
|
||||
ChangeDisc(guard, paths[0]);
|
||||
}
|
||||
|
||||
// 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())
|
||||
{
|
||||
|
@ -471,7 +473,7 @@ void DVDInterface::ChangeDisc(const std::string& new_path)
|
|||
return;
|
||||
}
|
||||
|
||||
EjectDisc(EjectCause::User);
|
||||
EjectDisc(guard, EjectCause::User);
|
||||
|
||||
m_disc_path_to_insert = new_path;
|
||||
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
|
||||
bool DVDInterface::AutoChangeDisc()
|
||||
bool DVDInterface::AutoChangeDisc(const Core::CPUThreadGuard& guard)
|
||||
{
|
||||
if (m_auto_disc_change_paths.empty())
|
||||
return false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1096,7 +1098,7 @@ void DVDInterface::ExecuteCommand(ReplyType reply_type)
|
|||
}
|
||||
else if (force_eject)
|
||||
{
|
||||
EjectDisc(EjectCause::Software);
|
||||
EjectDisc(Core::CPUThreadGuard{m_system}, EjectCause::Software);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
class PointerWrap;
|
||||
namespace Core
|
||||
{
|
||||
class CPUThreadGuard;
|
||||
class System;
|
||||
}
|
||||
} // namespace Core
|
||||
namespace CoreTiming
|
||||
{
|
||||
struct EventType;
|
||||
|
@ -140,10 +141,10 @@ public:
|
|||
void SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
|
||||
std::optional<std::vector<std::string>> auto_disc_change_paths);
|
||||
bool IsDiscInside() const;
|
||||
void EjectDisc(EjectCause cause); // Must only be called on the CPU thread
|
||||
void ChangeDisc(const std::vector<std::string>& paths); // Must only be called on the CPU thread
|
||||
void ChangeDisc(const std::string& new_path); // Must only be called on the CPU thread
|
||||
bool AutoChangeDisc(); // Must only be called on the CPU thread
|
||||
void EjectDisc(const Core::CPUThreadGuard& guard, EjectCause cause);
|
||||
void ChangeDisc(const Core::CPUThreadGuard& guard, const std::vector<std::string>& paths);
|
||||
void ChangeDisc(const Core::CPUThreadGuard& guard, const std::string& new_path);
|
||||
bool AutoChangeDisc(const Core::CPUThreadGuard& guard);
|
||||
|
||||
// This function returns true and calls SConfig::SetRunningGameMetadata(Volume&, Partition&)
|
||||
// if both of the following conditions are true:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "Core/HW/DVD/DVDInterface.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])
|
||||
{
|
||||
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
|
||||
// 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])
|
||||
{
|
||||
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
|
||||
// TODO: AVE, SLOT_LED
|
||||
|
|
|
@ -1254,13 +1254,12 @@ void MovieManager::PlayController(GCPadStatus* PadStatus, int controllerID)
|
|||
|
||||
if (m_pad_state.disc)
|
||||
{
|
||||
Core::RunAsCPUThread([this] {
|
||||
if (!m_system.GetDVDInterface().AutoChangeDisc())
|
||||
{
|
||||
m_system.GetCPU().Break();
|
||||
PanicAlertFmtT("Change the disc to {0}", m_disc_change_filename);
|
||||
}
|
||||
});
|
||||
const Core::CPUThreadGuard guard(m_system);
|
||||
if (!m_system.GetDVDInterface().AutoChangeDisc(guard))
|
||||
{
|
||||
m_system.GetCPU().Break();
|
||||
PanicAlertFmtT("Change the disc to {0}", m_disc_change_filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pad_state.reset)
|
||||
|
|
|
@ -879,9 +879,8 @@ void GameList::ChangeDisc()
|
|||
if (!game)
|
||||
return;
|
||||
|
||||
Core::RunAsCPUThread([file_path = game->GetFilePath()] {
|
||||
Core::System::GetInstance().GetDVDInterface().ChangeDisc(file_path);
|
||||
});
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, game->GetFilePath());
|
||||
}
|
||||
|
||||
QAbstractItemView* GameList::GetActiveView() const
|
||||
|
|
|
@ -794,15 +794,17 @@ void MainWindow::ChangeDisc()
|
|||
{
|
||||
std::vector<std::string> paths = StringListToStdVector(PromptFileNames());
|
||||
|
||||
if (!paths.empty())
|
||||
Core::RunAsCPUThread(
|
||||
[&paths] { Core::System::GetInstance().GetDVDInterface().ChangeDisc(paths); });
|
||||
if (paths.empty())
|
||||
return;
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, paths);
|
||||
}
|
||||
|
||||
void MainWindow::EjectDisc()
|
||||
{
|
||||
Core::RunAsCPUThread(
|
||||
[] { Core::System::GetInstance().GetDVDInterface().EjectDisc(DVD::EjectCause::User); });
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetDVDInterface().EjectDisc(Core::CPUThreadGuard{system}, DVD::EjectCause::User);
|
||||
}
|
||||
|
||||
void MainWindow::OpenUserFolder()
|
||||
|
|
Loading…
Reference in New Issue