mirror of
https://github.com/libretro/Play-.git
synced 2024-12-12 11:05:36 +00:00
22901bace1
- Removed direct use of WINAPI_FAMILY_PARTITION in MailBox.cpp. - Fixed bug due to changes in SetSpuHandler. - Added missing FUNCTIONSVIEW_STANDALONE definition for DebugWithDebugger config. git-svn-id: http://svn.purei.org/purei/trunk@1191 b36208d7-6611-0410-8bec-b1987f11c4a2
89 lines
1.6 KiB
C++
89 lines
1.6 KiB
C++
#include "MailBox.h"
|
|
#if defined(WIN32)
|
|
#include "win32/Win32Defs.h"
|
|
#endif
|
|
|
|
CMailBox::CMailBox()
|
|
{
|
|
|
|
}
|
|
|
|
CMailBox::~CMailBox()
|
|
{
|
|
|
|
}
|
|
|
|
bool CMailBox::IsPending() const
|
|
{
|
|
return m_calls.size() != 0;
|
|
}
|
|
|
|
void CMailBox::WaitForCall()
|
|
{
|
|
std::unique_lock<std::mutex> callLock(m_callMutex);
|
|
while(!IsPending())
|
|
{
|
|
m_waitCondition.wait(callLock);
|
|
}
|
|
}
|
|
|
|
void CMailBox::WaitForCall(unsigned int timeOut)
|
|
{
|
|
std::unique_lock<std::mutex> callLock(m_callMutex);
|
|
if(IsPending()) return;
|
|
m_waitCondition.wait_for(callLock, std::chrono::milliseconds(timeOut));
|
|
}
|
|
|
|
void CMailBox::FlushCalls()
|
|
{
|
|
SendCall([] () { }, true);
|
|
}
|
|
|
|
void CMailBox::SendCall(const FunctionType& function, bool waitForCompletion)
|
|
{
|
|
std::unique_lock<std::mutex> callLock(m_callMutex);
|
|
|
|
MESSAGE message;
|
|
message.function = function;
|
|
message.sync = waitForCompletion;
|
|
m_calls.push_back(message);
|
|
m_waitCondition.notify_all();
|
|
|
|
if(waitForCompletion)
|
|
{
|
|
m_callDone = false;
|
|
while(!m_callDone)
|
|
{
|
|
#ifdef FRAMEWORK_WIN_DESKTOP
|
|
MSG wmmsg;
|
|
while(PeekMessage(&wmmsg, NULL, 0, 0, PM_REMOVE))
|
|
{
|
|
TranslateMessage(&wmmsg);
|
|
DispatchMessage(&wmmsg);
|
|
}
|
|
m_callFinished.wait_for(callLock, std::chrono::milliseconds(100));
|
|
#else
|
|
m_callFinished.wait(callLock);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
void CMailBox::ReceiveCall()
|
|
{
|
|
MESSAGE message;
|
|
{
|
|
std::unique_lock<std::mutex> waitLock(m_callMutex);
|
|
if(!IsPending()) return;
|
|
message = *m_calls.begin();
|
|
m_calls.pop_front();
|
|
}
|
|
message.function();
|
|
if(message.sync)
|
|
{
|
|
std::unique_lock<std::mutex> waitLock(m_callMutex);
|
|
m_callDone = true;
|
|
m_callFinished.notify_all();
|
|
}
|
|
}
|