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-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#ifndef __TBB_tbb_stddef_H
18#define __TBB_tbb_stddef_H
19
20// Marketing-driven product version
21#define TBB_VERSION_MAJOR 2020
22#define TBB_VERSION_MINOR 2
23
24// Engineering-focused interface version
25#define TBB_INTERFACE_VERSION 11102
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
127typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char * comment );
128
129#if __TBBMALLOC_BUILD
130namespace rml { namespace internal {
131 #define __TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : rml::internal::assertion_failure(__FILE__,__LINE__,#predicate,message))
132#else
133namespace 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)
167 #define __TBB_ASSERT_EX(predicate,comment) ((void)(1 && (predicate)))
168
169#endif /* !TBB_USE_ASSERT */
170
172namespace 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
210namespace internal {
211
213
216const 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
253template<class T, size_t S, size_t R>
254struct padded_base : T {
255 char pad[S - R];
256};
257template<class T, size_t S> struct padded_base<T, S, 0> : T {};
258
260template<class T, size_t S = NFS_MaxLineSize>
261struct 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
274void __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
290void __TBB_EXPORTED_FUNC runtime_warning( const char* format, ... );
291
292#if TBB_USE_ASSERT
293static void* const poisoned_ptr = reinterpret_cast<void*>(-1);
294
296// Also works for regular (non-__TBB_atomic) pointers.
297template<typename T>
298inline void poison_pointer( T* __TBB_atomic & p ) { p = reinterpret_cast<T*>(poisoned_ptr); }
299
301template<typename T>
302inline bool is_poisoned( T* p ) { return p == reinterpret_cast<T*>(poisoned_ptr); }
303#else
304template<typename T>
305inline 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.
313template<typename T, typename U>
314inline T punned_cast( U* ptr ) {
315 uintptr_t x = reinterpret_cast<uintptr_t>(ptr);
316 return reinterpret_cast<T>(x);
317}
318
319#if __TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT
320
323public:
324 void operator=( const no_assign& ) = delete;
325 no_assign( const no_assign& ) = default;
326 no_assign() = default;
327};
328
331public:
332 no_copy( const no_copy& ) = delete;
333 no_copy() = default;
334};
335
336#else /*__TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT*/
337
339class no_assign {
340 // Deny assignment
341 void operator=( const no_assign& );
342public:
343#if __GNUC__
345 no_assign() {}
346#endif /* __GNUC__ */
347};
348
350class no_copy: no_assign {
352 no_copy( const no_copy& );
353public:
355 no_copy() {}
356};
357
358#endif /*__TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT*/
359
360#if TBB_DEPRECATED_MUTEX_COPYING
361class mutex_copy_deprecated_and_disabled {};
362#else
363// By default various implementations of mutexes are not copy constructible
364// and not copy assignable.
366#endif
367
369template<typename T>
370inline bool is_aligned(T* pointer, uintptr_t alignment) {
371 return 0==((uintptr_t)pointer & (alignment-1));
372}
373
375template<typename integer_type>
376inline bool is_power_of_two(integer_type arg) {
377 return arg && (0 == (arg & (arg - 1)));
378}
379
381template<typename argument_integer_type, typename divisor_integer_type>
382inline argument_integer_type modulo_power_of_two(argument_integer_type arg, divisor_integer_type divisor) {
383 __TBB_ASSERT( is_power_of_two(divisor), "Divisor should be a power of two" );
384 return (arg & (divisor - 1));
385}
386
387
389// i.e. for strictly positive i and j, with j being a power of 2,
390// determines whether i==j<<k for some nonnegative k (so i==j yields true).
391template<typename argument_integer_type, typename power2_integer_type>
392inline bool is_power_of_two_at_least(argument_integer_type arg, power2_integer_type power2) {
393 __TBB_ASSERT( is_power_of_two(power2), "Divisor should be a power of two" );
394 return 0 == (arg & (arg - power2));
395}
396
398template<typename T1> void suppress_unused_warning( const T1& ) {}
399template<typename T1, typename T2> void suppress_unused_warning( const T1&, const T2& ) {}
400template<typename T1, typename T2, typename T3> void suppress_unused_warning( const T1&, const T2&, const T3& ) {}
401
402// Struct to be used as a version tag for inline functions.
406
408
409} // internal
410
412
416class split {
417};
418
420
427public:
428 proportional_split(size_t _left = 1, size_t _right = 1) : my_left(_left), my_right(_right) { }
429
430 size_t left() const { return my_left; }
431 size_t right() const { return my_right; }
432
433 // used when range does not support proportional split
434 operator split() const { return split(); }
435
436#if __TBB_ENABLE_RANGE_FEEDBACK
437 void set_proportion(size_t _left, size_t _right) {
438 my_left = _left;
439 my_right = _right;
440 }
441#endif
442private:
444};
445
446} // tbb
447
448// Following is a set of classes and functions typically used in compile-time "metaprogramming".
449// TODO: move all that to a separate header
450
451#if __TBB_CPP11_SMART_POINTERS_PRESENT
452#include <memory> // for unique_ptr
453#endif
454
455#if __TBB_CPP11_RVALUE_REF_PRESENT || __TBB_CPP11_DECLTYPE_PRESENT || _LIBCPP_VERSION
456#include <utility> // for std::move, std::forward, std::declval
457#endif
458
459namespace tbb {
460namespace internal {
461
462#if __TBB_CPP11_SMART_POINTERS_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT && __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
463 template<typename T, typename... Args>
464 std::unique_ptr<T> make_unique(Args&&... args) {
465 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
466 }
467#endif
468
470template<typename T>
472 typedef T value_type;
473};
474
475#if _MSC_VER
477template<typename T>
478struct allocator_type<const T> {
479 typedef T value_type;
480};
481#endif
482
483// Ad-hoc implementation of true_type & false_type
484// Intended strictly for internal use! For public APIs (traits etc), use C++11 analogues.
485template <bool v>
487 static /*constexpr*/ const bool value = v;
488};
491
493template <unsigned u, unsigned long long ull >
495 //Explicit cast is needed to avoid compiler warnings about possible truncation.
496 //The value of the right size, which is selected by ?:, is anyway not truncated or promoted.
497 static const size_t value = (size_t)((sizeof(size_t)==sizeof(u)) ? u : ull);
498};
499
500#if __TBB_CPP11_RVALUE_REF_PRESENT
501using std::move;
502using std::forward;
503#elif defined(_LIBCPP_NAMESPACE)
504// libc++ defines "pre-C++11 move and forward" similarly to ours; use it to avoid name conflicts in some cases.
506using std::_LIBCPP_NAMESPACE::forward;
507#else
508// It is assumed that cv qualifiers, if any, are part of the deduced type.
509template <typename T>
510T& move( T& x ) { return x; }
511template <typename T>
512T& forward( T& x ) { return x; }
513#endif /* __TBB_CPP11_RVALUE_REF_PRESENT */
514
515// Helper macros to simplify writing templates working with both C++03 and C++11.
516#if __TBB_CPP11_RVALUE_REF_PRESENT
517#define __TBB_FORWARDING_REF(A) A&&
518#else
519// It is assumed that cv qualifiers, if any, are part of a deduced type.
520// Thus this macro should not be used in public interfaces.
521#define __TBB_FORWARDING_REF(A) A&
522#endif
523#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
524#define __TBB_PARAMETER_PACK ...
525#define __TBB_PACK_EXPANSION(A) A...
526#else
527#define __TBB_PARAMETER_PACK
528#define __TBB_PACK_EXPANSION(A) A
529#endif /* __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
530
531#if __TBB_CPP11_DECLTYPE_PRESENT
532#if __TBB_CPP11_DECLVAL_BROKEN
533// Ad-hoc implementation of std::declval
534template <class T> __TBB_FORWARDING_REF(T) declval() /*noexcept*/;
535#else
536using std::declval;
537#endif
538#endif
539
540template <bool condition>
542
543template <>
544struct STATIC_ASSERTION_FAILED<false> { enum {value=1};};
545
546template<>
547struct STATIC_ASSERTION_FAILED<true>; //intentionally left undefined to cause compile time error
548
550}} // namespace tbb::internal
551
552#if __TBB_STATIC_ASSERT_PRESENT
553#define __TBB_STATIC_ASSERT(condition,msg) static_assert(condition,msg)
554#else
555//please note condition is intentionally inverted to get a bit more understandable error msg
556#define __TBB_STATIC_ASSERT_IMPL1(condition,msg,line) \
557 enum {static_assert_on_line_##line = tbb::internal::STATIC_ASSERTION_FAILED<!(condition)>::value}
558
559#define __TBB_STATIC_ASSERT_IMPL(condition,msg,line) __TBB_STATIC_ASSERT_IMPL1(condition,msg,line)
561#define __TBB_STATIC_ASSERT(condition,msg) __TBB_STATIC_ASSERT_IMPL(condition,msg,__LINE__)
562#endif
563
564#endif /* RC_INVOKED */
565#endif /* __TBB_tbb_stddef_H */
#define __TBB_atomic
Definition: tbb_stddef.h:237
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define __TBB_EXPORTED_FUNC
Definition: tbb_stddef.h:97
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
#define __TBB_FORWARDING_REF(A)
Definition: tbb_stddef.h:517
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_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 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
void const char const char int ITT_FORMAT __itt_group_sync p
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.
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:267
void __TBB_EXPORTED_FUNC assertion_failure(const char *filename, int line, const char *expression, const char *comment)
Process an assertion failure.
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
bool __TBB_false()
Definition: tbb_stddef.h:282
version_tag_v3 version_tag
Definition: tbb_stddef.h:407
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:305
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:87
bool_constant< false > false_type
Definition: tbb_stddef.h:490
bool is_power_of_two(integer_type arg)
A function to check if passed integer is a power of 2.
Definition: tbb_stddef.h:376
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
bool_constant< true > true_type
Definition: tbb_stddef.h:489
T punned_cast(U *ptr)
Cast between unrelated pointer types.
Definition: tbb_stddef.h:314
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:382
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:392
Pads type T to fill out to a multiple of cache line size.
Definition: tbb_stddef.h:261
Base class for types that should not be assigned.
Definition: tbb_stddef.h:322
void operator=(const no_assign &)=delete
no_assign(const no_assign &)=default
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:330
no_copy(const no_copy &)=delete
Dummy type that distinguishes splitting constructor from copy constructor.
Definition: tbb_stddef.h:416
Type enables transmission of splitting proportion from partitioners to range objects.
Definition: tbb_stddef.h:426
size_t left() const
Definition: tbb_stddef.h:430
proportional_split(size_t _left=1, size_t _right=1)
Definition: tbb_stddef.h:428
size_t right() const
Definition: tbb_stddef.h:431
Class for determining type of std::allocator<T>::value_type.
Definition: tbb_stddef.h:471
static const bool value
Definition: tbb_stddef.h:487
A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size...
Definition: tbb_stddef.h:494

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.