21 #ifndef __TBB_tbb_semaphore_H 22 #define __TBB_tbb_semaphore_H 31 #include <mach/semaphore.h> 32 #include <mach/task.h> 33 #include <mach/mach_init.h> 34 #include <mach/error.h> 50 class semaphore : no_copy {
51 static const int max_semaphore_cnt = MAXLONG;
58 void P() {WaitForSingleObjectEx(
sem, INFINITE, FALSE );}
60 void V() {ReleaseSemaphore(
sem, 1, NULL );}
64 sem = CreateSemaphoreEx( NULL, LONG(start_cnt_), max_semaphore_cnt, NULL, 0, SEMAPHORE_ALL_ACCESS );
68 class semaphore : no_copy {
75 kern_return_t ret = semaphore_destroy( mach_task_self(),
sem );
82 ret = semaphore_wait(
sem );
83 }
while( ret==KERN_ABORTED );
84 __TBB_ASSERT( ret==KERN_SUCCESS,
"semaphore_wait() failed" );
87 void V() { semaphore_signal(
sem ); }
91 kern_return_t ret = semaphore_create( mach_task_self(), &
sem, SYNC_POLICY_FIFO, start_cnt_ );
105 int ret = sem_destroy( &
sem );
110 while( sem_wait( &
sem )!=0 )
118 int ret = sem_init( &
sem, 0, start_cnt_ );
127 #if !__TBB_USE_SRWLOCK 136 void P() { WaitForSingleObjectEx(
my_sem, INFINITE, FALSE ); }
138 void V() { SetEvent(
my_sem ); }
144 union srwl_or_handle {
150 class binary_semaphore : no_copy {
165 class binary_semaphore : no_copy {
170 kern_return_t ret = semaphore_create( mach_task_self(), &
my_sem, SYNC_POLICY_FIFO, 0 );
175 kern_return_t ret = semaphore_destroy( mach_task_self(),
my_sem );
182 ret = semaphore_wait(
my_sem );
183 }
while( ret==KERN_ABORTED );
184 __TBB_ASSERT( ret==KERN_SUCCESS,
"semaphore_wait() failed" );
187 void V() { semaphore_signal(
my_sem ); }
194 class binary_semaphore : no_copy {
205 if( (
s =
my_sem.compare_and_swap( 1, 0 ))!=0 ) {
207 s =
my_sem.fetch_and_store( 2 );
210 s =
my_sem.fetch_and_store( 2 );
217 if(
my_sem.fetch_and_store( 0 )==2 )
218 futex_wakeup_one( &
my_sem );
230 int ret = sem_init( &
my_sem, 0, 0 );
235 int ret = sem_destroy( &
my_sem );
240 while( sem_wait( &
my_sem )!=0 )
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function h
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Base class for types that should not be copied or assigned.
semaphore(int start_cnt_=0)
ctor
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
binary_semaphore for concurrent monitor
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void * lock
uint32_t sem_count_t
for performance reasons, we want specialized binary_semaphore
void init_semaphore(int start_cnt_)
void const char const char int ITT_FORMAT __itt_group_sync s
Edsger Dijkstra's counting semaphore.