Skip to content

Commit

Permalink
Merge pull request #3980 from JosJuice/changedisc-threading-simplific…
Browse files Browse the repository at this point in the history
…ation

DVDInterface: Simplify calling ChangeDisc from CPU thread
  • Loading branch information
Parlane committed Jul 13, 2016
2 parents f4d2626 + 865be48 commit baf9abe
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
15 changes: 12 additions & 3 deletions Source/Core/Core/HW/DVDInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,20 @@ static void InsertDiscCallback(u64 userdata, s64 cyclesLate)
delete _FileName;
}

void ChangeDisc(const std::string& newFileName)
// Can only be called by the host thread
void ChangeDiscAsHost(const std::string& newFileName)
{
// WARNING: Can only run on Host Thread
bool was_unpaused = Core::PauseAndLock(true);

// The host thread is now temporarily the CPU thread
ChangeDiscAsCPU(newFileName);

Core::PauseAndLock(false, was_unpaused);
}

// Can only be called by the CPU thread
void ChangeDiscAsCPU(const std::string& newFileName)
{
std::string* _FileName = new std::string(newFileName);
CoreTiming::ScheduleEvent(0, s_eject_disc);
CoreTiming::ScheduleEvent(500000000, s_insert_disc, (u64)_FileName);
Expand All @@ -492,7 +502,6 @@ void ChangeDisc(const std::string& newFileName)
}
Movie::g_discChange = fileName.substr(sizeofpath);
}
Core::PauseAndLock(false, was_unpaused);
}

void SetLidOpen(bool open)
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/HW/DVDInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ bool VolumeIsValid();
// Disc detection and swapping
void SetDiscInside(bool _DiscInside);
bool IsDiscInside();
void ChangeDisc(const std::string& fileName); // [NOT THREADSAFE] Host only
void ChangeDiscAsHost(const std::string& path); // Can only be called by the host thread
void ChangeDiscAsCPU(const std::string& path); // Can only be called by the CPU thread

// DVD Access Functions
bool ChangePartition(u64 offset);
Expand Down
25 changes: 8 additions & 17 deletions Source/Core/Core/Movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,36 +1210,27 @@ void PlayController(GCPadStatus* PadStatus, int controllerID)
PadStatus->button |= PAD_TRIGGER_R;
if (s_padState.disc)
{
// This implementation assumes the disc change will only happen once. Trying to change more than
// that will cause
// it to load the last disc every time. As far as i know though, there are no 3+ disc games, so
// this should be fine.
CPU::Break();
// This implementation assumes the disc change will only happen once. Trying
// to change more than that will cause it to load the last disc every time.
// As far as I know, there are no 3+ disc games, so this should be fine.
bool found = false;
std::string path;
for (size_t i = 0; i < SConfig::GetInstance().m_ISOFolder.size(); ++i)
for (const std::string& iso_folder : SConfig::GetInstance().m_ISOFolder)
{
path = SConfig::GetInstance().m_ISOFolder[i];
if (File::Exists(path + '/' + g_discChange))
path = iso_folder + '/' + g_discChange;
if (File::Exists(path))
{
found = true;
break;
}
}
if (found)
{
path += '/' + g_discChange;

Core::QueueHostJob([=] {
if (!Movie::IsPlayingInput())
return;

DVDInterface::ChangeDisc(path);
CPU::EnableStepping(false);
});
DVDInterface::ChangeDiscAsCPU(path);
}
else
{
CPU::Break();
PanicAlertT("Change the disc to %s", g_discChange.c_str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void CRenderFrame::OnDropFiles(wxDropFilesEvent& event)
}
else
{
DVDInterface::ChangeDisc(filepath);
DVDInterface::ChangeDiscAsHost(filepath);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/FrameTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ void CFrame::DoOpen(bool Boot)
}
else
{
DVDInterface::ChangeDisc(WxStrToStr(path));
DVDInterface::ChangeDiscAsHost(WxStrToStr(path));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/GameListCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ void CGameListCtrl::OnChangeDisc(wxCommandEvent& WXUNUSED(event))
const GameListItem* iso = GetSelectedISO();
if (!iso || !Core::IsRunning())
return;
DVDInterface::ChangeDisc(WxStrToStr(iso->GetFileName()));
DVDInterface::ChangeDiscAsHost(WxStrToStr(iso->GetFileName()));
}

void CGameListCtrl::OnSize(wxSizeEvent& event)
Expand Down

0 comments on commit baf9abe

Please sign in to comment.