From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Threads/Winapi/PlatformEvent.h | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Runtime/Threads/Winapi/PlatformEvent.h (limited to 'Runtime/Threads/Winapi/PlatformEvent.h') diff --git a/Runtime/Threads/Winapi/PlatformEvent.h b/Runtime/Threads/Winapi/PlatformEvent.h new file mode 100644 index 0000000..1aa590d --- /dev/null +++ b/Runtime/Threads/Winapi/PlatformEvent.h @@ -0,0 +1,70 @@ +#ifndef __PLATFORMEVENT_H +#define __PLATFORMEVENT_H + +// Event synchronization object. + +#if SUPPORT_THREADS + +#include "Runtime/Utilities/NonCopyable.h" + +class Event : public NonCopyable +{ +public: + explicit Event(); + ~Event(); + + void WaitForSignal(); + void Signal(); + +private: + HANDLE m_Event; +}; + +inline Event::Event() +{ +#if UNITY_WINRT + m_Event = CreateEventExW(nullptr, nullptr, 0, 0); // ?!- +#else + m_Event = CreateEvent(NULL, FALSE, FALSE, NULL); +#endif +} + +inline Event::~Event() +{ + if (m_Event != NULL) + CloseHandle(m_Event); +} + +inline void Event::WaitForSignal() +{ +#if UNITY_WINRT + WaitForSingleObjectEx(m_Event, INFINITE, FALSE); // ?!- +#else + while (1) + { + DWORD result = WaitForSingleObjectEx(m_Event, INFINITE, TRUE); + switch (result) + { + case WAIT_OBJECT_0: + // We got the event + return; + case WAIT_IO_COMPLETION: + // Allow thread to run IO completion task + Sleep(1); + break; + default: + Assert (false); + break; + } + } +#endif +} + +inline void Event::Signal() +{ + SetEvent(m_Event); +} + +#endif // SUPPORT_THREADS + +#endif // __PLATFORMEVENT_H -- cgit v1.1-26-g67d0