mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-04 22:11:18 +12:00
Make controller button code thread-safe (#405)
* Refactor spinlock to meet Lockable requirements * Input: Refactor button code and make it thread-safe
This commit is contained in:
parent
c40466f3a8
commit
028b3f7992
28 changed files with 311 additions and 220 deletions
|
@ -45,7 +45,8 @@ struct WindowInfo
|
|||
{
|
||||
const std::lock_guard<std::mutex> lock(keycode_mutex);
|
||||
m_keydown[keycode] = state;
|
||||
};
|
||||
}
|
||||
|
||||
bool get_keystate(uint32 keycode)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(keycode_mutex);
|
||||
|
@ -54,25 +55,20 @@ struct WindowInfo
|
|||
return false;
|
||||
return result->second;
|
||||
}
|
||||
void get_keystates(std::unordered_map<uint32, bool>& buttons_out)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(keycode_mutex);
|
||||
for (auto&& button : m_keydown)
|
||||
{
|
||||
buttons_out[button.first] = button.second;
|
||||
}
|
||||
}
|
||||
|
||||
void set_keystatesdown()
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(keycode_mutex);
|
||||
std::for_each(m_keydown.begin(), m_keydown.end(), [](std::pair<const uint32, bool>& el){ el.second = false; });
|
||||
}
|
||||
|
||||
template <typename fn>
|
||||
void iter_keystates(fn f)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(keycode_mutex);
|
||||
std::for_each(m_keydown.cbegin(), m_keydown.cend(), f);
|
||||
}
|
||||
|
||||
WindowHandleInfo window_main;
|
||||
WindowHandleInfo window_pad;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue