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 )
 
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
 
Edsger Dijkstra's counting semaphore.
 
semaphore(int start_cnt_=0)
ctor
 
void init_semaphore(int start_cnt_)
 
#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
 
Base class for types that should not be copied or assigned.
 
void const char const char int ITT_FORMAT __itt_group_sync s
 
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
 
uint32_t sem_count_t
for performance reasons, we want specialized binary_semaphore
 
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