medfall

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

commit 6ddff6f3a2c4c03269b649cfb4ec3a9a9ae3a0cf
parent f03ba935aef515101aeb68831290109326c7c6c8
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Dec 13 23:13:13 +0200

Add mutex_destroy and ScopedMutexLock

Diffstat:
platform_mutex.h | 16++++++++++++++++
unix_mutex.h | 7+++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/platform_mutex.h b/platform_mutex.h @@ -9,4 +9,20 @@ #error new platform #endif +struct ScopedMutexLock { + Mutex * mutex; + + ScopedMutexLock( Mutex * mtx ) { + mutex = mtx; + mutex_lock( mutex ); + } + + ~ScopedMutexLock() { + mutex_unlock( mutex ); + } +}; + +#define SCOPED_MUTEX_LOCK( mutex ) \ + ScopedMutexLock CONCAT( scoped_mtx, __COUNTER___ )( mutex ); + #endif // _PLATFORM_MUTEX_H_ diff --git a/unix_mutex.h b/unix_mutex.h @@ -15,6 +15,13 @@ inline void mutex_init( Mutex * mutex ) { } } +inline void mutex_destroy( Mutex * mutex ) { + int ok = pthread_mutex_destroy( &mutex->mutex ); + if( ok != 0 ) { + err( 1, "pthread_mutex_destroy: %d", ok ); + } +} + inline void mutex_lock( Mutex * mutex ) { int ok = pthread_mutex_lock( &mutex->mutex ); if( ok != 0 ) {