Merge pull request #2295 from comex/fix-usb-threading

Fix threading issues
This commit is contained in:
skidau 2015-04-16 12:33:20 +10:00
commit f0593095b4
6 changed files with 11 additions and 13 deletions

View File

@ -267,6 +267,8 @@ void Stop() // - Hammertime!
g_video_backend->Video_ExitLoop(); g_video_backend->Video_ExitLoop();
} }
if (s_emu_thread.joinable())
s_emu_thread.join();
} }
static void DeclareAsCPUThread() static void DeclareAsCPUThread()
@ -793,12 +795,6 @@ void UpdateTitle()
Host_UpdateTitle(SMessage); Host_UpdateTitle(SMessage);
} }
void Shutdown()
{
if (s_emu_thread.joinable())
s_emu_thread.join();
}
void SetOnStoppedCallback(StoppedCallbackFunc callback) void SetOnStoppedCallback(StoppedCallbackFunc callback)
{ {
s_on_stopped_callback = callback; s_on_stopped_callback = callback;

View File

@ -40,7 +40,6 @@ enum EState
bool Init(); bool Init();
void Stop(); void Stop();
void Shutdown();
std::string StopMessage(bool, std::string); std::string StopMessage(bool, std::string);

View File

@ -224,8 +224,7 @@ u64 GetIdleTicks()
// schedule things to be executed on the main thread. // schedule things to be executed on the main thread.
void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata) void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata)
{ {
// TODO: Fix UI thread safety problems, and enable this assertion _assert_msg_(POWERPC, !Core::IsCPUThread(), "ScheduleEvent_Threadsafe from wrong thread");
// _assert_msg_(POWERPC, !Core::IsCPUThread(), "ScheduleEvent_Threadsafe from wrong thread");
std::lock_guard<std::mutex> lk(tsWriteLock); std::lock_guard<std::mutex> lk(tsWriteLock);
Event ne; Event ne;
ne.time = globalTimer + cyclesIntoFuture; ne.time = globalTimer + cyclesIntoFuture;
@ -287,8 +286,8 @@ static void AddEventToQueue(Event* ne)
// than Advance // than Advance
void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata) void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata)
{ {
// TODO: Fix UI thread safety problems, and enable this assertion _assert_msg_(POWERPC, Core::IsCPUThread() || Core::GetState() == Core::CORE_PAUSE,
//_assert_msg_(POWERPC, Core::IsCPUThread(), "ScheduleEvent from wrong thread"); "ScheduleEvent from wrong thread");
Event *ne = GetNewEvent(); Event *ne = GetNewEvent();
ne->userdata = userdata; ne->userdata = userdata;
ne->type = event_type; ne->type = event_type;

View File

@ -1584,17 +1584,21 @@ void CFrame::ConnectWiimote(int wm_idx, bool connect)
{ {
if (Core::IsRunning() && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) if (Core::IsRunning() && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
{ {
bool was_unpaused = Core::PauseAndLock(true);
GetUsbPointer()->AccessWiiMote(wm_idx | 0x100)->Activate(connect); GetUsbPointer()->AccessWiiMote(wm_idx | 0x100)->Activate(connect);
wxString msg(wxString::Format(_("Wiimote %i %s"), wm_idx + 1, wxString msg(wxString::Format(_("Wiimote %i %s"), wm_idx + 1,
connect ? _("Connected") : _("Disconnected"))); connect ? _("Connected") : _("Disconnected")));
Core::DisplayMessage(WxStrToStr(msg), 3000); Core::DisplayMessage(WxStrToStr(msg), 3000);
Host_UpdateMainFrame(); Host_UpdateMainFrame();
Core::PauseAndLock(false, was_unpaused);
} }
} }
void CFrame::OnConnectWiimote(wxCommandEvent& event) void CFrame::OnConnectWiimote(wxCommandEvent& event)
{ {
bool was_unpaused = Core::PauseAndLock(true);
ConnectWiimote(event.GetId() - IDM_CONNECT_WIIMOTE1, !GetUsbPointer()->AccessWiiMote((event.GetId() - IDM_CONNECT_WIIMOTE1) | 0x100)->IsConnected()); ConnectWiimote(event.GetId() - IDM_CONNECT_WIIMOTE1, !GetUsbPointer()->AccessWiiMote((event.GetId() - IDM_CONNECT_WIIMOTE1) | 0x100)->IsConnected());
Core::PauseAndLock(false, was_unpaused);
} }
// Toggle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_Panel to cover // Toggle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_Panel to cover
@ -1792,6 +1796,7 @@ void CFrame::UpdateGUI()
GetMenuBar()->FindItem(IDM_CONNECT_BALANCEBOARD)->Enable(RunningWii); GetMenuBar()->FindItem(IDM_CONNECT_BALANCEBOARD)->Enable(RunningWii);
if (RunningWii) if (RunningWii)
{ {
bool was_unpaused = Core::PauseAndLock(true);
GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(GetUsbPointer()-> GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(GetUsbPointer()->
AccessWiiMote(0x0100)->IsConnected()); AccessWiiMote(0x0100)->IsConnected());
GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(GetUsbPointer()-> GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(GetUsbPointer()->
@ -1802,6 +1807,7 @@ void CFrame::UpdateGUI()
AccessWiiMote(0x0103)->IsConnected()); AccessWiiMote(0x0103)->IsConnected());
GetMenuBar()->FindItem(IDM_CONNECT_BALANCEBOARD)->Check(GetUsbPointer()-> GetMenuBar()->FindItem(IDM_CONNECT_BALANCEBOARD)->Check(GetUsbPointer()->
AccessWiiMote(0x0104)->IsConnected()); AccessWiiMote(0x0104)->IsConnected());
Core::PauseAndLock(false, was_unpaused);
} }
if (m_ToolBar) if (m_ToolBar)

View File

@ -371,7 +371,6 @@ void DolphinApp::OnEndSession(wxCloseEvent& event)
int DolphinApp::OnExit() int DolphinApp::OnExit()
{ {
Core::Shutdown();
UICommon::Shutdown(); UICommon::Shutdown();
delete m_locale; delete m_locale;

View File

@ -348,7 +348,6 @@ int main(int argc, char* argv[])
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN) while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
updateMainFrameEvent.Wait(); updateMainFrameEvent.Wait();
Core::Shutdown();
platform->Shutdown(); platform->Shutdown();
UICommon::Shutdown(); UICommon::Shutdown();