Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
macos_common.h File Reference
#include <sched.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <libkern/OSAtomic.h>
Include dependency graph for macos_common.h:

Go to the source code of this file.

Macros

#define __TBB_Yield()   sched_yield()
 
#define __TBB_HardwareConcurrency()   __TBB_macos_available_cpu()
 
#define __TBB_UnknownArchitecture   1
 
#define __TBB_machine_cmpswp8   __TBB_machine_cmpswp8_OsX
 
#define __TBB_WORDSIZE   __SIZEOF_POINTER__
 
#define __TBB_ENDIANNESS   __TBB_ENDIAN_UNSUPPORTED
 
#define __TBB_control_consistency_helper()   OSMemoryBarrier()
 
#define __TBB_acquire_consistency_helper()   OSMemoryBarrier()
 
#define __TBB_release_consistency_helper()   OSMemoryBarrier()
 
#define __TBB_full_memory_fence()   OSMemoryBarrier()
 
#define __TBB_USE_GENERIC_PART_WORD_CAS   1
 
#define __TBB_USE_GENERIC_PART_WORD_FETCH_ADD   1
 
#define __TBB_USE_GENERIC_FETCH_STORE   1
 
#define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE   1
 
#define __TBB_USE_GENERIC_RELAXED_LOAD_STORE   1
 
#define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE   1
 

Functions

static int __TBB_macos_available_cpu ()
 
static int64_t __TBB_machine_cmpswp8_OsX (volatile void *ptr, int64_t value, int64_t comparand)
 
static int32_t __TBB_machine_cmpswp4 (volatile void *ptr, int32_t value, int32_t comparand)
 
static int32_t __TBB_machine_fetchadd4 (volatile void *ptr, int32_t addend)
 
static int64_t __TBB_machine_fetchadd8 (volatile void *ptr, int64_t addend)
 

Macro Definition Documentation

◆ __TBB_acquire_consistency_helper

#define __TBB_acquire_consistency_helper ( )    OSMemoryBarrier()

Definition at line 96 of file macos_common.h.

◆ __TBB_control_consistency_helper

#define __TBB_control_consistency_helper ( )    OSMemoryBarrier()

As this generic implementation has absolutely no information about underlying hardware, its performance most likely will be sub-optimal because of full memory fence usages where a more lightweight synchronization means (or none at all) could suffice. Thus if you use this header to enable TBB on a new platform, consider forking it and relaxing below helpers as appropriate.

Definition at line 95 of file macos_common.h.

◆ __TBB_ENDIANNESS

#define __TBB_ENDIANNESS   __TBB_ENDIAN_UNSUPPORTED

Definition at line 87 of file macos_common.h.

◆ __TBB_full_memory_fence

#define __TBB_full_memory_fence ( )    OSMemoryBarrier()

Definition at line 98 of file macos_common.h.

◆ __TBB_HardwareConcurrency

#define __TBB_HardwareConcurrency ( )    __TBB_macos_available_cpu()

Definition at line 43 of file macos_common.h.

◆ __TBB_machine_cmpswp8

#define __TBB_machine_cmpswp8   __TBB_machine_cmpswp8_OsX

Definition at line 70 of file macos_common.h.

◆ __TBB_release_consistency_helper

#define __TBB_release_consistency_helper ( )    OSMemoryBarrier()

Definition at line 97 of file macos_common.h.

◆ __TBB_UnknownArchitecture

#define __TBB_UnknownArchitecture   1

Definition at line 48 of file macos_common.h.

◆ __TBB_USE_GENERIC_FETCH_STORE

#define __TBB_USE_GENERIC_FETCH_STORE   1

Definition at line 125 of file macos_common.h.

◆ __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE

#define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE   1

Definition at line 126 of file macos_common.h.

◆ __TBB_USE_GENERIC_PART_WORD_CAS

#define __TBB_USE_GENERIC_PART_WORD_CAS   1

Definition at line 123 of file macos_common.h.

◆ __TBB_USE_GENERIC_PART_WORD_FETCH_ADD

#define __TBB_USE_GENERIC_PART_WORD_FETCH_ADD   1

Definition at line 124 of file macos_common.h.

◆ __TBB_USE_GENERIC_RELAXED_LOAD_STORE

#define __TBB_USE_GENERIC_RELAXED_LOAD_STORE   1

Definition at line 127 of file macos_common.h.

◆ __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE

#define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE   1

Definition at line 131 of file macos_common.h.

◆ __TBB_WORDSIZE

#define __TBB_WORDSIZE   __SIZEOF_POINTER__

Definition at line 77 of file macos_common.h.

◆ __TBB_Yield

#define __TBB_Yield ( )    sched_yield()

Definition at line 28 of file macos_common.h.

Function Documentation

◆ __TBB_machine_cmpswp4()

static int32_t __TBB_machine_cmpswp4 ( volatile void ptr,
int32_t  value,
int32_t  comparand 
)
inlinestatic

Definition at line 100 of file macos_common.h.

101 {
102  __TBB_ASSERT( tbb::internal::is_aligned(ptr,4), "address not properly aligned for macOS atomics");
103  int32_t* address = (int32_t*)ptr;
104  while( !OSAtomicCompareAndSwap32Barrier(comparand, value, address) ){
105  int32_t snapshot = *address;
106  if( snapshot!=comparand ) return snapshot;
107  }
108  return comparand;
109 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
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 * address
bool is_aligned(T *pointer, uintptr_t alignment)
A function to check if passed in pointer is aligned on a specific border.
Definition: tbb_stddef.h:353
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 void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value

References __TBB_ASSERT, address, tbb::internal::is_aligned(), and value.

Here is the call graph for this function:

◆ __TBB_machine_cmpswp8_OsX()

static int64_t __TBB_machine_cmpswp8_OsX ( volatile void ptr,
int64_t  value,
int64_t  comparand 
)
inlinestatic

Definition at line 55 of file macos_common.h.

56 {
57  __TBB_ASSERT( tbb::internal::is_aligned(ptr,8), "address not properly aligned for macOS* atomics");
58  int64_t* address = (int64_t*)ptr;
59  while( !OSAtomicCompareAndSwap64Barrier(comparand, value, address) ){
60 #if __TBB_WORDSIZE==8
61  int64_t snapshot = *address;
62 #else
63  int64_t snapshot = OSAtomicAdd64( 0, address );
64 #endif
65  if( snapshot!=comparand ) return snapshot;
66  }
67  return comparand;
68 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
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 * address
bool is_aligned(T *pointer, uintptr_t alignment)
A function to check if passed in pointer is aligned on a specific border.
Definition: tbb_stddef.h:353
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 void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value

References __TBB_ASSERT, address, tbb::internal::is_aligned(), and value.

Here is the call graph for this function:

◆ __TBB_machine_fetchadd4()

static int32_t __TBB_machine_fetchadd4 ( volatile void ptr,
int32_t  addend 
)
inlinestatic

Definition at line 111 of file macos_common.h.

112 {
113  __TBB_ASSERT( tbb::internal::is_aligned(ptr,4), "address not properly aligned for macOS atomics");
114  return OSAtomicAdd32Barrier(addend, (int32_t*)ptr) - addend;
115 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
bool is_aligned(T *pointer, uintptr_t alignment)
A function to check if passed in pointer is aligned on a specific border.
Definition: tbb_stddef.h:353

References __TBB_ASSERT, and tbb::internal::is_aligned().

Here is the call graph for this function:

◆ __TBB_machine_fetchadd8()

static int64_t __TBB_machine_fetchadd8 ( volatile void ptr,
int64_t  addend 
)
inlinestatic

Definition at line 117 of file macos_common.h.

118 {
119  __TBB_ASSERT( tbb::internal::is_aligned(ptr,8), "address not properly aligned for macOS atomics");
120  return OSAtomicAdd64Barrier(addend, (int64_t*)ptr) - addend;
121 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
bool is_aligned(T *pointer, uintptr_t alignment)
A function to check if passed in pointer is aligned on a specific border.
Definition: tbb_stddef.h:353

References __TBB_ASSERT, and tbb::internal::is_aligned().

Here is the call graph for this function:

◆ __TBB_macos_available_cpu()

static int __TBB_macos_available_cpu ( )
inlinestatic

Definition at line 35 of file macos_common.h.

35  {
36  int name[2] = {CTL_HW, HW_AVAILCPU};
37  int ncpu;
38  size_t size = sizeof(ncpu);
39  sysctl( name, 2, &ncpu, &size, NULL, 0 );
40  return ncpu;
41 }
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 size
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name

References name, and size.


Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.