Mesen-X/Utilities/AutoResetEvent.cpp
Souryo 37c3201057 Frame decoding/Rendering is now handled by separate threads (i.e there are now 3 threads in the emu + UI thread)
Improved performance (less memory copying, less spin waiting, etc.) - uses less CPU at normal speed, and faster when no FPS limit
2015-08-30 21:04:21 -04:00

33 lines
720 B
C++

#include "stdafx.h"
#include "AutoResetEvent.h"
AutoResetEvent::AutoResetEvent()
{
_signaled = false;
}
AutoResetEvent::~AutoResetEvent()
{
Signal();
}
void AutoResetEvent::Wait(int timeoutDelay)
{
std::unique_lock<std::mutex> lock(_mutex);
if(timeoutDelay == 0) {
//Wait until signaled
_signal.wait(lock, [this] { return _signaled; });
} else {
//Wait until signaled or timeout
auto timeoutTime = std::chrono::system_clock::now() + std::chrono::duration<int, std::milli>(timeoutDelay);
_signal.wait_until(lock, timeoutTime, [this] { return _signaled; });
}
_signaled = false;
}
void AutoResetEvent::Signal()
{
std::unique_lock<std::mutex> lock(_mutex);
_signaled = true;
_signal.notify_all();
}