commit 73e24f4d2f5e9e96b28a51034158b45203d7b9c6 parent 94c05bf59708e8a7bafcf9f92818e635a1af45b7 Author: Michael Savage <mikejsavage@gmail.com> Date: Thu Aug 13 21:50:44 +0200 Use dispatch_semaphore_t while I am on OS X Diffstat:
work_queue.cc | | | 15 | +++++++++++---- |
work_queue.h | | | 6 | ++++-- |
diff --git a/work_queue.cc b/work_queue.cc @@ -1,5 +1,7 @@ +#include <err.h> #include <pthread.h> -#include <semaphore.h> +// #include <semaphore.h> +#include <dispatch/dispatch.h> #include "int.h" #include "work_queue.h" @@ -38,7 +40,8 @@ static void * workqueue_worker( void * data ) { for( ;; ) { if( !workqueue_step( queue ) ) { - sem_wait( queue->sem ); + // sem_wait( queue->sem ); + dispatch_semaphore_wait( queue->sem, DISPATCH_TIME_FOREVER ); } } @@ -48,7 +51,10 @@ static void * workqueue_worker( void * data ) { void workqueue_init( WorkQueue * const queue, const u32 num_threads ) { *queue = { }; - sem_init( queue->sem, 0, 0 ); + // if( sem_init( queue->sem, 0, 0 ) == -1 ) { + // err( 1, "can't create semaphore" ); + // } + queue->sem = dispatch_semaphore_create( 0 ); for( u32 i = 0; i < num_threads; i++ ) { pthread_t thread; @@ -67,7 +73,8 @@ void workqueue_enqueue( WorkQueue * const queue, WorkQueueCallback * const callb write_barrier(); queue->tail = ( queue->tail + 1 ) % array_len( queue->jobs ); - sem_post( queue->sem ); + // sem_post( queue->sem ); + dispatch_semaphore_signal( queue->sem ); } void workqueue_exhaust( WorkQueue * const queue ) { diff --git a/work_queue.h b/work_queue.h @@ -1,7 +1,8 @@ #ifndef _WORK_QUEUE_H_ #define _WORK_QUEUE_H_ -#include <semaphore.h> +// #include <semaphore.h> +#include <dispatch/dispatch.h> #include "int.h" @@ -16,7 +17,8 @@ struct Job { struct WorkQueue { Job jobs[ 256 ]; - sem_t * sem; + // sem_t * sem; + dispatch_semaphore_t sem; // using head/length means we need to an atomic pair which is a pain volatile u16 head;