BRE12
tbb_stddef.h
1 /*
2  Copyright 2005-2016 Intel Corporation. All Rights Reserved.
3 
4  This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5  you can redistribute it and/or modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation. Threading Building Blocks is
7  distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9  See the GNU General Public License for more details. You should have received a copy of
10  the GNU General Public License along with Threading Building Blocks; if not, write to the
11  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12 
13  As a special exception, you may use this file as part of a free software library without
14  restriction. Specifically, if other files instantiate templates or use macros or inline
15  functions from this file, or you compile this file and link it with other files to produce
16  an executable, this file does not by itself cause the resulting executable to be covered
17  by the GNU General Public License. This exception does not however invalidate any other
18  reasons why the executable file might be covered by the GNU General Public License.
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 4
26 #define TBB_VERSION_MINOR 4
27 
28 // Engineering-focused interface version
29 #define TBB_INTERFACE_VERSION 9005
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 
142  assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler( assertion_handler_type new_handler );
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 
208 extern "C" int __TBB_EXPORTED_FUNC TBB_runtime_interface_version();
209 
214 namespace internal {
215 
217 
220 const size_t NFS_MaxLineSize = 128;
221 
241 #define __TBB_atomic // intentionally empty, see above
242 
243 template<class T, size_t S, size_t R>
244 struct padded_base : T {
245  char pad[S - R];
246 };
247 template<class T, size_t S> struct padded_base<T, S, 0> : T {};
248 
250 template<class T, size_t S = NFS_MaxLineSize>
251 struct padded : padded_base<T, S, sizeof(T) % S> {};
252 
254 
256 #define __TBB_offsetof(class_name, member_name) \
257  ((ptrdiff_t)&(reinterpret_cast<class_name*>(0x1000)->member_name) - 0x1000)
258 
260 #define __TBB_get_object_ref(class_name, member_name, member_addr) \
261  (*reinterpret_cast<class_name*>((char*)member_addr - __TBB_offsetof(class_name, member_name)))
262 
264 void __TBB_EXPORTED_FUNC handle_perror( int error_code, const char* aux_info );
265 
266 #if TBB_USE_EXCEPTIONS
267  #define __TBB_TRY try
268  #define __TBB_CATCH(e) catch(e)
269  #define __TBB_THROW(e) throw e
270  #define __TBB_RETHROW() throw
271 #else /* !TBB_USE_EXCEPTIONS */
272  inline bool __TBB_false() { return false; }
273  #define __TBB_TRY
274  #define __TBB_CATCH(e) if ( tbb::internal::__TBB_false() )
275  #define __TBB_THROW(e) ((void)0)
276  #define __TBB_RETHROW() ((void)0)
277 #endif /* !TBB_USE_EXCEPTIONS */
278 
280 void __TBB_EXPORTED_FUNC runtime_warning( const char* format, ... );
281 
282 #if TBB_USE_ASSERT
283 static void* const poisoned_ptr = reinterpret_cast<void*>(-1);
284 
286 // Also works for regular (non-__TBB_atomic) pointers.
287 template<typename T>
288 inline void poison_pointer( T* __TBB_atomic & p ) { p = reinterpret_cast<T*>(poisoned_ptr); }
289 
291 template<typename T>
292 inline bool is_poisoned( T* p ) { return p == reinterpret_cast<T*>(poisoned_ptr); }
293 #else
294 template<typename T>
295 inline void poison_pointer( T* __TBB_atomic & ) {/*do nothing*/}
296 #endif /* !TBB_USE_ASSERT */
297 
299 
301 // T is a pointer type because it will be explicitly provided by the programmer as a template argument;
302 // U is a referent type to enable the compiler to check that "ptr" is a pointer, deducing U in the process.
303 template<typename T, typename U>
304 inline T punned_cast( U* ptr ) {
305  uintptr_t x = reinterpret_cast<uintptr_t>(ptr);
306  return reinterpret_cast<T>(x);
307 }
308 
310 class no_assign {
311  // Deny assignment
312  void operator=( const no_assign& );
313 public:
314 #if __GNUC__
315  no_assign() {}
317 #endif /* __GNUC__ */
318 };
319 
321 class no_copy: no_assign {
323  no_copy( const no_copy& );
324 public:
326  no_copy() {}
327 };
328 
329 #if TBB_DEPRECATED_MUTEX_COPYING
330 class mutex_copy_deprecated_and_disabled {};
331 #else
332 // By default various implementations of mutexes are not copy constructible
333 // and not copy assignable.
334 class mutex_copy_deprecated_and_disabled : no_copy {};
335 #endif
336 
338 template<typename T>
339 inline bool is_aligned(T* pointer, uintptr_t alignment) {
340  return 0==((uintptr_t)pointer & (alignment-1));
341 }
342 
344 template<typename integer_type>
345 inline bool is_power_of_two(integer_type arg) {
346  return arg && (0 == (arg & (arg - 1)));
347 }
348 
350 template<typename argument_integer_type, typename divisor_integer_type>
351 inline argument_integer_type modulo_power_of_two(argument_integer_type arg, divisor_integer_type divisor) {
352  __TBB_ASSERT( is_power_of_two(divisor), "Divisor should be a power of two" );
353  return (arg & (divisor - 1));
354 }
355 
356 
358 // i.e. for strictly positive i and j, with j being a power of 2,
359 // determines whether i==j<<k for some nonnegative k (so i==j yields true).
360 template<typename argument_integer_type, typename power2_integer_type>
361 inline bool is_power_of_two_at_least(argument_integer_type arg, power2_integer_type power2) {
362  __TBB_ASSERT( is_power_of_two(power2), "Divisor should be a power of two" );
363  return 0 == (arg & (arg - power2));
364 }
365 
367 template<typename T1> void suppress_unused_warning( const T1& ) {}
368 template<typename T1, typename T2> void suppress_unused_warning( const T1&, const T2& ) {}
369 template<typename T1, typename T2, typename T3> void suppress_unused_warning( const T1&, const T2&, const T3& ) {}
370 
371 // Struct to be used as a version tag for inline functions.
374 struct version_tag_v3 {};
375 
376 typedef version_tag_v3 version_tag;
377 
378 } // internal
379 
381 
385 class split {
386 };
387 
389 
395 class proportional_split: internal::no_assign {
396 public:
397  proportional_split(size_t _left = 1, size_t _right = 1) : my_left(_left), my_right(_right) { }
398 
399  size_t left() const { return my_left; }
400  size_t right() const { return my_right; }
401 
402  // used when range does not support proportional split
403  operator split() const { return split(); }
404 
405 #if __TBB_ENABLE_RANGE_FEEDBACK
406  void set_proportion(size_t _left, size_t _right) {
407  my_left = _left;
408  my_right = _right;
409  }
410 #endif
411 private:
412  size_t my_left, my_right;
413 };
414 
415 } // tbb
416 
417 // Following is a set of classes and functions typically used in compile-time "metaprogramming".
418 // TODO: move all that to a separate header
419 
420 #if __TBB_ALLOCATOR_TRAITS_PRESENT
421 #include <memory> //for allocator_traits
422 #endif
423 
424 #if __TBB_CPP11_RVALUE_REF_PRESENT || _LIBCPP_VERSION
425 #include <utility> // for std::move
426 #endif
427 
428 namespace tbb {
429 namespace internal {
430 
432 template<typename T>
433 struct allocator_type {
434  typedef T value_type;
435 };
436 
437 #if _MSC_VER
438 template<typename T>
440 struct allocator_type<const T> {
441  typedef T value_type;
442 };
443 #endif
444 
445 // Ad-hoc implementation of true_type & false_type
446 // Intended strictly for internal use! For public APIs (traits etc), use C++11 analogues.
447 template <bool v>
448 struct bool_constant {
449  static /*constexpr*/ const bool value = v;
450 };
451 typedef bool_constant<true> true_type;
452 typedef bool_constant<false> false_type;
453 
454 #if __TBB_ALLOCATOR_TRAITS_PRESENT
455 using std::allocator_traits;
456 #else
457 template<typename allocator>
458 struct allocator_traits{
459  typedef tbb::internal::false_type propagate_on_container_move_assignment;
460 };
461 #endif
462 
464 template <unsigned u, unsigned long long ull >
465 struct select_size_t_constant {
466  //Explicit cast is needed to avoid compiler warnings about possible truncation.
467  //The value of the right size, which is selected by ?:, is anyway not truncated or promoted.
468  static const size_t value = (size_t)((sizeof(size_t)==sizeof(u)) ? u : ull);
469 };
470 
471 #if __TBB_CPP11_RVALUE_REF_PRESENT
472 using std::move;
473 using std::forward;
474 #elif defined(_LIBCPP_NAMESPACE)
475 // libc++ defines "pre-C++11 move and forward" similarly to ours; use it to avoid name conflicts in some cases.
476 using std::_LIBCPP_NAMESPACE::move;
477 using std::_LIBCPP_NAMESPACE::forward;
478 #else
479 // It is assumed that cv qualifiers, if any, are part of the deduced type.
480 template <typename T>
481 T& move( T& x ) { return x; }
482 template <typename T>
483 T& forward( T& x ) { return x; }
484 #endif /* __TBB_CPP11_RVALUE_REF_PRESENT */
485 
486 // Helper macros to simplify writing templates working with both C++03 and C++11.
487 #if __TBB_CPP11_RVALUE_REF_PRESENT
488 #define __TBB_FORWARDING_REF(A) A&&
489 #else
490 // It is assumed that cv qualifiers, if any, are part of a deduced type.
491 // Thus this macro should not be used in public interfaces.
492 #define __TBB_FORWARDING_REF(A) A&
493 #endif
494 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
495 #define __TBB_PARAMETER_PACK ...
496 #define __TBB_PACK_EXPANSION(A) A...
497 #else
498 #define __TBB_PARAMETER_PACK
499 #define __TBB_PACK_EXPANSION(A) A
500 #endif /* __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
501 
502 #if __TBB_CPP11_DECLTYPE_PRESENT
503 #if __TBB_CPP11_DECLVAL_BROKEN
504 // Ad-hoc implementation of std::declval
505 template <class T> __TBB_FORWARDING_REF(T) declval() /*noexcept*/;
506 #else
507 using std::declval;
508 #endif
509 #endif
510 
511 template <bool condition>
512 struct STATIC_ASSERTION_FAILED;
513 
514 template <>
515 struct STATIC_ASSERTION_FAILED<false> { enum {value=1};};
516 
517 template<>
518 struct STATIC_ASSERTION_FAILED<true>; //intentionally left undefined to cause compile time error
519 
521 }} // namespace tbb::internal
522 
523 #if __TBB_STATIC_ASSERT_PRESENT
524 #define __TBB_STATIC_ASSERT(condition,msg) static_assert(condition,msg)
525 #else
526 //please note condition is intentionally inverted to get a bit more understandable error msg
527 #define __TBB_STATIC_ASSERT_IMPL1(condition,msg,line) \
528  enum {static_assert_on_line_##line = tbb::internal::STATIC_ASSERTION_FAILED<!(condition)>::value}
529 
530 #define __TBB_STATIC_ASSERT_IMPL(condition,msg,line) __TBB_STATIC_ASSERT_IMPL1(condition,msg,line)
531 #define __TBB_STATIC_ASSERT(condition,msg) __TBB_STATIC_ASSERT_IMPL(condition,msg,__LINE__)
533 #endif
534 
535 #endif /* RC_INVOKED */
536 #endif /* __TBB_tbb_stddef_H */
int __TBB_EXPORTED_FUNC TBB_runtime_interface_version()
The function returns the interface version of the TBB shared library being used.
void __TBB_EXPORTED_FUNC assertion_failure(const char *filename, int line, const char *expression, const char *comment)
Process an assertion failure.
Definition: _flow_graph_async_msg_impl.h:32
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler(assertion_handler_type new_handler)
Set assertion handler and return previous value of it.