medfall

A super great game engine
Log | Files | Refs

darwin_semaphore.h (674B)


      1 #pragma once
      2 
      3 #include <dispatch/dispatch.h>
      4 
      5 struct PlatformSemaphore {
      6 	dispatch_semaphore_t sem;
      7 };
      8 
      9 inline void platform_semaphore_init( PlatformSemaphore * sem ) {
     10 	sem->sem = dispatch_semaphore_create( 0 );
     11 	if( sem->sem == NULL ) {
     12 		FATAL( "dispatch_semaphore_create" );
     13 	}
     14 }
     15 
     16 inline void platform_semaphore_signal( PlatformSemaphore * sem ) {
     17 	dispatch_semaphore_signal( sem->sem );
     18 }
     19 
     20 inline void platform_semaphore_wait( PlatformSemaphore * sem ) {
     21 	dispatch_semaphore_wait( sem->sem, DISPATCH_TIME_FOREVER );
     22 }
     23 
     24 inline void platform_semaphore_destroy( PlatformSemaphore * sem ) {
     25 	// TODO: might need a cast to dispatch_object_t
     26 	dispatch_release( sem->sem );
     27 }