From 0cc8eda12449516a1e30d3c31c463ac26cccd9cf Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Sat, 12 Mar 2011 01:19:04 +0000 Subject: [PATCH] Re-enable the std::mutex try_lock on linux and use it for the Host_GetKeyState keystate_lock mutex. This reduces the number of application crashes on linux during emulation. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7334 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/StdMutex.h | 18 ++++++++++-------- Source/Core/DolphinWX/Src/Frame.h | 2 +- Source/Core/DolphinWX/Src/FrameTools.cpp | 2 +- Source/Core/DolphinWX/Src/Main.cpp | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Source/Core/Common/Src/StdMutex.h b/Source/Core/Common/Src/StdMutex.h index 0d8572eb60..4f79ca8f39 100644 --- a/Source/Core/Common/Src/StdMutex.h +++ b/Source/Core/Common/Src/StdMutex.h @@ -157,15 +157,17 @@ public: #endif } +#ifdef __linux__ // TryAcquireSRWLockExclusive requires Windows 7!! -// bool try_lock() -// { -//#ifdef _WIN32 -// return (0 != TryAcquireSRWLockExclusive(&m_handle)); -//#else -// return !pthread_mutex_trylock(&m_handle); -//#endif -// } + bool try_lock() + { +#ifdef _WIN32 + return (0 != TryAcquireSRWLockExclusive(&m_handle)); +#else + return !pthread_mutex_trylock(&m_handle); +#endif + } +#endif native_handle_type native_handle() { diff --git a/Source/Core/DolphinWX/Src/Frame.h b/Source/Core/DolphinWX/Src/Frame.h index 8b74dcf5f4..4feeaf4b76 100644 --- a/Source/Core/DolphinWX/Src/Frame.h +++ b/Source/Core/DolphinWX/Src/Frame.h @@ -145,7 +145,7 @@ class CFrame : public CRenderFrame #ifdef __WXGTK__ Common::Event panic_event; bool bPanicResult; - std::recursive_mutex keystate_lock; + std::mutex keystate_lock; #endif #if defined(HAVE_XRANDR) && HAVE_XRANDR diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index 5b55ab5bc3..7441fc4c62 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -1023,7 +1023,7 @@ void CFrame::DoStop() { #if defined __WXGTK__ wxMutexGuiLeave(); - std::lock_guard lk(keystate_lock); + std::lock_guard lk(keystate_lock); wxMutexGuiEnter(); #endif // Ask for confirmation in case the user accidentally clicked Stop / Escape diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index c0f3ed4709..239f936a21 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -584,8 +584,8 @@ bool Host_GetKeyState(int keycode) #ifdef _WIN32 return GetAsyncKeyState(keycode); #elif defined __WXGTK__ - std::unique_lock lk(main_frame->keystate_lock, std::try_to_lock); - if (!lk.owns_lock()) + std::unique_lock lk(main_frame->keystate_lock, std::defer_lock); + if (!lk.try_lock()) return false; bool key_pressed;