54 #if defined(ION_PLATFORM_WINDOWS)
55 # if defined(ION_MUTEX_USE_CRITICAL_SECTION)
56 InitializeCriticalSection(&critical_section_);
60 event_ = CreateEvent(NULL, FALSE, FALSE, NULL);
62 #elif defined(ION_PLATFORM_ASMJS)
65 pthread_mutex_init(&pthread_mutex_, NULL);
70 #if defined(ION_PLATFORM_WINDOWS)
71 # if defined(ION_MUTEX_USE_CRITICAL_SECTION)
72 DeleteCriticalSection(&critical_section_);
76 #elif defined(ION_PLATFORM_ASMJS)
79 pthread_mutex_destroy(&pthread_mutex_);
93 #if defined(ION_PLATFORM_WINDOWS)
94 # if defined(ION_MUTEX_USE_CRITICAL_SECTION)
95 EnterCriticalSection(&critical_section_);
97 if (InterlockedIncrement(&blockers_) > 1)
103 WaitForSingleObject(event_, INFINITE);
108 #elif defined(ION_PLATFORM_ASMJS)
112 pthread_mutex_lock(&pthread_mutex_);
117 #if defined(ION_PLATFORM_WINDOWS)
118 # if defined(ION_MUTEX_USE_CRITICAL_SECTION)
119 return TryEnterCriticalSection(&critical_section_);
121 if (InterlockedIncrement(&blockers_) > 1) {
126 InterlockedDecrement(&blockers_);
133 #elif defined(ION_PLATFORM_ASMJS)
141 return pthread_mutex_trylock(&pthread_mutex_) == 0;
146 #if defined(ION_PLATFORM_WINDOWS)
147 # if defined(ION_MUTEX_USE_CRITICAL_SECTION)
148 LeaveCriticalSection(&critical_section_);
157 if (InterlockedDecrement(&blockers_) > 0)
161 #elif defined(ION_PLATFORM_ASMJS)
165 pthread_mutex_unlock(&pthread_mutex_);
169 #undef ION_MUTEX_USE_CRITICAL_SECTION
bool TryLock()
Returns true if the mutex was successfully locked, and false otherwise.
bool IsLocked()
Returns whether the Mutex is currently locked. Does not block.
Mutex()
POSIX mutexes are non-recursive, meaning that if the same thread tries to Lock() the mutex...
void Unlock()
Unlocks the Mutex.
void Lock()
Locks the Mutex.
ThreadId GetCurrentThreadId()
Thread ID functions.