17 #ifndef __TBB_tbb_semaphore_H
18 #define __TBB_tbb_semaphore_H
27 #include <mach/semaphore.h>
28 #include <mach/task.h>
29 #include <mach/mach_init.h>
30 #include <mach/error.h>
46 class semaphore : no_copy {
47 static const int max_semaphore_cnt = MAXLONG;
54 void P() {WaitForSingleObjectEx(
sem, INFINITE, FALSE );}
56 void V() {ReleaseSemaphore(
sem, 1, NULL );}
60 sem = CreateSemaphoreEx( NULL, LONG(start_cnt_), max_semaphore_cnt, NULL, 0, SEMAPHORE_ALL_ACCESS );
64 class semaphore : no_copy {
71 kern_return_t ret = semaphore_destroy( mach_task_self(),
sem );
78 ret = semaphore_wait(
sem );
79 }
while( ret==KERN_ABORTED );
80 __TBB_ASSERT( ret==KERN_SUCCESS,
"semaphore_wait() failed" );
83 void V() { semaphore_signal(
sem ); }
87 kern_return_t ret = semaphore_create( mach_task_self(), &
sem, SYNC_POLICY_FIFO, start_cnt_ );
101 int ret = sem_destroy( &
sem );
106 while( sem_wait( &
sem )!=0 )
114 int ret = sem_init( &
sem, 0, start_cnt_ );
123 #if !__TBB_USE_SRWLOCK
132 void P() { WaitForSingleObjectEx(
my_sem, INFINITE, FALSE ); }
134 void V() { SetEvent(
my_sem ); }
140 union srwl_or_handle {
146 class binary_semaphore : no_copy {
161 class binary_semaphore : no_copy {
166 kern_return_t ret = semaphore_create( mach_task_self(), &
my_sem, SYNC_POLICY_FIFO, 0 );
171 kern_return_t ret = semaphore_destroy( mach_task_self(),
my_sem );
178 ret = semaphore_wait(
my_sem );
179 }
while( ret==KERN_ABORTED );
180 __TBB_ASSERT( ret==KERN_SUCCESS,
"semaphore_wait() failed" );
183 void V() { semaphore_signal(
my_sem ); }
190 class binary_semaphore : no_copy {
201 if( (
s =
my_sem.compare_and_swap( 1, 0 ))!=0 ) {
203 s =
my_sem.fetch_and_store( 2 );
206 s =
my_sem.fetch_and_store( 2 );
213 if(
my_sem.fetch_and_store( 0 )==2 )
214 futex_wakeup_one( &
my_sem );
226 int ret = sem_init( &
my_sem, 0, 0 );
231 int ret = sem_destroy( &
my_sem );
236 while( sem_wait( &
my_sem )!=0 )