medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 1866f96788a08c71ab1c8af2526741b4b3abf8b8
parent 1a6367f2f0acca37fbcba6b3385c681c8f094595
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Feb 19 13:06:41 +0200

Use CRITICAL_SECTION in win32_mutex

Diffstat:
win32_mutex.h | 24++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/win32_mutex.h b/win32_mutex.h @@ -5,37 +5,25 @@ #include "log.h" struct Mutex { - HANDLE mutex; + CRITICAL_SECTION cs; }; inline void mutex_init( Mutex * mutex ) { - mutex->mutex = CreateMutex( NULL, FALSE, NULL ); - if( mutex->mutex == NULL ) { - FATAL( "CreateMutex failed" ); - } + InitializeCriticalSection( &mutex->cs ); } inline void mutex_destroy( Mutex * mutex ) { - if( CloseHandle( mutex->mutex ) == 0 ) { - FATAL( "CloseHandle failed" ); - } + DeleteCriticalSection( &mutex->cs ); } inline void mutex_lock( Mutex * mutex ) { - if( WaitForSingleObject( mutex->mutex, INFINITE ) == WAIT_FAILED ) { - FATAL( "WaitForSingleObject failed" ); - } + EnterCriticalSection( &mutex->cs ); } inline bool mutex_trylock( Mutex * mutex ) { - DWORD ok = WaitForSingleObject( mutex->mutex, 0 ); - if( ok == WAIT_FAILED ) FATAL( "WaitForSingleObject failed" ); - if( ok == WAIT_TIMEOUT ) return false; - return true; + return TryEnterCriticalSection( &mutex->cs ) != 0; } inline void mutex_unlock( Mutex * mutex ) { - if( ReleaseMutex( mutex->mutex ) == 0 ) { - FATAL( "ReleaseMutex failed" ); - } + LeaveCriticalSection( &mutex->cs ); }