summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinWX/FrameTools.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2017-07-21 14:06:02 +0800
committerLéo Lam <leo@innovatetechnologi.es>2017-07-21 16:45:59 +0800
commitf106a9637df3f1cb31a09d451729cae1acdc63cb (patch)
treeb4519263d46f4ad6ef38830666857107e3981a88 /Source/Core/DolphinWX/FrameTools.cpp
parent2f0bec93cb3eb02f159461f13557bde4bd2771bb (diff)
Replace balanced Core::PauseAndLock calls with RunAsCPUThread
Core::PauseAndLock requires all calls to it to be balanced, like this: const bool was_unpaused = Core::PauseAndLock(true); // do stuff on the CPU thread Core::PauseAndLock(false, was_unpaused); Aside from being a bit cumbersome, it turns out all callers really don't need to know about was_unpaused at all. They just need to do something on the CPU thread safely, including locking/unlocking. So this commit replaces Core::PauseAndLock with a function that makes both the purpose and the scope of what is being run on the CPU thread visually clear. This makes it harder to accidentally run something on the wrong thread, or forget the second call to PauseAndLock to unpause, or forget that it needs to be passed was_unpaused at the end. We also don't need comments to indicate code X is being run on the CPU thread anymore, as the function name makes it obvious.
Diffstat (limited to 'Source/Core/DolphinWX/FrameTools.cpp')
-rw-r--r--Source/Core/DolphinWX/FrameTools.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp
index a403118000..d633561cfd 100644
--- a/Source/Core/DolphinWX/FrameTools.cpp
+++ b/Source/Core/DolphinWX/FrameTools.cpp
@@ -1411,19 +1411,19 @@ void CFrame::ConnectWiimote(int wm_idx, bool connect)
if (Core::IsRunning() && SConfig::GetInstance().bWii &&
!SConfig::GetInstance().m_bt_passthrough_enabled)
{
- bool was_unpaused = Core::PauseAndLock(true);
- const auto ios = IOS::HLE::GetIOS();
- if (!ios)
- return;
+ Core::RunAsCPUThread([&] {
+ const auto ios = IOS::HLE::GetIOS();
+ if (!ios)
+ return;
- const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
- ios->GetDeviceByName("/dev/usb/oh1/57e/305"));
- if (bt)
- bt->AccessWiiMote(wm_idx | 0x100)->Activate(connect);
- const char* message = connect ? "Wii Remote %i connected" : "Wii Remote %i disconnected";
- Core::DisplayMessage(StringFromFormat(message, wm_idx + 1), 3000);
- Host_UpdateMainFrame();
- Core::PauseAndLock(false, was_unpaused);
+ const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
+ ios->GetDeviceByName("/dev/usb/oh1/57e/305"));
+ if (bt)
+ bt->AccessWiiMote(wm_idx | 0x100)->Activate(connect);
+ const char* message = connect ? "Wii Remote %i connected" : "Wii Remote %i disconnected";
+ Core::DisplayMessage(StringFromFormat(message, wm_idx + 1), 3000);
+ Host_UpdateMainFrame();
+ });
}
}
@@ -1432,13 +1432,13 @@ void CFrame::OnConnectWiimote(wxCommandEvent& event)
const auto ios = IOS::HLE::GetIOS();
if (!ios || SConfig::GetInstance().m_bt_passthrough_enabled)
return;
- bool was_unpaused = Core::PauseAndLock(true);
- const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
- ios->GetDeviceByName("/dev/usb/oh1/57e/305"));
- const bool is_connected =
- bt && bt->AccessWiiMote((event.GetId() - IDM_CONNECT_WIIMOTE1) | 0x100)->IsConnected();
- ConnectWiimote(event.GetId() - IDM_CONNECT_WIIMOTE1, !is_connected);
- Core::PauseAndLock(false, was_unpaused);
+ Core::RunAsCPUThread([&] {
+ const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
+ ios->GetDeviceByName("/dev/usb/oh1/57e/305"));
+ const bool is_connected =
+ bt && bt->AccessWiiMote((event.GetId() - IDM_CONNECT_WIIMOTE1) | 0x100)->IsConnected();
+ ConnectWiimote(event.GetId() - IDM_CONNECT_WIIMOTE1, !is_connected);
+ });
}
// Toggle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_panel to
@@ -1603,15 +1603,15 @@ void CFrame::UpdateGUI()
GetMenuBar()->FindItem(IDM_CONNECT_BALANCEBOARD)->Enable(ShouldEnableWiimotes);
if (ShouldEnableWiimotes)
{
- bool was_unpaused = Core::PauseAndLock(true);
- GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(bt->AccessWiiMote(0x0100)->IsConnected());
- GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(bt->AccessWiiMote(0x0101)->IsConnected());
- GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Check(bt->AccessWiiMote(0x0102)->IsConnected());
- GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Check(bt->AccessWiiMote(0x0103)->IsConnected());
- GetMenuBar()
- ->FindItem(IDM_CONNECT_BALANCEBOARD)
- ->Check(bt->AccessWiiMote(0x0104)->IsConnected());
- Core::PauseAndLock(false, was_unpaused);
+ Core::RunAsCPUThread([&] {
+ GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(bt->AccessWiiMote(0x0100)->IsConnected());
+ GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(bt->AccessWiiMote(0x0101)->IsConnected());
+ GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Check(bt->AccessWiiMote(0x0102)->IsConnected());
+ GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Check(bt->AccessWiiMote(0x0103)->IsConnected());
+ GetMenuBar()
+ ->FindItem(IDM_CONNECT_BALANCEBOARD)
+ ->Check(bt->AccessWiiMote(0x0104)->IsConnected());
+ });
}
GetMenuBar()->FindItem(IDM_RECORD_READ_ONLY)->Enable(Running || Paused);