blob: 3f2bd63163e3a35440966d8e2f1603840f938f3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "UnityPrefix.h"
#if SUPPORT_THREADS
#ifndef MUTEX_API_WINAPI
#define MUTEX_API_WINAPI (UNITY_WIN || UNITY_XENON || UNITY_WINRT)
#endif
#endif // SUPPORT_THREADS
#if MUTEX_API_WINAPI
#include "PlatformMutex.h"
// -------------------------------------------------------------------------------------------------
// windows
// Note: TryEnterCriticalSection only exists on NT-derived systems.
// But we do not run on Win9x currently anyway, so just accept it.
#if !defined _WIN32_WINNT || _WIN32_WINNT < 0x0400
extern "C" WINBASEAPI BOOL WINAPI TryEnterCriticalSection( IN OUT LPCRITICAL_SECTION lpCriticalSection );
#endif
PlatformMutex::PlatformMutex()
{
#if UNITY_WINRT
BOOL const result = InitializeCriticalSectionEx(&crit_sec, 0, CRITICAL_SECTION_NO_DEBUG_INFO);
Assert(FALSE != result);
#else
InitializeCriticalSection( &crit_sec );
#endif
}
PlatformMutex::~PlatformMutex ()
{
DeleteCriticalSection( &crit_sec );
}
void PlatformMutex::Lock()
{
EnterCriticalSection( &crit_sec );
}
void PlatformMutex::Unlock()
{
LeaveCriticalSection( &crit_sec );
}
bool PlatformMutex::TryLock()
{
return TryEnterCriticalSection( &crit_sec ) ? true : false;
}
#endif // MUTEX_API_WINAPI
|