21 #ifndef __TBB_tbb_semaphore_H 22 #define __TBB_tbb_semaphore_H 30 #include <mach/semaphore.h> 31 #include <mach/task.h> 32 #include <mach/mach_init.h> 33 #include <mach/error.h> 49 class semaphore : no_copy {
50 static const int max_semaphore_cnt = MAXLONG;
57 void P() {WaitForSingleObjectEx(
sem, INFINITE, FALSE );}
59 void V() {ReleaseSemaphore(
sem, 1, NULL );}
63 sem = CreateSemaphoreEx( NULL, LONG(start_cnt_), max_semaphore_cnt, NULL, 0, SEMAPHORE_ALL_ACCESS );
67 class semaphore : no_copy {
74 kern_return_t ret = semaphore_destroy( mach_task_self(),
sem );
81 ret = semaphore_wait(
sem );
82 }
while( ret==KERN_ABORTED );
83 __TBB_ASSERT( ret==KERN_SUCCESS,
"semaphore_wait() failed" );
86 void V() { semaphore_signal(
sem ); }
90 kern_return_t ret = semaphore_create( mach_task_self(), &
sem, SYNC_POLICY_FIFO, start_cnt_ );
104 int ret = sem_destroy( &
sem );
109 while( sem_wait( &
sem )!=0 )
117 int ret = sem_init( &
sem, 0, start_cnt_ );
126 #if !__TBB_USE_SRWLOCK 135 void P() { WaitForSingleObjectEx(
my_sem, INFINITE, FALSE ); }
137 void V() { SetEvent(
my_sem ); }
143 union srwl_or_handle {
149 class binary_semaphore : no_copy {
164 class binary_semaphore : no_copy {
169 kern_return_t ret = semaphore_create( mach_task_self(), &
my_sem, SYNC_POLICY_FIFO, 0 );
174 kern_return_t ret = semaphore_destroy( mach_task_self(),
my_sem );
181 ret = semaphore_wait(
my_sem );
182 }
while( ret==KERN_ABORTED );
183 __TBB_ASSERT( ret==KERN_SUCCESS,
"semaphore_wait() failed" );
186 void V() { semaphore_signal(
my_sem ); }
193 class binary_semaphore : no_copy {
204 if( (
s =
my_sem.compare_and_swap( 1, 0 ))!=0 ) {
206 s =
my_sem.fetch_and_store( 2 );
209 s =
my_sem.fetch_and_store( 2 );
216 if(
my_sem.fetch_and_store( 0 )==2 )
217 futex_wakeup_one( &
my_sem );
229 int ret = sem_init( &
my_sem, 0, 0 );
234 int ret = sem_destroy( &
my_sem );
239 while( sem_wait( &
my_sem )!=0 )
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
void const char const char int ITT_FORMAT __itt_group_sync s
uint32_t sem_count_t
for performance reasons, we want specialized binary_semaphore
binary_semaphore for concurrent monitor
Base class for types that should not be copied or assigned.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
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.
void init_semaphore(int start_cnt_)
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
semaphore(int start_cnt_=0)
ctor