Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
macos_common.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2020 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #if !defined(__TBB_machine_H) || defined(__TBB_machine_macos_common_H)
18 #error Do not #include this internal file directly; use public TBB headers instead.
19 #endif
20 
21 #define __TBB_machine_macos_common_H
22 
23 #include <sched.h>
24 #define __TBB_Yield() sched_yield()
25 
26 // __TBB_HardwareConcurrency
27 
28 #include <sys/types.h>
29 #include <sys/sysctl.h>
30 
31 static inline int __TBB_macos_available_cpu() {
32  int name[2] = {CTL_HW, HW_AVAILCPU};
33  int ncpu;
34  size_t size = sizeof(ncpu);
35  sysctl( name, 2, &ncpu, &size, NULL, 0 );
36  return ncpu;
37 }
38 
39 #define __TBB_HardwareConcurrency() __TBB_macos_available_cpu()
40 
41 #ifndef __TBB_full_memory_fence
42  // TBB has not recognized the architecture (none of the architecture abstraction
43  // headers was included).
44  #define __TBB_UnknownArchitecture 1
45 #endif
46 
47 #if __TBB_UnknownArchitecture
48 // Implementation of atomic operations based on OS provided primitives
49 #include <libkern/OSAtomic.h>
50 
51 static inline int64_t __TBB_machine_cmpswp8_OsX(volatile void *ptr, int64_t value, int64_t comparand)
52 {
53  __TBB_ASSERT( tbb::internal::is_aligned(ptr,8), "address not properly aligned for macOS* atomics");
54  int64_t* address = (int64_t*)ptr;
55  while( !OSAtomicCompareAndSwap64Barrier(comparand, value, address) ){
56 #if __TBB_WORDSIZE==8
57  int64_t snapshot = *address;
58 #else
59  int64_t snapshot = OSAtomicAdd64( 0, address );
60 #endif
61  if( snapshot!=comparand ) return snapshot;
62  }
63  return comparand;
64 }
65 
66 #define __TBB_machine_cmpswp8 __TBB_machine_cmpswp8_OsX
67 
68 #endif /* __TBB_UnknownArchitecture */
69 
70 #if __TBB_UnknownArchitecture
71 
72 #ifndef __TBB_WORDSIZE
73 #define __TBB_WORDSIZE __SIZEOF_POINTER__
74 #endif
75 
76 #ifdef __TBB_ENDIANNESS
77  // Already determined based on hardware architecture.
78 #elif __BIG_ENDIAN__
79  #define __TBB_ENDIANNESS __TBB_ENDIAN_BIG
80 #elif __LITTLE_ENDIAN__
81  #define __TBB_ENDIANNESS __TBB_ENDIAN_LITTLE
82 #else
83  #define __TBB_ENDIANNESS __TBB_ENDIAN_UNSUPPORTED
84 #endif
85 
91 #define __TBB_control_consistency_helper() OSMemoryBarrier()
92 #define __TBB_acquire_consistency_helper() OSMemoryBarrier()
93 #define __TBB_release_consistency_helper() OSMemoryBarrier()
94 #define __TBB_full_memory_fence() OSMemoryBarrier()
95 
96 static inline int32_t __TBB_machine_cmpswp4(volatile void *ptr, int32_t value, int32_t comparand)
97 {
98  __TBB_ASSERT( tbb::internal::is_aligned(ptr,4), "address not properly aligned for macOS atomics");
99  int32_t* address = (int32_t*)ptr;
100  while( !OSAtomicCompareAndSwap32Barrier(comparand, value, address) ){
101  int32_t snapshot = *address;
102  if( snapshot!=comparand ) return snapshot;
103  }
104  return comparand;
105 }
106 
107 static inline int32_t __TBB_machine_fetchadd4(volatile void *ptr, int32_t addend)
108 {
109  __TBB_ASSERT( tbb::internal::is_aligned(ptr,4), "address not properly aligned for macOS atomics");
110  return OSAtomicAdd32Barrier(addend, (int32_t*)ptr) - addend;
111 }
112 
113 static inline int64_t __TBB_machine_fetchadd8(volatile void *ptr, int64_t addend)
114 {
115  __TBB_ASSERT( tbb::internal::is_aligned(ptr,8), "address not properly aligned for macOS atomics");
116  return OSAtomicAdd64Barrier(addend, (int64_t*)ptr) - addend;
117 }
118 
119 #define __TBB_USE_GENERIC_PART_WORD_CAS 1
120 #define __TBB_USE_GENERIC_PART_WORD_FETCH_ADD 1
121 #define __TBB_USE_GENERIC_FETCH_STORE 1
122 #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1
123 #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1
124 #if __TBB_WORDSIZE == 4
125  #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1
126 #endif
127 #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1
128 
129 #endif /* __TBB_UnknownArchitecture */
static int __TBB_macos_available_cpu()
Definition: macos_common.h:31
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
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:370
static int64_t __TBB_machine_cmpswp8_OsX(volatile void *ptr, int64_t value, int64_t comparand)
Definition: macos_common.h:51
static int64_t __TBB_machine_fetchadd8(volatile void *ptr, int64_t addend)
Definition: macos_common.h:113
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
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
static int32_t __TBB_machine_fetchadd4(volatile void *ptr, int32_t addend)
Definition: macos_common.h:107
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
static int32_t __TBB_machine_cmpswp4(volatile void *ptr, int32_t value, int32_t comparand)
Definition: macos_common.h:96
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

Copyright © 2005-2020 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.