| 1 | /* | 
|---|
| 2 | Copyright (c) 2005-2019 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 | #ifndef __TBB_tbb_stddef_H | 
|---|
| 18 | #define __TBB_tbb_stddef_H | 
|---|
| 19 |  | 
|---|
| 20 | // Marketing-driven product version | 
|---|
| 21 | #define TBB_VERSION_MAJOR 2019 | 
|---|
| 22 | #define TBB_VERSION_MINOR 0 | 
|---|
| 23 |  | 
|---|
| 24 | // Engineering-focused interface version | 
|---|
| 25 | #define TBB_INTERFACE_VERSION 11008 | 
|---|
| 26 | #define TBB_INTERFACE_VERSION_MAJOR TBB_INTERFACE_VERSION/1000 | 
|---|
| 27 |  | 
|---|
| 28 | // The oldest major interface version still supported | 
|---|
| 29 | // To be used in SONAME, manifests, etc. | 
|---|
| 30 | #define TBB_COMPATIBLE_INTERFACE_VERSION 2 | 
|---|
| 31 |  | 
|---|
| 32 | #define __TBB_STRING_AUX(x) #x | 
|---|
| 33 | #define __TBB_STRING(x) __TBB_STRING_AUX(x) | 
|---|
| 34 |  | 
|---|
| 35 | // We do not need defines below for resource processing on windows | 
|---|
| 36 | #if !defined RC_INVOKED | 
|---|
| 37 |  | 
|---|
| 38 | // Define groups for Doxygen documentation | 
|---|
| 39 | /** | 
|---|
| 40 | * @defgroup algorithms         Algorithms | 
|---|
| 41 | * @defgroup containers         Containers | 
|---|
| 42 | * @defgroup memory_allocation  Memory Allocation | 
|---|
| 43 | * @defgroup synchronization    Synchronization | 
|---|
| 44 | * @defgroup timing             Timing | 
|---|
| 45 | * @defgroup task_scheduling    Task Scheduling | 
|---|
| 46 | */ | 
|---|
| 47 |  | 
|---|
| 48 | // Simple text that is displayed on the main page of Doxygen documentation. | 
|---|
| 49 | /** | 
|---|
| 50 | * \mainpage Main Page | 
|---|
| 51 | * | 
|---|
| 52 | * Click the tabs above for information about the | 
|---|
| 53 | * - <a href="./modules.html">Modules</a> (groups of functionality) implemented by the library | 
|---|
| 54 | * - <a href="./annotated.html">Classes</a> provided by the library | 
|---|
| 55 | * - <a href="./files.html">Files</a> constituting the library. | 
|---|
| 56 | * . | 
|---|
| 57 | * Please note that significant part of TBB functionality is implemented in the form of | 
|---|
| 58 | * template functions, descriptions of which are not accessible on the <a href="./annotated.html">Classes</a> | 
|---|
| 59 | * tab. Use <a href="./modules.html">Modules</a> or <a href="./namespacemembers.html">Namespace/Namespace Members</a> | 
|---|
| 60 | * tabs to find them. | 
|---|
| 61 | * | 
|---|
| 62 | * Additional pieces of information can be found here | 
|---|
| 63 | * - \subpage concepts | 
|---|
| 64 | * . | 
|---|
| 65 | */ | 
|---|
| 66 |  | 
|---|
| 67 | /** \page concepts TBB concepts | 
|---|
| 68 |  | 
|---|
| 69 | A concept is a set of requirements to a type, which are necessary and sufficient | 
|---|
| 70 | for the type to model a particular behavior or a set of behaviors. Some concepts | 
|---|
| 71 | are specific to a particular algorithm (e.g. algorithm body), while other ones | 
|---|
| 72 | are common to several algorithms (e.g. range concept). | 
|---|
| 73 |  | 
|---|
| 74 | All TBB algorithms make use of different classes implementing various concepts. | 
|---|
| 75 | Implementation classes are supplied by the user as type arguments of template | 
|---|
| 76 | parameters and/or as objects passed as function call arguments. The library | 
|---|
| 77 | provides predefined  implementations of some concepts (e.g. several kinds of | 
|---|
| 78 | \ref range_req "ranges"), while other ones must always be implemented by the user. | 
|---|
| 79 |  | 
|---|
| 80 | TBB defines a set of minimal requirements each concept must conform to. Here is | 
|---|
| 81 | the list of different concepts hyperlinked to the corresponding requirements specifications: | 
|---|
| 82 | - \subpage range_req | 
|---|
| 83 | - \subpage parallel_do_body_req | 
|---|
| 84 | - \subpage parallel_for_body_req | 
|---|
| 85 | - \subpage parallel_reduce_body_req | 
|---|
| 86 | - \subpage parallel_scan_body_req | 
|---|
| 87 | - \subpage parallel_sort_iter_req | 
|---|
| 88 | **/ | 
|---|
| 89 |  | 
|---|
| 90 | // tbb_config.h should be included the first since it contains macro definitions used in other headers | 
|---|
| 91 | #include "tbb_config.h" | 
|---|
| 92 |  | 
|---|
| 93 | #if _MSC_VER >=1400 | 
|---|
| 94 | #define __TBB_EXPORTED_FUNC   __cdecl | 
|---|
| 95 | #define __TBB_EXPORTED_METHOD __thiscall | 
|---|
| 96 | #else | 
|---|
| 97 | #define __TBB_EXPORTED_FUNC | 
|---|
| 98 | #define __TBB_EXPORTED_METHOD | 
|---|
| 99 | #endif | 
|---|
| 100 |  | 
|---|
| 101 | #if __INTEL_COMPILER || _MSC_VER | 
|---|
| 102 | #define __TBB_NOINLINE(decl) __declspec(noinline) decl | 
|---|
| 103 | #elif __GNUC__ | 
|---|
| 104 | #define __TBB_NOINLINE(decl) decl __attribute__ ((noinline)) | 
|---|
| 105 | #else | 
|---|
| 106 | #define __TBB_NOINLINE(decl) decl | 
|---|
| 107 | #endif | 
|---|
| 108 |  | 
|---|
| 109 | #if __TBB_NOEXCEPT_PRESENT | 
|---|
| 110 | #define __TBB_NOEXCEPT(expression) noexcept(expression) | 
|---|
| 111 | #else | 
|---|
| 112 | #define __TBB_NOEXCEPT(expression) | 
|---|
| 113 | #endif | 
|---|
| 114 |  | 
|---|
| 115 | #include <cstddef>      /* Need size_t and ptrdiff_t */ | 
|---|
| 116 |  | 
|---|
| 117 | #if _MSC_VER | 
|---|
| 118 | #define __TBB_tbb_windef_H | 
|---|
| 119 | #include "internal/_tbb_windef.h" | 
|---|
| 120 | #undef __TBB_tbb_windef_H | 
|---|
| 121 | #endif | 
|---|
| 122 | #if !defined(_MSC_VER) || _MSC_VER>=1600 | 
|---|
| 123 | #include <stdint.h> | 
|---|
| 124 | #endif | 
|---|
| 125 |  | 
|---|
| 126 | //! Type for an assertion handler | 
|---|
| 127 | typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char *  ); | 
|---|
| 128 |  | 
|---|
| 129 | #if __TBBMALLOC_BUILD | 
|---|
| 130 | namespace rml { namespace internal { | 
|---|
| 131 | #define __TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : rml::internal::assertion_failure(__FILE__,__LINE__,#predicate,message)) | 
|---|
| 132 | #else | 
|---|
| 133 | namespace tbb { | 
|---|
| 134 | #define __TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : tbb::assertion_failure(__FILE__,__LINE__,#predicate,message)) | 
|---|
| 135 | #endif | 
|---|
| 136 |  | 
|---|
| 137 | //! Set assertion handler and return previous value of it. | 
|---|
| 138 | assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler( assertion_handler_type new_handler ); | 
|---|
| 139 |  | 
|---|
| 140 | //! Process an assertion failure. | 
|---|
| 141 | /** Normally called from __TBB_ASSERT macro. | 
|---|
| 142 | If assertion handler is null, print message for assertion failure and abort. | 
|---|
| 143 | Otherwise call the assertion handler. */ | 
|---|
| 144 | void __TBB_EXPORTED_FUNC assertion_failure( const char* filename, int line, const char* expression, const char*  ); | 
|---|
| 145 |  | 
|---|
| 146 | #if __TBBMALLOC_BUILD | 
|---|
| 147 | }}  // namespace rml::internal | 
|---|
| 148 | #else | 
|---|
| 149 | } // namespace tbb | 
|---|
| 150 | #endif | 
|---|
| 151 |  | 
|---|
| 152 | #if TBB_USE_ASSERT | 
|---|
| 153 |  | 
|---|
| 154 | //! Assert that predicate is true. | 
|---|
| 155 | /** If predicate is false, print assertion failure message. | 
|---|
| 156 | If the comment argument is not NULL, it is printed as part of the failure message. | 
|---|
| 157 | The comment argument has no other effect. */ | 
|---|
| 158 | #define __TBB_ASSERT(predicate,message) __TBB_ASSERT_RELEASE(predicate,message) | 
|---|
| 159 |  | 
|---|
| 160 | #define __TBB_ASSERT_EX __TBB_ASSERT | 
|---|
| 161 |  | 
|---|
| 162 | #else /* !TBB_USE_ASSERT */ | 
|---|
| 163 |  | 
|---|
| 164 | //! No-op version of __TBB_ASSERT. | 
|---|
| 165 | #define __TBB_ASSERT(predicate,comment) ((void)0) | 
|---|
| 166 | //! "Extended" version is useful to suppress warnings if a variable is only used with an assert | 
|---|
| 167 | #define __TBB_ASSERT_EX(predicate,comment) ((void)(1 && (predicate))) | 
|---|
| 168 |  | 
|---|
| 169 | #endif /* !TBB_USE_ASSERT */ | 
|---|
| 170 |  | 
|---|
| 171 | //! The namespace tbb contains all components of the library. | 
|---|
| 172 | namespace tbb { | 
|---|
| 173 |  | 
|---|
| 174 | namespace internal { | 
|---|
| 175 | #if _MSC_VER && _MSC_VER<1600 | 
|---|
| 176 | typedef __int8 int8_t; | 
|---|
| 177 | typedef __int16 int16_t; | 
|---|
| 178 | typedef __int32 int32_t; | 
|---|
| 179 | typedef __int64 int64_t; | 
|---|
| 180 | typedef unsigned __int8 uint8_t; | 
|---|
| 181 | typedef unsigned __int16 uint16_t; | 
|---|
| 182 | typedef unsigned __int32 uint32_t; | 
|---|
| 183 | typedef unsigned __int64 uint64_t; | 
|---|
| 184 | #else /* Posix */ | 
|---|
| 185 | using ::int8_t; | 
|---|
| 186 | using ::int16_t; | 
|---|
| 187 | using ::int32_t; | 
|---|
| 188 | using ::int64_t; | 
|---|
| 189 | using ::uint8_t; | 
|---|
| 190 | using ::uint16_t; | 
|---|
| 191 | using ::uint32_t; | 
|---|
| 192 | using ::uint64_t; | 
|---|
| 193 | #endif /* Posix */ | 
|---|
| 194 | } // namespace internal | 
|---|
| 195 |  | 
|---|
| 196 | using std::size_t; | 
|---|
| 197 | using std::ptrdiff_t; | 
|---|
| 198 |  | 
|---|
| 199 | //! The function returns the interface version of the TBB shared library being used. | 
|---|
| 200 | /** | 
|---|
| 201 | * The version it returns is determined at runtime, not at compile/link time. | 
|---|
| 202 | * So it can be different than the value of TBB_INTERFACE_VERSION obtained at compile time. | 
|---|
| 203 | */ | 
|---|
| 204 | extern "C"int __TBB_EXPORTED_FUNC TBB_runtime_interface_version(); | 
|---|
| 205 |  | 
|---|
| 206 | /** | 
|---|
| 207 | * @cond INTERNAL | 
|---|
| 208 | * @brief Identifiers declared inside namespace internal should never be used directly by client code. | 
|---|
| 209 | */ | 
|---|
| 210 | namespace internal { | 
|---|
| 211 |  | 
|---|
| 212 | //! Compile-time constant that is upper bound on cache line/sector size. | 
|---|
| 213 | /** It should be used only in situations where having a compile-time upper | 
|---|
| 214 | bound is more useful than a run-time exact answer. | 
|---|
| 215 | @ingroup memory_allocation */ | 
|---|
| 216 | const size_t NFS_MaxLineSize = 128; | 
|---|
| 217 |  | 
|---|
| 218 | /** Label for data that may be accessed from different threads, and that may eventually become wrapped | 
|---|
| 219 | in a formal atomic type. | 
|---|
| 220 |  | 
|---|
| 221 | Note that no problems have yet been observed relating to the definition currently being empty, | 
|---|
| 222 | even if at least "volatile" would seem to be in order to avoid data sometimes temporarily hiding | 
|---|
| 223 | in a register (although "volatile" as a "poor man's atomic" lacks several other features of a proper | 
|---|
| 224 | atomic, some of which are now provided instead through specialized functions). | 
|---|
| 225 |  | 
|---|
| 226 | Note that usage is intentionally compatible with a definition as qualifier "volatile", | 
|---|
| 227 | both as a way to have the compiler help enforce use of the label and to quickly rule out | 
|---|
| 228 | one potential issue. | 
|---|
| 229 |  | 
|---|
| 230 | Note however that, with some architecture/compiler combinations, e.g. on IA-64 architecture, "volatile" | 
|---|
| 231 | also has non-portable memory semantics that are needlessly expensive for "relaxed" operations. | 
|---|
| 232 |  | 
|---|
| 233 | Note that this must only be applied to data that will not change bit patterns when cast to/from | 
|---|
| 234 | an integral type of the same length; tbb::atomic must be used instead for, e.g., floating-point types. | 
|---|
| 235 |  | 
|---|
| 236 | TODO: apply wherever relevant **/ | 
|---|
| 237 | #define __TBB_atomic // intentionally empty, see above | 
|---|
| 238 |  | 
|---|
| 239 | #if __TBB_OVERRIDE_PRESENT | 
|---|
| 240 | #define __TBB_override override | 
|---|
| 241 | #else | 
|---|
| 242 | #define __TBB_override // formal comment only | 
|---|
| 243 | #endif | 
|---|
| 244 |  | 
|---|
| 245 | #if __TBB_CPP17_FALLTHROUGH_PRESENT | 
|---|
| 246 | #define __TBB_fallthrough [[fallthrough]] | 
|---|
| 247 | #elif __TBB_FALLTHROUGH_PRESENT | 
|---|
| 248 | #define __TBB_fallthrough __attribute__ ((fallthrough)) | 
|---|
| 249 | #else | 
|---|
| 250 | #define __TBB_fallthrough | 
|---|
| 251 | #endif | 
|---|
| 252 |  | 
|---|
| 253 | template<class T, size_t S, size_t R> | 
|---|
| 254 | struct padded_base : T { | 
|---|
| 255 | char pad[S - R]; | 
|---|
| 256 | }; | 
|---|
| 257 | template<class T, size_t S> struct padded_base<T, S, 0> : T {}; | 
|---|
| 258 |  | 
|---|
| 259 | //! Pads type T to fill out to a multiple of cache line size. | 
|---|
| 260 | template<class T, size_t S = NFS_MaxLineSize> | 
|---|
| 261 | struct padded : padded_base<T, S, sizeof(T) % S> {}; | 
|---|
| 262 |  | 
|---|
| 263 | //! Extended variant of the standard offsetof macro | 
|---|
| 264 | /** The standard offsetof macro is not sufficient for TBB as it can be used for | 
|---|
| 265 | POD-types only. The constant 0x1000 (not NULL) is necessary to appease GCC. **/ | 
|---|
| 266 | #define __TBB_offsetof(class_name, member_name) \ | 
|---|
| 267 | ((ptrdiff_t)&(reinterpret_cast<class_name*>(0x1000)->member_name) - 0x1000) | 
|---|
| 268 |  | 
|---|
| 269 | //! Returns address of the object containing a member with the given name and address | 
|---|
| 270 | #define __TBB_get_object_ref(class_name, member_name, member_addr) \ | 
|---|
| 271 | (*reinterpret_cast<class_name*>((char*)member_addr - __TBB_offsetof(class_name, member_name))) | 
|---|
| 272 |  | 
|---|
| 273 | //! Throws std::runtime_error with what() returning error_code description prefixed with aux_info | 
|---|
| 274 | void __TBB_EXPORTED_FUNC handle_perror( int error_code, const char* aux_info ); | 
|---|
| 275 |  | 
|---|
| 276 | #if TBB_USE_EXCEPTIONS | 
|---|
| 277 | #define __TBB_TRY try | 
|---|
| 278 | #define __TBB_CATCH(e) catch(e) | 
|---|
| 279 | #define __TBB_THROW(e) throw e | 
|---|
| 280 | #define __TBB_RETHROW() throw | 
|---|
| 281 | #else /* !TBB_USE_EXCEPTIONS */ | 
|---|
| 282 | inline bool __TBB_false() { return false; } | 
|---|
| 283 | #define __TBB_TRY | 
|---|
| 284 | #define __TBB_CATCH(e) if ( tbb::internal::__TBB_false() ) | 
|---|
| 285 | #define __TBB_THROW(e) tbb::internal::suppress_unused_warning(e) | 
|---|
| 286 | #define __TBB_RETHROW() ((void)0) | 
|---|
| 287 | #endif /* !TBB_USE_EXCEPTIONS */ | 
|---|
| 288 |  | 
|---|
| 289 | //! Report a runtime warning. | 
|---|
| 290 | void __TBB_EXPORTED_FUNC runtime_warning( const char* format, ... ); | 
|---|
| 291 |  | 
|---|
| 292 | #if TBB_USE_ASSERT | 
|---|
| 293 | static void* const poisoned_ptr = reinterpret_cast<void*>(-1); | 
|---|
| 294 |  | 
|---|
| 295 | //! Set p to invalid pointer value. | 
|---|
| 296 | //  Also works for regular (non-__TBB_atomic) pointers. | 
|---|
| 297 | template<typename T> | 
|---|
| 298 | inline void poison_pointer( T* __TBB_atomic & p ) { p = reinterpret_cast<T*>(poisoned_ptr); } | 
|---|
| 299 |  | 
|---|
| 300 | /** Expected to be used in assertions only, thus no empty form is defined. **/ | 
|---|
| 301 | template<typename T> | 
|---|
| 302 | inline bool is_poisoned( T* p ) { return p == reinterpret_cast<T*>(poisoned_ptr); } | 
|---|
| 303 | #else | 
|---|
| 304 | template<typename T> | 
|---|
| 305 | inline void poison_pointer( T* __TBB_atomic & ) {/*do nothing*/} | 
|---|
| 306 | #endif /* !TBB_USE_ASSERT */ | 
|---|
| 307 |  | 
|---|
| 308 | //! Cast between unrelated pointer types. | 
|---|
| 309 | /** This method should be used sparingly as a last resort for dealing with | 
|---|
| 310 | situations that inherently break strict ISO C++ aliasing rules. */ | 
|---|
| 311 | // T is a pointer type because it will be explicitly provided by the programmer as a template argument; | 
|---|
| 312 | // U is a referent type to enable the compiler to check that "ptr" is a pointer, deducing U in the process. | 
|---|
| 313 | template<typename T, typename U> | 
|---|
| 314 | inline T punned_cast( U* ptr ) { | 
|---|
| 315 | uintptr_t x = reinterpret_cast<uintptr_t>(ptr); | 
|---|
| 316 | return reinterpret_cast<T>(x); | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 | //! Base class for types that should not be assigned. | 
|---|
| 320 | class no_assign { | 
|---|
| 321 | // Deny assignment | 
|---|
| 322 | void operator=( const no_assign& ); | 
|---|
| 323 | public: | 
|---|
| 324 | #if __GNUC__ | 
|---|
| 325 | //! Explicitly define default construction, because otherwise gcc issues gratuitous warning. | 
|---|
| 326 | no_assign() {} | 
|---|
| 327 | #endif /* __GNUC__ */ | 
|---|
| 328 | }; | 
|---|
| 329 |  | 
|---|
| 330 | //! Base class for types that should not be copied or assigned. | 
|---|
| 331 | class no_copy: no_assign { | 
|---|
| 332 | //! Deny copy construction | 
|---|
| 333 | no_copy( const no_copy& ); | 
|---|
| 334 | public: | 
|---|
| 335 | //! Allow default construction | 
|---|
| 336 | no_copy() {} | 
|---|
| 337 | }; | 
|---|
| 338 |  | 
|---|
| 339 | #if TBB_DEPRECATED_MUTEX_COPYING | 
|---|
| 340 | class mutex_copy_deprecated_and_disabled {}; | 
|---|
| 341 | #else | 
|---|
| 342 | // By default various implementations of mutexes are not copy constructible | 
|---|
| 343 | // and not copy assignable. | 
|---|
| 344 | class mutex_copy_deprecated_and_disabled : no_copy {}; | 
|---|
| 345 | #endif | 
|---|
| 346 |  | 
|---|
| 347 | //! A function to check if passed in pointer is aligned on a specific border | 
|---|
| 348 | template<typename T> | 
|---|
| 349 | inline bool is_aligned(T* pointer, uintptr_t alignment) { | 
|---|
| 350 | return 0==((uintptr_t)pointer & (alignment-1)); | 
|---|
| 351 | } | 
|---|
| 352 |  | 
|---|
| 353 | //! A function to check if passed integer is a power of 2 | 
|---|
| 354 | template<typename integer_type> | 
|---|
| 355 | inline bool is_power_of_two(integer_type arg) { | 
|---|
| 356 | return arg && (0 == (arg & (arg - 1))); | 
|---|
| 357 | } | 
|---|
| 358 |  | 
|---|
| 359 | //! A function to compute arg modulo divisor where divisor is a power of 2. | 
|---|
| 360 | template<typename argument_integer_type, typename divisor_integer_type> | 
|---|
| 361 | inline argument_integer_type modulo_power_of_two(argument_integer_type arg, divisor_integer_type divisor) { | 
|---|
| 362 | __TBB_ASSERT( is_power_of_two(divisor), "Divisor should be a power of two"); | 
|---|
| 363 | return (arg & (divisor - 1)); | 
|---|
| 364 | } | 
|---|
| 365 |  | 
|---|
| 366 |  | 
|---|
| 367 | //! A function to determine if arg is a power of 2 at least as big as another power of 2. | 
|---|
| 368 | // i.e. for strictly positive i and j, with j being a power of 2, | 
|---|
| 369 | // determines whether i==j<<k for some nonnegative k (so i==j yields true). | 
|---|
| 370 | template<typename argument_integer_type, typename power2_integer_type> | 
|---|
| 371 | inline bool is_power_of_two_at_least(argument_integer_type arg, power2_integer_type power2) { | 
|---|
| 372 | __TBB_ASSERT( is_power_of_two(power2), "Divisor should be a power of two"); | 
|---|
| 373 | return 0 == (arg & (arg - power2)); | 
|---|
| 374 | } | 
|---|
| 375 |  | 
|---|
| 376 | //! Utility template function to prevent "unused" warnings by various compilers. | 
|---|
| 377 | template<typename T1> void suppress_unused_warning( const T1& ) {} | 
|---|
| 378 | template<typename T1, typename T2> void suppress_unused_warning( const T1&, const T2& ) {} | 
|---|
| 379 | template<typename T1, typename T2, typename T3> void suppress_unused_warning( const T1&, const T2&, const T3& ) {} | 
|---|
| 380 |  | 
|---|
| 381 | // Struct to be used as a version tag for inline functions. | 
|---|
| 382 | /** Version tag can be necessary to prevent loader on Linux from using the wrong | 
|---|
| 383 | symbol in debug builds (when inline functions are compiled as out-of-line). **/ | 
|---|
| 384 | struct version_tag_v3 {}; | 
|---|
| 385 |  | 
|---|
| 386 | typedef version_tag_v3 version_tag; | 
|---|
| 387 |  | 
|---|
| 388 | } // internal | 
|---|
| 389 |  | 
|---|
| 390 | //! Dummy type that distinguishes splitting constructor from copy constructor. | 
|---|
| 391 | /** | 
|---|
| 392 | * See description of parallel_for and parallel_reduce for example usages. | 
|---|
| 393 | * @ingroup algorithms | 
|---|
| 394 | */ | 
|---|
| 395 | class split { | 
|---|
| 396 | }; | 
|---|
| 397 |  | 
|---|
| 398 | //! Type enables transmission of splitting proportion from partitioners to range objects | 
|---|
| 399 | /** | 
|---|
| 400 | * In order to make use of such facility Range objects must implement | 
|---|
| 401 | * splitting constructor with this type passed and initialize static | 
|---|
| 402 | * constant boolean field 'is_splittable_in_proportion' with the value | 
|---|
| 403 | * of 'true' | 
|---|
| 404 | */ | 
|---|
| 405 | class proportional_split: internal::no_assign { | 
|---|
| 406 | public: | 
|---|
| 407 | proportional_split(size_t _left = 1, size_t _right = 1) : my_left(_left), my_right(_right) { } | 
|---|
| 408 |  | 
|---|
| 409 | size_t left() const { return my_left; } | 
|---|
| 410 | size_t right() const { return my_right; } | 
|---|
| 411 |  | 
|---|
| 412 | // used when range does not support proportional split | 
|---|
| 413 | operator split() const { return split(); } | 
|---|
| 414 |  | 
|---|
| 415 | #if __TBB_ENABLE_RANGE_FEEDBACK | 
|---|
| 416 | void set_proportion(size_t _left, size_t _right) { | 
|---|
| 417 | my_left = _left; | 
|---|
| 418 | my_right = _right; | 
|---|
| 419 | } | 
|---|
| 420 | #endif | 
|---|
| 421 | private: | 
|---|
| 422 | size_t my_left, my_right; | 
|---|
| 423 | }; | 
|---|
| 424 |  | 
|---|
| 425 | } // tbb | 
|---|
| 426 |  | 
|---|
| 427 | // Following is a set of classes and functions typically used in compile-time "metaprogramming". | 
|---|
| 428 | // TODO: move all that to a separate header | 
|---|
| 429 |  | 
|---|
| 430 | #if __TBB_CPP11_SMART_POINTERS_PRESENT | 
|---|
| 431 | #include <memory> // for unique_ptr | 
|---|
| 432 | #endif | 
|---|
| 433 |  | 
|---|
| 434 | #if __TBB_CPP11_RVALUE_REF_PRESENT || __TBB_CPP11_DECLTYPE_PRESENT || _LIBCPP_VERSION | 
|---|
| 435 | #include <utility> // for std::move, std::forward, std::declval | 
|---|
| 436 | #endif | 
|---|
| 437 |  | 
|---|
| 438 | namespace tbb { | 
|---|
| 439 | namespace internal { | 
|---|
| 440 |  | 
|---|
| 441 | #if __TBB_CPP11_SMART_POINTERS_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT | 
|---|
| 442 | template<typename T, typename... Args> | 
|---|
| 443 | std::unique_ptr<T> make_unique(Args&&... args) { | 
|---|
| 444 | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 
|---|
| 445 | } | 
|---|
| 446 | #endif | 
|---|
| 447 |  | 
|---|
| 448 | //! Class for determining type of std::allocator<T>::value_type. | 
|---|
| 449 | template<typename T> | 
|---|
| 450 | struct allocator_type { | 
|---|
| 451 | typedef T value_type; | 
|---|
| 452 | }; | 
|---|
| 453 |  | 
|---|
| 454 | #if _MSC_VER | 
|---|
| 455 | //! Microsoft std::allocator has non-standard extension that strips const from a type. | 
|---|
| 456 | template<typename T> | 
|---|
| 457 | struct allocator_type<const T> { | 
|---|
| 458 | typedef T value_type; | 
|---|
| 459 | }; | 
|---|
| 460 | #endif | 
|---|
| 461 |  | 
|---|
| 462 | // Ad-hoc implementation of true_type & false_type | 
|---|
| 463 | // Intended strictly for internal use! For public APIs (traits etc), use C++11 analogues. | 
|---|
| 464 | template <bool v> | 
|---|
| 465 | struct bool_constant { | 
|---|
| 466 | static /*constexpr*/ const bool value = v; | 
|---|
| 467 | }; | 
|---|
| 468 | typedef bool_constant<true> true_type; | 
|---|
| 469 | typedef bool_constant<false> false_type; | 
|---|
| 470 |  | 
|---|
| 471 | //! A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size. | 
|---|
| 472 | template <unsigned u, unsigned long long ull > | 
|---|
| 473 | struct select_size_t_constant { | 
|---|
| 474 | //Explicit cast is needed to avoid compiler warnings about possible truncation. | 
|---|
| 475 | //The value of the right size,   which is selected by ?:, is anyway not truncated or promoted. | 
|---|
| 476 | static const size_t value = (size_t)((sizeof(size_t)==sizeof(u)) ? u : ull); | 
|---|
| 477 | }; | 
|---|
| 478 |  | 
|---|
| 479 | #if __TBB_CPP11_RVALUE_REF_PRESENT | 
|---|
| 480 | using std::move; | 
|---|
| 481 | using std::forward; | 
|---|
| 482 | #elif defined(_LIBCPP_NAMESPACE) | 
|---|
| 483 | // libc++ defines "pre-C++11 move and forward" similarly to ours; use it to avoid name conflicts in some cases. | 
|---|
| 484 | using std::_LIBCPP_NAMESPACE::move; | 
|---|
| 485 | using std::_LIBCPP_NAMESPACE::forward; | 
|---|
| 486 | #else | 
|---|
| 487 | // It is assumed that cv qualifiers, if any, are part of the deduced type. | 
|---|
| 488 | template <typename T> | 
|---|
| 489 | T& move( T& x ) { return x; } | 
|---|
| 490 | template <typename T> | 
|---|
| 491 | T& forward( T& x ) { return x; } | 
|---|
| 492 | #endif /* __TBB_CPP11_RVALUE_REF_PRESENT */ | 
|---|
| 493 |  | 
|---|
| 494 | // Helper macros to simplify writing templates working with both C++03 and C++11. | 
|---|
| 495 | #if __TBB_CPP11_RVALUE_REF_PRESENT | 
|---|
| 496 | #define  __TBB_FORWARDING_REF(A) A&& | 
|---|
| 497 | #else | 
|---|
| 498 | // It is assumed that cv qualifiers, if any, are part of a deduced type. | 
|---|
| 499 | // Thus this macro should not be used in public interfaces. | 
|---|
| 500 | #define  __TBB_FORWARDING_REF(A) A& | 
|---|
| 501 | #endif | 
|---|
| 502 | #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT | 
|---|
| 503 | #define __TBB_PARAMETER_PACK ... | 
|---|
| 504 | #define __TBB_PACK_EXPANSION(A) A... | 
|---|
| 505 | #else | 
|---|
| 506 | #define __TBB_PARAMETER_PACK | 
|---|
| 507 | #define __TBB_PACK_EXPANSION(A) A | 
|---|
| 508 | #endif /* __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */ | 
|---|
| 509 |  | 
|---|
| 510 | #if __TBB_CPP11_DECLTYPE_PRESENT | 
|---|
| 511 | #if __TBB_CPP11_DECLVAL_BROKEN | 
|---|
| 512 | // Ad-hoc implementation of std::declval | 
|---|
| 513 | template <class T> __TBB_FORWARDING_REF(T) declval() /*noexcept*/; | 
|---|
| 514 | #else | 
|---|
| 515 | using std::declval; | 
|---|
| 516 | #endif | 
|---|
| 517 | #endif | 
|---|
| 518 |  | 
|---|
| 519 | template <bool condition> | 
|---|
| 520 | struct STATIC_ASSERTION_FAILED; | 
|---|
| 521 |  | 
|---|
| 522 | template <> | 
|---|
| 523 | struct STATIC_ASSERTION_FAILED<false> { enum {value=1};}; | 
|---|
| 524 |  | 
|---|
| 525 | template<> | 
|---|
| 526 | struct STATIC_ASSERTION_FAILED<true>; //intentionally left undefined to cause compile time error | 
|---|
| 527 |  | 
|---|
| 528 | //! @endcond | 
|---|
| 529 | }} // namespace tbb::internal | 
|---|
| 530 |  | 
|---|
| 531 | #if __TBB_STATIC_ASSERT_PRESENT | 
|---|
| 532 | #define __TBB_STATIC_ASSERT(condition,msg) static_assert(condition,msg) | 
|---|
| 533 | #else | 
|---|
| 534 | //please note condition is intentionally inverted to get a bit more understandable error msg | 
|---|
| 535 | #define __TBB_STATIC_ASSERT_IMPL1(condition,msg,line)       \ | 
|---|
| 536 | enum {static_assert_on_line_##line = tbb::internal::STATIC_ASSERTION_FAILED<!(condition)>::value} | 
|---|
| 537 |  | 
|---|
| 538 | #define __TBB_STATIC_ASSERT_IMPL(condition,msg,line) __TBB_STATIC_ASSERT_IMPL1(condition,msg,line) | 
|---|
| 539 | //! Verify condition, at compile time | 
|---|
| 540 | #define __TBB_STATIC_ASSERT(condition,msg) __TBB_STATIC_ASSERT_IMPL(condition,msg,__LINE__) | 
|---|
| 541 | #endif | 
|---|
| 542 |  | 
|---|
| 543 | #endif /* RC_INVOKED */ | 
|---|
| 544 | #endif /* __TBB_tbb_stddef_H */ | 
|---|
| 545 |  | 
|---|