Fix Common::Barrier and fix the deadlock by making Common::Event check to see if an event has already been set or not.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7305 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2011-03-05 22:17:28 +00:00
parent 024a87af7a
commit 7bc2ae01f2
4 changed files with 17 additions and 10 deletions

View File

@ -51,18 +51,29 @@ void SetCurrentThreadAffinity(u32 mask);
class Event
{
public:
Event()
: is_set(false)
{};
void Set()
{
if (!is_set)
{
is_set = true;
m_condvar.notify_one();
}
}
void Wait()
{
std::unique_lock<std::mutex> lk(m_mutex);
if (!is_set)
m_condvar.wait(lk);
is_set = false;
}
private:
bool is_set;
std::condition_variable m_condvar;
std::mutex m_mutex;
};
@ -71,10 +82,6 @@ private:
class Barrier
{
public:
Barrier()
: m_count(2), m_waiting(0)
{}
Barrier(size_t count)
: m_count(count), m_waiting(0)
{}
@ -84,7 +91,7 @@ public:
{
std::unique_lock<std::mutex> lk(m_mutex);
if (m_count >= ++m_waiting)
if (m_count == ++m_waiting)
{
m_waiting = 0;
m_condvar.notify_all();

View File

@ -665,7 +665,7 @@ void CFrame::OnHostMessage(wxCommandEvent& event)
break;
case IDM_KEYSTATE:
bKeyStateResult = wxGetKeyState(wxKeyCode(event.GetInt()));
keystate_event.Wait();
keystate_event.Set();
break;
#endif

View File

@ -145,7 +145,7 @@ class CFrame : public CRenderFrame
#ifdef __WXGTK__
Common::Event panic_event;
bool bPanicResult;
Common::Barrier keystate_event;
Common::Event keystate_event;
bool bKeyStateResult;
#endif

View File

@ -1045,7 +1045,7 @@ void CFrame::DoStop()
#ifdef __WXGTK__
// Make sure the app doesn't hang waiting on a keystate check
keystate_event.Wait();
keystate_event.Set();
#endif
BootManager::Stop();