[Common] Add Sync Event class
This commit is contained in:
parent
a3172b30ab
commit
19bf3e9945
|
@ -177,6 +177,10 @@
|
||||||
/>
|
/>
|
||||||
</FileConfiguration>
|
</FileConfiguration>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\SyncEvent.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="Trace.cpp"
|
RelativePath="Trace.cpp"
|
||||||
>
|
>
|
||||||
|
@ -230,6 +234,10 @@
|
||||||
RelativePath=".\stdtypes.h"
|
RelativePath=".\stdtypes.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\SyncEvent.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="Trace.h"
|
RelativePath="Trace.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<ClCompile Include="stdafx.cpp">
|
<ClCompile Include="stdafx.cpp">
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="SyncEvent.cpp" />
|
||||||
<ClCompile Include="Trace.cpp" />
|
<ClCompile Include="Trace.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -57,6 +58,7 @@
|
||||||
<ClInclude Include="std string.h" />
|
<ClInclude Include="std string.h" />
|
||||||
<ClInclude Include="stdafx.h" />
|
<ClInclude Include="stdafx.h" />
|
||||||
<ClInclude Include="stdtypes.h" />
|
<ClInclude Include="stdtypes.h" />
|
||||||
|
<ClInclude Include="SyncEvent.h" />
|
||||||
<ClInclude Include="Trace.h" />
|
<ClInclude Include="Trace.h" />
|
||||||
<ClInclude Include="TraceDefs.h" />
|
<ClInclude Include="TraceDefs.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -41,6 +41,9 @@
|
||||||
<ClCompile Include="CriticalSection.cpp">
|
<ClCompile Include="CriticalSection.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="SyncEvent.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="CriticalSection.h">
|
<ClInclude Include="CriticalSection.h">
|
||||||
|
@ -82,5 +85,8 @@
|
||||||
<ClInclude Include="stdtypes.h">
|
<ClInclude Include="stdtypes.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="SyncEvent.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
|
@ -16,3 +16,4 @@
|
||||||
#include "Trace.h"
|
#include "Trace.h"
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include "Smart Pointer.h"
|
#include "Smart Pointer.h"
|
||||||
|
#include "SyncEvent.h"
|
||||||
|
|
Loading…
Reference in New Issue