[Common] Add Sync Event class

This commit is contained in:
zilmar 2015-11-06 22:42:27 +11:00
parent a3172b30ab
commit 19bf3e9945
6 changed files with 69 additions and 0 deletions

View File

@ -177,6 +177,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\SyncEvent.cpp"
>
</File>
<File
RelativePath="Trace.cpp"
>
@ -230,6 +234,10 @@
RelativePath=".\stdtypes.h"
>
</File>
<File
RelativePath=".\SyncEvent.h"
>
</File>
<File
RelativePath="Trace.h"
>

View File

@ -43,6 +43,7 @@
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SyncEvent.cpp" />
<ClCompile Include="Trace.cpp" />
</ItemGroup>
<ItemGroup>
@ -57,6 +58,7 @@
<ClInclude Include="std string.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="stdtypes.h" />
<ClInclude Include="SyncEvent.h" />
<ClInclude Include="Trace.h" />
<ClInclude Include="TraceDefs.h" />
</ItemGroup>

View File

@ -41,6 +41,9 @@
<ClCompile Include="CriticalSection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SyncEvent.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CriticalSection.h">
@ -82,5 +85,8 @@
<ClInclude Include="stdtypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SyncEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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;
}

21
Source/Common/SyncEvent.h Normal file
View File

@ -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;
};

View File

@ -16,3 +16,4 @@
#include "Trace.h"
#include "md5.h"
#include "Smart Pointer.h"
#include "SyncEvent.h"