From 19bf3e9945c4069b44554e517db5803986765abb Mon Sep 17 00:00:00 2001 From: zilmar Date: Fri, 6 Nov 2015 22:42:27 +1100 Subject: [PATCH] [Common] Add Sync Event class --- Source/Common/Common.vcproj | 8 +++++++ Source/Common/Common.vcxproj | 2 ++ Source/Common/Common.vcxproj.filters | 6 ++++++ Source/Common/SyncEvent.cpp | 31 ++++++++++++++++++++++++++++ Source/Common/SyncEvent.h | 21 +++++++++++++++++++ Source/Common/stdafx.h | 1 + 6 files changed, 69 insertions(+) create mode 100644 Source/Common/SyncEvent.cpp create mode 100644 Source/Common/SyncEvent.h diff --git a/Source/Common/Common.vcproj b/Source/Common/Common.vcproj index ecce01f61..651bcd98d 100644 --- a/Source/Common/Common.vcproj +++ b/Source/Common/Common.vcproj @@ -177,6 +177,10 @@ /> + + @@ -230,6 +234,10 @@ RelativePath=".\stdtypes.h" > + + diff --git a/Source/Common/Common.vcxproj b/Source/Common/Common.vcxproj index caa307a36..3da6fdc3a 100644 --- a/Source/Common/Common.vcxproj +++ b/Source/Common/Common.vcxproj @@ -43,6 +43,7 @@ Create + @@ -57,6 +58,7 @@ + diff --git a/Source/Common/Common.vcxproj.filters b/Source/Common/Common.vcxproj.filters index 852dc95bd..4c71fc098 100644 --- a/Source/Common/Common.vcxproj.filters +++ b/Source/Common/Common.vcxproj.filters @@ -41,6 +41,9 @@ Source Files + + Source Files + @@ -82,5 +85,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Source/Common/SyncEvent.cpp b/Source/Common/SyncEvent.cpp new file mode 100644 index 000000000..cdf4b4735 --- /dev/null +++ b/Source/Common/SyncEvent.cpp @@ -0,0 +1,31 @@ +#include "stdafx.h" + +SyncEvent::SyncEvent(bool bManualReset) +{ + m_Event = CreateEvent(NULL, bManualReset, FALSE, NULL); +} + +SyncEvent::~SyncEvent() +{ + CloseHandle(m_Event); +} + +void SyncEvent::Trigger() +{ + SetEvent(m_Event); +} + +bool SyncEvent::IsTriggered(int32_t iWaitTime) +{ + return (WAIT_OBJECT_0 == WaitForSingleObject(m_Event,iWaitTime)); +} + +void SyncEvent::Reset() +{ + ResetEvent(m_Event); +} + +void * SyncEvent::GetHandle() +{ + return m_Event; +} \ No newline at end of file diff --git a/Source/Common/SyncEvent.h b/Source/Common/SyncEvent.h new file mode 100644 index 000000000..3b95e8c77 --- /dev/null +++ b/Source/Common/SyncEvent.h @@ -0,0 +1,21 @@ +#pragma once + +class SyncEvent +{ +public: + enum { INFINITE_TIMEOUT = 0xFFFFFFFF }; + + SyncEvent(bool bManualReset = true); + ~SyncEvent(void); + + void Trigger (void); + bool IsTriggered (int32_t iWaitTime = 0); + void Reset(); + void * GetHandle(); + +protected: + SyncEvent(const SyncEvent&); // Disable copy constructor + SyncEvent& operator=(const SyncEvent&); // Disable assignment + + void * m_Event; +}; \ No newline at end of file diff --git a/Source/Common/stdafx.h b/Source/Common/stdafx.h index e601c4074..feed741db 100644 --- a/Source/Common/stdafx.h +++ b/Source/Common/stdafx.h @@ -16,3 +16,4 @@ #include "Trace.h" #include "md5.h" #include "Smart Pointer.h" +#include "SyncEvent.h"