commit d424f16fd3016919b1eab127b52b064d53a4fa86 parent 4f4a47a7057fe71f4e58124724f8d656e404ecb6 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Aug 16 12:05:11 +0200 Make platform semaphore functions inline to save work in Makefile Diffstat:
Makefile | | | 2 | +- |
darwin_semaphore.cc | | | 10 | ++++++---- |
linux_semaphore.cc | | | 10 | ++++++---- |
platform_semaphore.h | | | 20 | ++++---------------- |
diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ all: medfall hm.so pp OBJS = main.o gl.o BSPOBJS = bsp.o bsp_renderer.o gl.o -HMOBJS = hm.o heightmap.o terrain_manager.o work_queue.o stb_image.o stb_perlin.o darwin_semaphore.o +HMOBJS = hm.o heightmap.o terrain_manager.o work_queue.o stb_image.o stb_perlin.o PPOBJS = pp.o stb_image.o stb_image_write.o WARNINGS = -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-write-strings diff --git a/darwin_semaphore.cc b/darwin_semaphore.cc @@ -1,15 +1,17 @@ #include <dispatch/dispatch.h> -#include "platform_semaphore.h" +struct Semaphore { + dispatch_semaphore_t sem; +}; -void semaphore_init( Semaphore * const sem ) { +inline void semaphore_init( Semaphore * const sem ) { sem->sem = dispatch_semaphore_create( 0 ); } -void semaphore_signal( Semaphore * const sem ) { +inline void semaphore_signal( Semaphore * const sem ) { dispatch_semaphore_signal( sem->sem ); } -void semaphore_wait( Semaphore * const sem ) { +inline void semaphore_wait( Semaphore * const sem ) { dispatch_semaphore_wait( sem->sem, DISPATCH_TIME_FOREVER ); } diff --git a/linux_semaphore.cc b/linux_semaphore.cc @@ -1,19 +1,21 @@ #include <err.h> #include <semaphore.h> -#include "platform_semaphore.h" +struct Semaphore { + sem_t * sem; +}; -void semaphore_init( Semaphore * const sem ) { +inline void semaphore_init( Semaphore * const sem ) { const int ok = sem_init( &sem->sem, 0, 0 ); if( ok == -1 ) { err( 1, "sem_init failed" ); } } -void semaphore_signal( Semaphore * const sem ) { +inline void semaphore_signal( Semaphore * const sem ) { sem_post( sem->sem ); } -void semaphore_wait( Semaphore * const sem ) { +inline void semaphore_wait( Semaphore * const sem ) { sem_wait( sem->sem ); } diff --git a/platform_semaphore.h b/platform_semaphore.h @@ -2,24 +2,12 @@ #ifndef _PLATFORM_SEMAPHORE_H_ #define _PLATFORM_SEMAPHORE_H_ -#ifdef __APPLE__ -#include <dispatch/dispatch.h> - -struct Semaphore { - dispatch_semaphore_t sem; -}; +#ifdef __linux__ +#include "linux_semaphore.cc" #endif -#ifdef __linux__ // this is wrong -#include <semaphore.h> - -struct Semaphore { - sem_t * sem; -}; +#ifdef __APPLE__ +#include "darwin_semaphore.cc" #endif -void semaphore_init( Semaphore * const sem ); -void semaphore_signal( Semaphore * const sem ); -void semaphore_wait( Semaphore * const sem ); - #endif // _PLATFORM_SEMAPHORE_H_