medfall

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

commit d15d90c2e72f6dfb91f9da99a4f647566a29f321
parent ac6af3ad60f843e9c0a234335e9861cd289224ce
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Aug 20 20:49:29 +0100

Add win32_semaphore.h

Diffstat:
platform_semaphore.h | 2++
win32_semaphore.h | 36++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/platform_semaphore.h b/platform_semaphore.h @@ -6,6 +6,8 @@ #include "linux_semaphore.h" #elif defined( __APPLE__ ) #include "darwin_semaphore.h" +#elif defined( _WIN32 ) +#include "win32_semaphore.h" #else #error new platform #endif diff --git a/win32_semaphore.h b/win32_semaphore.h @@ -0,0 +1,36 @@ +#ifndef _WIN32_SEMAPHORE_H_ +#define _WIN32_SEMAPHORE_H_ + +#include <windows.h> + +struct Semaphore { + HANDLE sem; +}; + +inline void semaphore_init( Semaphore * sem ) { + LONG max = 1024; // TODO + sem->sem = CreateSemaphore( NULL, 0, max, NULL ); + if( sem->sem == NULL ) { + // ERROR( "CreateSemaphore failed" ); + printf( "CreateSemaphore failed" ); + exit( 1 ); + } +} + +inline void semaphore_signal( Semaphore * sem ) { + if( ReleaseSemaphore( sem->sem, 1, NULL ) == 0 ) { + // ERROR( "ReleaseSemaphore failed" ); + printf( "ReleaseSemaphore failed" ); + exit( 1 ); + } +} + +inline void semaphore_wait( Semaphore * sem ) { + if( WaitForSingleObject( sem->sem, INFINITE ) == WAIT_FAILED ) { + // ERROR( "WaitForSingleObject failed" ); + printf( "WaitForSingleObject failed" ); + exit( 1 ); + } +} + +#endif // _WIN32_SEMAPHORE_H_