21 #if !defined(__TBB_machine_H) || defined(__TBB_machine_macos_common_H) 22 #error Do not #include this internal file directly; use public TBB headers instead. 25 #define __TBB_machine_macos_common_H 28 #define __TBB_Yield() sched_yield() 32 #include <sys/types.h> 33 #include <sys/sysctl.h> 35 static inline int __TBB_macos_available_cpu() {
36 int name[2] = {CTL_HW, HW_AVAILCPU};
38 size_t size =
sizeof(ncpu);
39 sysctl( name, 2, &ncpu, &size, NULL, 0 );
43 #define __TBB_HardwareConcurrency() __TBB_macos_available_cpu() 45 #ifndef __TBB_full_memory_fence 48 #define __TBB_UnknownArchitecture 1 51 #if __TBB_UnknownArchitecture 53 #include <libkern/OSAtomic.h> 55 static inline int64_t __TBB_machine_cmpswp8_OsX(
volatile void *ptr, int64_t value, int64_t comparand)
57 __TBB_ASSERT( tbb::internal::is_aligned(ptr,8),
"address not properly aligned for OS X* atomics");
58 int64_t* address = (int64_t*)ptr;
59 while( !OSAtomicCompareAndSwap64Barrier(comparand, value, address) ){
61 int64_t snapshot = *address;
63 int64_t snapshot = OSAtomicAdd64( 0, address );
65 if( snapshot!=comparand )
return snapshot;
70 #define __TBB_machine_cmpswp8 __TBB_machine_cmpswp8_OsX 74 #if __TBB_UnknownArchitecture 76 #ifndef __TBB_WORDSIZE 77 #define __TBB_WORDSIZE __SIZEOF_POINTER__ 80 #ifdef __TBB_ENDIANNESS 83 #define __TBB_ENDIANNESS __TBB_ENDIAN_BIG 84 #elif __LITTLE_ENDIAN__ 85 #define __TBB_ENDIANNESS __TBB_ENDIAN_LITTLE 87 #define __TBB_ENDIANNESS __TBB_ENDIAN_UNSUPPORTED 95 #define __TBB_control_consistency_helper() OSMemoryBarrier() 96 #define __TBB_acquire_consistency_helper() OSMemoryBarrier() 97 #define __TBB_release_consistency_helper() OSMemoryBarrier() 98 #define __TBB_full_memory_fence() OSMemoryBarrier() 100 static inline int32_t __TBB_machine_cmpswp4(
volatile void *ptr, int32_t value, int32_t comparand)
102 __TBB_ASSERT( tbb::internal::is_aligned(ptr,4),
"address not properly aligned for OS X* 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;
111 static inline int32_t __TBB_machine_fetchadd4(
volatile void *ptr, int32_t addend)
113 __TBB_ASSERT( tbb::internal::is_aligned(ptr,4),
"address not properly aligned for OS X* atomics");
114 return OSAtomicAdd32Barrier(addend, (int32_t*)ptr) - addend;
117 static inline int64_t __TBB_machine_fetchadd8(
volatile void *ptr, int64_t addend)
119 __TBB_ASSERT( tbb::internal::is_aligned(ptr,8),
"address not properly aligned for OS X* atomics");
120 return OSAtomicAdd64Barrier(addend, (int64_t*)ptr) - addend;
123 #define __TBB_USE_GENERIC_PART_WORD_CAS 1 124 #define __TBB_USE_GENERIC_PART_WORD_FETCH_ADD 1 125 #define __TBB_USE_GENERIC_FETCH_STORE 1 126 #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1 127 #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1 128 #if __TBB_WORDSIZE == 4 129 #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1 131 #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1