Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb_stddef.h
Go to the documentation of this file.
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 
18 
19 */
20 
21 #ifndef __TBB_tbb_stddef_H
22 #define __TBB_tbb_stddef_H
23 
24 // Marketing-driven product version
25 #define TBB_VERSION_MAJOR 2019
26 #define TBB_VERSION_MINOR 0
27 
28 // Engineering-focused interface version
29 #define TBB_INTERFACE_VERSION 11005
30 #define TBB_INTERFACE_VERSION_MAJOR TBB_INTERFACE_VERSION/1000
31 
32 // The oldest major interface version still supported
33 // To be used in SONAME, manifests, etc.
34 #define TBB_COMPATIBLE_INTERFACE_VERSION 2
35 
36 #define __TBB_STRING_AUX(x) #x
37 #define __TBB_STRING(x) __TBB_STRING_AUX(x)
38 
39 // We do not need defines below for resource processing on windows
40 #if !defined RC_INVOKED
41 
42 // Define groups for Doxygen documentation
52 // Simple text that is displayed on the main page of Doxygen documentation.
94 // tbb_config.h should be included the first since it contains macro definitions used in other headers
95 #include "tbb_config.h"
96 
97 #if _MSC_VER >=1400
98  #define __TBB_EXPORTED_FUNC __cdecl
99  #define __TBB_EXPORTED_METHOD __thiscall
100 #else
101  #define __TBB_EXPORTED_FUNC
102  #define __TBB_EXPORTED_METHOD
103 #endif
104 
105 #if __INTEL_COMPILER || _MSC_VER
106 #define __TBB_NOINLINE(decl) __declspec(noinline) decl
107 #elif __GNUC__
108 #define __TBB_NOINLINE(decl) decl __attribute__ ((noinline))
109 #else
110 #define __TBB_NOINLINE(decl) decl
111 #endif
112 
113 #if __TBB_NOEXCEPT_PRESENT
114 #define __TBB_NOEXCEPT(expression) noexcept(expression)
115 #else
116 #define __TBB_NOEXCEPT(expression)
117 #endif
118 
119 #include <cstddef> /* Need size_t and ptrdiff_t */
120 
121 #if _MSC_VER
122  #define __TBB_tbb_windef_H
123  #include "internal/_tbb_windef.h"
124  #undef __TBB_tbb_windef_H
125 #endif
126 #if !defined(_MSC_VER) || _MSC_VER>=1600
127  #include <stdint.h>
128 #endif
129 
131 typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char * comment );
132 
133 #if __TBBMALLOC_BUILD
134 namespace rml { namespace internal {
135  #define __TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : rml::internal::assertion_failure(__FILE__,__LINE__,#predicate,message))
136 #else
137 namespace tbb {
138  #define __TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : tbb::assertion_failure(__FILE__,__LINE__,#predicate,message))
139 #endif
140 
143 
145 
148  void __TBB_EXPORTED_FUNC assertion_failure( const char* filename, int line, const char* expression, const char* comment );
149 
150 #if __TBBMALLOC_BUILD
151 }} // namespace rml::internal
152 #else
153 } // namespace tbb
154 #endif
155 
156 #if TBB_USE_ASSERT
157 
159 
162  #define __TBB_ASSERT(predicate,message) __TBB_ASSERT_RELEASE(predicate,message)
163 
164  #define __TBB_ASSERT_EX __TBB_ASSERT
165 
166 #else /* !TBB_USE_ASSERT */
167 
169  #define __TBB_ASSERT(predicate,comment) ((void)0)
170  #define __TBB_ASSERT_EX(predicate,comment) ((void)(1 && (predicate)))
172 
173 #endif /* !TBB_USE_ASSERT */
174 
176 namespace tbb {
177 
178  namespace internal {
179 #if _MSC_VER && _MSC_VER<1600
180  typedef __int8 int8_t;
181  typedef __int16 int16_t;
182  typedef __int32 int32_t;
183  typedef __int64 int64_t;
184  typedef unsigned __int8 uint8_t;
185  typedef unsigned __int16 uint16_t;
186  typedef unsigned __int32 uint32_t;
187  typedef unsigned __int64 uint64_t;
188 #else /* Posix */
189  using ::int8_t;
190  using ::int16_t;
191  using ::int32_t;
192  using ::int64_t;
193  using ::uint8_t;
194  using ::uint16_t;
195  using ::uint32_t;
196  using ::uint64_t;
197 #endif /* Posix */
198  } // namespace internal
199 
200  using std::size_t;
201  using std::ptrdiff_t;
202 
204 
209 
214 namespace internal {
215 
217 
220 const size_t NFS_MaxLineSize = 128;
221 
241 #define __TBB_atomic // intentionally empty, see above
242 
243 #if __TBB_OVERRIDE_PRESENT
244 #define __TBB_override override
245 #else
246 #define __TBB_override // formal comment only
247 #endif
248 
249 #if __TBB_CPP17_FALLTHROUGH_PRESENT
250 #define __TBB_fallthrough [[fallthrough]]
251 #elif __TBB_FALLTHROUGH_PRESENT
252 #define __TBB_fallthrough __attribute__ ((fallthrough))
253 #else
254 #define __TBB_fallthrough
255 #endif
256 
257 template<class T, size_t S, size_t R>
258 struct padded_base : T {
259  char pad[S - R];
260 };
261 template<class T, size_t S> struct padded_base<T, S, 0> : T {};
262 
264 template<class T, size_t S = NFS_MaxLineSize>
265 struct padded : padded_base<T, S, sizeof(T) % S> {};
266 
268 
270 #define __TBB_offsetof(class_name, member_name) \
271  ((ptrdiff_t)&(reinterpret_cast<class_name*>(0x1000)->member_name) - 0x1000)
272 
274 #define __TBB_get_object_ref(class_name, member_name, member_addr) \
275  (*reinterpret_cast<class_name*>((char*)member_addr - __TBB_offsetof(class_name, member_name)))
276 
278 void __TBB_EXPORTED_FUNC handle_perror( int error_code, const char* aux_info );
279 
280 #if TBB_USE_EXCEPTIONS
281  #define __TBB_TRY try
282  #define __TBB_CATCH(e) catch(e)
283  #define __TBB_THROW(e) throw e
284  #define __TBB_RETHROW() throw
285 #else /* !TBB_USE_EXCEPTIONS */
286  inline bool __TBB_false() { return false; }
287  #define __TBB_TRY
288  #define __TBB_CATCH(e) if ( tbb::internal::__TBB_false() )
289  #define __TBB_THROW(e) tbb::internal::suppress_unused_warning(e)
290  #define __TBB_RETHROW() ((void)0)
291 #endif /* !TBB_USE_EXCEPTIONS */
292 
294 void __TBB_EXPORTED_FUNC runtime_warning( const char* format, ... );
295 
296 #if TBB_USE_ASSERT
297 static void* const poisoned_ptr = reinterpret_cast<void*>(-1);
298 
300 // Also works for regular (non-__TBB_atomic) pointers.
301 template<typename T>
302 inline void poison_pointer( T* __TBB_atomic & p ) { p = reinterpret_cast<T*>(poisoned_ptr); }
303 
305 template<typename T>
306 inline bool is_poisoned( T* p ) { return p == reinterpret_cast<T*>(poisoned_ptr); }
307 #else
308 template<typename T>
309 inline void poison_pointer( T* __TBB_atomic & ) {/*do nothing*/}
310 #endif /* !TBB_USE_ASSERT */
311 
313 
315 // T is a pointer type because it will be explicitly provided by the programmer as a template argument;
316 // U is a referent type to enable the compiler to check that "ptr" is a pointer, deducing U in the process.
317 template<typename T, typename U>
318 inline T punned_cast( U* ptr ) {
319  uintptr_t x = reinterpret_cast<uintptr_t>(ptr);
320  return reinterpret_cast<T>(x);
321 }
322 
324 class no_assign {
325  // Deny assignment
326  void operator=( const no_assign& );
327 public:
328 #if __GNUC__
329  no_assign() {}
331 #endif /* __GNUC__ */
332 };
333 
337  no_copy( const no_copy& );
338 public:
340  no_copy() {}
341 };
342 
343 #if TBB_DEPRECATED_MUTEX_COPYING
345 #else
346 // By default various implementations of mutexes are not copy constructible
347 // and not copy assignable.
349 #endif
350 
352 template<typename T>
353 inline bool is_aligned(T* pointer, uintptr_t alignment) {
354  return 0==((uintptr_t)pointer & (alignment-1));
355 }
356 
358 template<typename integer_type>
359 inline bool is_power_of_two(integer_type arg) {
360  return arg && (0 == (arg & (arg - 1)));
361 }
362 
364 template<typename argument_integer_type, typename divisor_integer_type>
365 inline argument_integer_type modulo_power_of_two(argument_integer_type arg, divisor_integer_type divisor) {
366  __TBB_ASSERT( is_power_of_two(divisor), "Divisor should be a power of two" );
367  return (arg & (divisor - 1));
368 }
369 
370 
372 // i.e. for strictly positive i and j, with j being a power of 2,
373 // determines whether i==j<<k for some nonnegative k (so i==j yields true).
374 template<typename argument_integer_type, typename power2_integer_type>
375 inline bool is_power_of_two_at_least(argument_integer_type arg, power2_integer_type power2) {
376  __TBB_ASSERT( is_power_of_two(power2), "Divisor should be a power of two" );
377  return 0 == (arg & (arg - power2));
378 }
379 
381 template<typename T1> void suppress_unused_warning( const T1& ) {}
382 template<typename T1, typename T2> void suppress_unused_warning( const T1&, const T2& ) {}
383 template<typename T1, typename T2, typename T3> void suppress_unused_warning( const T1&, const T2&, const T3& ) {}
384 
385 // Struct to be used as a version tag for inline functions.
388 struct version_tag_v3 {};
389 
391 
392 } // internal
393 
395 
399 class split {
400 };
401 
403 
409 class proportional_split: internal::no_assign {
410 public:
411  proportional_split(size_t _left = 1, size_t _right = 1) : my_left(_left), my_right(_right) { }
412 
413  size_t left() const { return my_left; }
414  size_t right() const { return my_right; }
415 
416  // used when range does not support proportional split
417  operator split() const { return split(); }
418 
419 #if __TBB_ENABLE_RANGE_FEEDBACK
420  void set_proportion(size_t _left, size_t _right) {
421  my_left = _left;
422  my_right = _right;
423  }
424 #endif
425 private:
426  size_t my_left, my_right;
427 };
428 
429 } // tbb
430 
431 // Following is a set of classes and functions typically used in compile-time "metaprogramming".
432 // TODO: move all that to a separate header
433 
434 #if __TBB_CPP11_SMART_POINTERS_PRESENT
435 #include <memory> // for unique_ptr
436 #endif
437 
438 #if __TBB_CPP11_RVALUE_REF_PRESENT || __TBB_CPP11_DECLTYPE_PRESENT || _LIBCPP_VERSION
439 #include <utility> // for std::move, std::forward, std::declval
440 #endif
441 
442 namespace tbb {
443 namespace internal {
444 
445 #if __TBB_CPP11_SMART_POINTERS_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
446  template<typename T, typename... Args>
447  std::unique_ptr<T> make_unique(Args&&... args) {
448  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
449  }
450 #endif
451 
453 template<typename T>
455  typedef T value_type;
456 };
457 
458 #if _MSC_VER
459 template<typename T>
461 struct allocator_type<const T> {
462  typedef T value_type;
463 };
464 #endif
465 
466 // Ad-hoc implementation of true_type & false_type
467 // Intended strictly for internal use! For public APIs (traits etc), use C++11 analogues.
468 template <bool v>
470  static /*constexpr*/ const bool value = v;
471 };
474 
476 template <unsigned u, unsigned long long ull >
478  //Explicit cast is needed to avoid compiler warnings about possible truncation.
479  //The value of the right size, which is selected by ?:, is anyway not truncated or promoted.
480  static const size_t value = (size_t)((sizeof(size_t)==sizeof(u)) ? u : ull);
481 };
482 
483 #if __TBB_CPP11_RVALUE_REF_PRESENT
484 using std::move;
485 using std::forward;
486 #elif defined(_LIBCPP_NAMESPACE)
487 // libc++ defines "pre-C++11 move and forward" similarly to ours; use it to avoid name conflicts in some cases.
489 using std::_LIBCPP_NAMESPACE::forward;
490 #else
491 // It is assumed that cv qualifiers, if any, are part of the deduced type.
492 template <typename T>
493 T& move( T& x ) { return x; }
494 template <typename T>
495 T& forward( T& x ) { return x; }
496 #endif /* __TBB_CPP11_RVALUE_REF_PRESENT */
497 
498 // Helper macros to simplify writing templates working with both C++03 and C++11.
499 #if __TBB_CPP11_RVALUE_REF_PRESENT
500 #define __TBB_FORWARDING_REF(A) A&&
501 #else
502 // It is assumed that cv qualifiers, if any, are part of a deduced type.
503 // Thus this macro should not be used in public interfaces.
504 #define __TBB_FORWARDING_REF(A) A&
505 #endif
506 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
507 #define __TBB_PARAMETER_PACK ...
508 #define __TBB_PACK_EXPANSION(A) A...
509 #else
510 #define __TBB_PARAMETER_PACK
511 #define __TBB_PACK_EXPANSION(A) A
512 #endif /* __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
513 
514 #if __TBB_CPP11_DECLTYPE_PRESENT
515 #if __TBB_CPP11_DECLVAL_BROKEN
516 // Ad-hoc implementation of std::declval
517 template <class T> __TBB_FORWARDING_REF(T) declval() /*noexcept*/;
518 #else
519 using std::declval;
520 #endif
521 #endif
522 
523 template <bool condition>
525 
526 template <>
527 struct STATIC_ASSERTION_FAILED<false> { enum {value=1};};
528 
529 template<>
530 struct STATIC_ASSERTION_FAILED<true>; //intentionally left undefined to cause compile time error
531 
533 }} // namespace tbb::internal
534 
535 #if __TBB_STATIC_ASSERT_PRESENT
536 #define __TBB_STATIC_ASSERT(condition,msg) static_assert(condition,msg)
537 #else
538 //please note condition is intentionally inverted to get a bit more understandable error msg
539 #define __TBB_STATIC_ASSERT_IMPL1(condition,msg,line) \
540  enum {static_assert_on_line_##line = tbb::internal::STATIC_ASSERTION_FAILED<!(condition)>::value}
541 
542 #define __TBB_STATIC_ASSERT_IMPL(condition,msg,line) __TBB_STATIC_ASSERT_IMPL1(condition,msg,line)
543 #define __TBB_STATIC_ASSERT(condition,msg) __TBB_STATIC_ASSERT_IMPL(condition,msg,__LINE__)
545 #endif
546 
547 #endif /* RC_INVOKED */
548 #endif /* __TBB_tbb_stddef_H */
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size...
Definition: tbb_stddef.h:477
size_t left() const
Definition: tbb_stddef.h:413
Type enables transmission of splitting proportion from partitioners to range objects.
Definition: tbb_stddef.h:409
int __TBB_EXPORTED_FUNC TBB_runtime_interface_version()
The function returns the interface version of the TBB shared library being used.
Definition: tbb_misc.cpp:258
T punned_cast(U *ptr)
Cast between unrelated pointer types.
Definition: tbb_stddef.h:318
argument_integer_type modulo_power_of_two(argument_integer_type arg, divisor_integer_type divisor)
A function to compute arg modulo divisor where divisor is a power of 2.
Definition: tbb_stddef.h:365
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:381
bool_constant< true > true_type
Definition: tbb_stddef.h:472
no_copy()
Allow default construction.
Definition: tbb_stddef.h:340
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:335
bool is_power_of_two(integer_type arg)
A function to check if passed integer is a power of 2.
Definition: tbb_stddef.h:359
version_tag_v3 version_tag
Definition: tbb_stddef.h:390
void const char const char int ITT_FORMAT __itt_group_sync p
bool is_power_of_two_at_least(argument_integer_type arg, power2_integer_type power2)
A function to determine if arg is a power of 2 at least as big as another power of 2.
Definition: tbb_stddef.h:375
Base class for types that should not be assigned.
Definition: tbb_stddef.h:324
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 ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark S
void __TBB_EXPORTED_FUNC assertion_failure(const char *filename, int line, const char *expression, const char *comment)
Process an assertion failure.
size_t right() const
Definition: tbb_stddef.h:414
#define __TBB_FORWARDING_REF(A)
Definition: tbb_stddef.h:500
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
The graph class.
Dummy type that distinguishes splitting constructor from copy constructor.
Definition: tbb_stddef.h:399
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
proportional_split(size_t _left=1, size_t _right=1)
Definition: tbb_stddef.h:411
#define __TBB_EXPORTED_FUNC
Definition: tbb_stddef.h:101
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:309
bool __TBB_false()
Definition: tbb_stddef.h:286
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
void operator=(const no_assign &)
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:220
#define __TBB_atomic
Definition: tbb_stddef.h:241
bool_constant< false > false_type
Definition: tbb_stddef.h:473
assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler(assertion_handler_type new_handler)
Set assertion handler and return previous value of it.
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info.
Definition: tbb_misc.cpp:78
Class for determining type of std::allocator<T>::value_type.
Definition: tbb_stddef.h:454
void(* assertion_handler_type)(const char *filename, int line, const char *expression, const char *comment)
Type for an assertion handler.
Definition: tbb_stddef.h:131
static const bool value
Definition: tbb_stddef.h:470
Pads type T to fill out to a multiple of cache line size.
Definition: tbb_stddef.h:265

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.