medfall

A super great game engine
Log | Files | Refs

commit 4c6b17656a85cd97b9afe2a4b1564c04e60e34f5
parent 84102d9b1265e7e2f3ea35e394e9fd9a1e5e47fa
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue, 21 Aug 2018 10:16:04 +0300

Merge branch 'master' of ssh://git.mikejsavage.co.uk/medfall

Diffstat:
ggentropy.cc | 2+-
unix_mutex.h | 8--------
win32_mutex.h | 16+++++-----------
3 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/ggentropy.cc b/ggentropy.cc @@ -30,7 +30,7 @@ bool ggentropy( void * buf, size_t n ) { if( CryptAcquireContext( &provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == 0 ) return false; - int ok = CryptGenRandom( provider, n, buf ); + int ok = CryptGenRandom( provider, n, ( BYTE * ) buf ); CryptReleaseContext( provider, 0 ); return ok != 0; diff --git a/unix_mutex.h b/unix_mutex.h @@ -28,14 +28,6 @@ inline void mutex_lock( Mutex * mutex ) { } } -inline bool mutex_trylock( Mutex * mutex ) { - int ok = pthread_mutex_trylock( &mutex->mutex ); - if( ok == 0 ) return true; - if( ok == EBUSY ) return false; - - err( 1, "pthread_mutex_lock: %d", ok ); -} - inline void mutex_unlock( Mutex * mutex ) { int ok = pthread_mutex_unlock( &mutex->mutex ); if( ok != 0 ) { diff --git a/win32_mutex.h b/win32_mutex.h @@ -5,25 +5,19 @@ #include "log.h" struct Mutex { - CRITICAL_SECTION cs; + SRWLOCK lock; }; inline void mutex_init( Mutex * mutex ) { - InitializeCriticalSection( &mutex->cs ); + InitializeSRWLock( &mutex->lock ); } -inline void mutex_destroy( Mutex * mutex ) { - DeleteCriticalSection( &mutex->cs ); -} +inline void mutex_destroy( Mutex * mutex ) { } inline void mutex_lock( Mutex * mutex ) { - EnterCriticalSection( &mutex->cs ); -} - -inline bool mutex_trylock( Mutex * mutex ) { - return TryEnterCriticalSection( &mutex->cs ) != 0; + AcquireSRWLockExclusive( &mutex->lock ); } inline void mutex_unlock( Mutex * mutex ) { - LeaveCriticalSection( &mutex->cs ); + ReleaseSRWLockExclusive( &mutex->lock ); }