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 #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 11006
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
48 // Simple text that is displayed on the main page of Doxygen documentation.
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 
127 typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char * comment );
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 
139 
141 
144  void __TBB_EXPORTED_FUNC assertion_failure( const char* filename, int line, const char* expression, const char* comment );
145 
146 #if __TBBMALLOC_BUILD
147 }} // namespace rml::internal
148 #else
149 } // namespace tbb
150 #endif
151 
152 #if TBB_USE_ASSERT
153 
155 
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 
165  #define __TBB_ASSERT(predicate,comment) ((void)0)
166  #define __TBB_ASSERT_EX(predicate,comment) ((void)(1 && (predicate)))
168 
169 #endif /* !TBB_USE_ASSERT */
170 
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 
200 
205 
210 namespace internal {
211 
213 
216 const size_t NFS_MaxLineSize = 128;
217 
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 
260 template<class T, size_t S = NFS_MaxLineSize>
261 struct padded : padded_base<T, S, sizeof(T) % S> {};
262 
264 
266 #define __TBB_offsetof(class_name, member_name) \
267  ((ptrdiff_t)&(reinterpret_cast<class_name*>(0x1000)->member_name) - 0x1000)
268 
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 
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 
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 
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 
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 
309 
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 
320 class no_assign {
321  // Deny assignment
322  void operator=( const no_assign& );
323 public:
324 #if __GNUC__
325  no_assign() {}
327 #endif /* __GNUC__ */
328 };
329 
333  no_copy( const no_copy& );
334 public:
336  no_copy() {}
337 };
338 
339 #if TBB_DEPRECATED_MUTEX_COPYING
341 #else
342 // By default various implementations of mutexes are not copy constructible
343 // and not copy assignable.
345 #endif
346 
348 template<typename T>
349 inline bool is_aligned(T* pointer, uintptr_t alignment) {
350  return 0==((uintptr_t)pointer & (alignment-1));
351 }
352 
354 template<typename integer_type>
355 inline bool is_power_of_two(integer_type arg) {
356  return arg && (0 == (arg & (arg - 1)));
357 }
358 
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 
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 
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.
384 struct version_tag_v3 {};
385 
387 
388 } // internal
389 
391 
395 class split {
396 };
397 
399 
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 
449 template<typename T>
451  typedef T value_type;
452 };
453 
454 #if _MSC_VER
455 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>
466  static /*constexpr*/ const bool value = v;
467 };
470 
472 template <unsigned u, unsigned long long ull >
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.
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>
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 
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 #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 */
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
no_copy()
Allow default construction.
Definition: tbb_stddef.h:336
void __TBB_EXPORTED_FUNC assertion_failure(const char *filename, int line, const char *expression, const char *comment)
Process an assertion failure.
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:361
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
Dummy type that distinguishes splitting constructor from copy constructor.
Definition: tbb_stddef.h:395
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:305
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
void operator=(const no_assign &)
T punned_cast(U *ptr)
Cast between unrelated pointer types.
Definition: tbb_stddef.h:314
#define __TBB_FORWARDING_REF(A)
Definition: tbb_stddef.h:496
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:331
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:216
The graph class.
Class for determining type of std::allocator<T>::value_type.
Definition: tbb_stddef.h:450
Base class for types that should not be assigned.
Definition: tbb_stddef.h:320
assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler(assertion_handler_type new_handler)
Set assertion handler and return previous value of it.
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:254
A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size...
Definition: tbb_stddef.h:473
Type enables transmission of splitting proportion from partitioners to range objects.
Definition: tbb_stddef.h:405
bool __TBB_false()
Definition: tbb_stddef.h:282
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:349
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:377
bool is_power_of_two(integer_type arg)
A function to check if passed integer is a power of 2.
Definition: tbb_stddef.h:355
version_tag_v3 version_tag
Definition: tbb_stddef.h:386
proportional_split(size_t _left=1, size_t _right=1)
Definition: tbb_stddef.h:407
#define __TBB_EXPORTED_FUNC
Definition: tbb_stddef.h:97
bool_constant< false > false_type
Definition: tbb_stddef.h:469
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:371
size_t left() const
Definition: tbb_stddef.h:409
void const char const char int ITT_FORMAT __itt_group_sync p
void(* assertion_handler_type)(const char *filename, int line, const char *expression, const char *comment)
Type for an assertion handler.
Definition: tbb_stddef.h:127
bool_constant< true > true_type
Definition: tbb_stddef.h:468
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:74
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:305
static const bool value
Definition: tbb_stddef.h:466
#define __TBB_atomic
Definition: tbb_stddef.h:237
size_t right() const
Definition: tbb_stddef.h:410
Pads type T to fill out to a multiple of cache line size.
Definition: tbb_stddef.h:261

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.