linux_semaphore.h (383B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #pragma once #include <err.h> #include <semaphore.h> struct Semaphore { sem_t sem; }; inline void semaphore_init( Semaphore * sem ) { int ok = sem_init( &sem->sem, 0, 0 ); if( ok == -1 ) { err( 1, "sem_init failed" ); } } inline void semaphore_signal( Semaphore * sem ) { sem_post( &sem->sem ); } inline void semaphore_wait( Semaphore * sem ) { sem_wait( &sem->sem ); } |