medfall

A super great game engine
Log | Files | Refs

unix_mutex.h (732B)


      1 #pragma once
      2 
      3 #include <err.h>
      4 #include <pthread.h>
      5 
      6 struct Mutex {
      7 	pthread_mutex_t mutex;
      8 };
      9 
     10 inline void mutex_init( Mutex * mutex ) {
     11 	int ok = pthread_mutex_init( &mutex->mutex, NULL );
     12 	if( ok != 0 ) {
     13 		err( 1, "pthread_mutex_init: %d", ok );
     14 	}
     15 }
     16 
     17 inline void mutex_destroy( Mutex * mutex ) {
     18 	int ok = pthread_mutex_destroy( &mutex->mutex );
     19 	if( ok != 0 ) {
     20 		err( 1, "pthread_mutex_destroy: %d", ok );
     21 	}
     22 }
     23 
     24 inline void mutex_lock( Mutex * mutex ) {
     25 	int ok = pthread_mutex_lock( &mutex->mutex );
     26 	if( ok != 0 ) {
     27 		err( 1, "pthread_mutex_lock: %d", ok );
     28 	}
     29 }
     30 
     31 inline void mutex_unlock( Mutex * mutex ) {
     32 	int ok = pthread_mutex_unlock( &mutex->mutex );
     33 	if( ok != 0 ) {
     34 		err( 1, "pthread_mutex_unlock: %d", ok );
     35 	}
     36 }