2 Copyright 2005-2011 Intel Corporation. All Rights Reserved.
4 This file is part of Threading Building Blocks.
6 Threading Building Blocks is free software; you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
10 Threading Building Blocks is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with Threading Building Blocks; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 As a special exception, you may use this file as part of a free software
20 library without restriction. Specifically, if other files instantiate
21 templates or use macros or inline functions from this file, or you compile
22 this file and link it with other files to produce an executable, this
23 file does not by itself cause the resulting executable to be covered by
24 the GNU General Public License. This exception does not however
25 invalidate any other reasons why the executable file might be covered by
26 the GNU General Public License.
29 #ifndef __TBB_tbb_stddef_H
30 #define __TBB_tbb_stddef_H
32 // Marketing-driven product version
33 #define TBB_VERSION_MAJOR 3
34 #define TBB_VERSION_MINOR 0
36 // Engineering-focused interface version
37 #define TBB_INTERFACE_VERSION 5006
38 #define TBB_INTERFACE_VERSION_MAJOR TBB_INTERFACE_VERSION/1000
40 // The oldest major interface version still supported
41 // To be used in SONAME, manifests, etc.
42 #define TBB_COMPATIBLE_INTERFACE_VERSION 2
44 #define __TBB_STRING_AUX(x) #x
45 #define __TBB_STRING(x) __TBB_STRING_AUX(x)
47 // We do not need defines below for resource processing on windows
48 #if !defined RC_INVOKED
50 // Define groups for Doxygen documentation
52 * @defgroup algorithms Algorithms
53 * @defgroup containers Containers
54 * @defgroup memory_allocation Memory Allocation
55 * @defgroup synchronization Synchronization
56 * @defgroup timing Timing
57 * @defgroup task_scheduling Task Scheduling
60 // Simple text that is displayed on the main page of Doxygen documentation.
64 * Click the tabs above for information about the
65 * - <a href="./modules.html">Modules</a> (groups of functionality) implemented by the library
66 * - <a href="./annotated.html">Classes</a> provided by the library
67 * - <a href="./files.html">Files</a> constituting the library.
69 * Please note that significant part of TBB functionality is implemented in the form of
70 * template functions, descriptions of which are not accessible on the <a href="./annotated.html">Classes</a>
71 * tab. Use <a href="./modules.html">Modules</a> or <a href="./namespacemembers.html">Namespace/Namespace Members</a>
74 * Additional pieces of information can be found here
79 /** \page concepts TBB concepts
81 A concept is a set of requirements to a type, which are necessary and sufficient
82 for the type to model a particular behavior or a set of behaviors. Some concepts
83 are specific to a particular algorithm (e.g. algorithm body), while other ones
84 are common to several algorithms (e.g. range concept).
86 All TBB algorithms make use of different classes implementing various concepts.
87 Implementation classes are supplied by the user as type arguments of template
88 parameters and/or as objects passed as function call arguments. The library
89 provides predefined implementations of some concepts (e.g. several kinds of
90 \ref range_req "ranges"), while other ones must always be implemented by the user.
92 TBB defines a set of minimal requirements each concept must conform to. Here is
93 the list of different concepts hyperlinked to the corresponding requirements specifications:
95 - \subpage parallel_do_body_req
96 - \subpage parallel_for_body_req
97 - \subpage parallel_reduce_body_req
98 - \subpage parallel_scan_body_req
99 - \subpage parallel_sort_iter_req
102 // Define preprocessor symbols used to determine architecture
104 # if defined(_M_X64)||defined(__x86_64__) // the latter for MinGW support
105 # define __TBB_x86_64 1
106 # elif defined(_M_IA64)
108 # elif defined(_M_IX86)||defined(__i386__) // the latter for MinGW support
109 # define __TBB_x86_32 1
111 #else /* Assume generic Unix */
112 # if !__linux__ && !__APPLE__
113 # define __TBB_generic_os 1
116 # define __TBB_x86_64 1
119 # elif __i386__||__i386 // __i386 is for Sun OS
120 # define __TBB_x86_32 1
122 # define __TBB_generic_arch 1
126 // tbb_config.h should be included the first since it contains macro definitions used in other headers
127 #include "tbb_config.h"
130 // define the parts of stdint.h that are needed, but put them inside tbb::internal
133 typedef __int8 int8_t;
134 typedef __int16 int16_t;
135 typedef __int32 int32_t;
136 typedef __int64 int64_t;
137 typedef unsigned __int8 uint8_t;
138 typedef unsigned __int16 uint16_t;
139 typedef unsigned __int32 uint32_t;
140 typedef unsigned __int64 uint64_t;
141 } // namespace internal
145 #endif /* _MSC_VER */
148 #define __TBB_EXPORTED_FUNC __cdecl
149 #define __TBB_EXPORTED_METHOD __thiscall
151 #define __TBB_EXPORTED_FUNC
152 #define __TBB_EXPORTED_METHOD
155 #include <cstddef> /* Need size_t and ptrdiff_t */
158 #define __TBB_tbb_windef_H
159 #include "_tbb_windef.h"
160 #undef __TBB_tbb_windef_H
163 //! The namespace tbb contains all components of the library.
166 using std::size_t; using std::ptrdiff_t;
168 //! Type for an assertion handler
169 typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char * comment );
173 //! Assert that x is true.
174 /** If x is false, print assertion failure message.
175 If the comment argument is not NULL, it is printed as part of the failure message.
176 The comment argument has no other effect. */
177 #define __TBB_ASSERT(predicate,message) ((predicate)?((void)0):tbb::assertion_failure(__FILE__,__LINE__,#predicate,message))
178 #define __TBB_ASSERT_EX __TBB_ASSERT
180 //! Set assertion handler and return previous value of it.
181 assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler( assertion_handler_type new_handler );
183 //! Process an assertion failure.
184 /** Normally called from __TBB_ASSERT macro.
185 If assertion handler is null, print message for assertion failure and abort.
186 Otherwise call the assertion handler. */
187 void __TBB_EXPORTED_FUNC assertion_failure( const char* filename, int line, const char* expression, const char* comment );
191 //! No-op version of __TBB_ASSERT.
192 #define __TBB_ASSERT(predicate,comment) ((void)0)
193 //! "Extended" version is useful to suppress warnings if a variable is only used with an assert
194 #define __TBB_ASSERT_EX(predicate,comment) ((void)(1 && (predicate)))
196 #endif /* TBB_USE_ASSERT */
198 //! The function returns the interface version of the TBB shared library being used.
200 * The version it returns is determined at runtime, not at compile/link time.
201 * So it can be different than the value of TBB_INTERFACE_VERSION obtained at compile time.
203 extern "C" int __TBB_EXPORTED_FUNC TBB_runtime_interface_version();
205 //! Dummy type that distinguishes splitting constructor from copy constructor.
207 * See description of parallel_for and parallel_reduce for example usages.
208 * @ingroup algorithms
215 * @brief Identifiers declared inside namespace internal should never be used directly by client code.
219 //! Compile-time constant that is upper bound on cache line/sector size.
220 /** It should be used only in situations where having a compile-time upper
221 bound is more useful than a run-time exact answer.
222 @ingroup memory_allocation */
223 const size_t NFS_MaxLineSize = 128;
225 template<class T, int S>
226 struct padded_base : T {
227 char pad[NFS_MaxLineSize - sizeof(T) % NFS_MaxLineSize];
229 template<class T> struct padded_base<T, 0> : T {};
231 //! Pads type T to fill out to a multiple of cache line size.
233 struct padded : padded_base<T, sizeof(T)> {};
235 //! Extended variant of the standard offsetof macro
236 /** The standard offsetof macro is not sufficient for TBB as it can be used for
237 POD-types only. The constant 0x1000 (not NULL) is necessary to appease GCC. **/
238 #define __TBB_offsetof(class_name, member_name) \
239 ((ptrdiff_t)&(reinterpret_cast<class_name*>(0x1000)->member_name) - 0x1000)
241 //! Returns address of the object containing a member with the given name and address
242 #define __TBB_get_object_ref(class_name, member_name, member_addr) \
243 (*reinterpret_cast<class_name*>((char*)member_addr - __TBB_offsetof(class_name, member_name)))
245 //! Throws std::runtime_error with what() returning error_code description prefixed with aux_info
246 void __TBB_EXPORTED_FUNC handle_perror( int error_code, const char* aux_info );
248 #if TBB_USE_EXCEPTIONS
249 #define __TBB_TRY try
250 #define __TBB_CATCH(e) catch(e)
251 #define __TBB_THROW(e) throw e
252 #define __TBB_RETHROW() throw
253 #else /* !TBB_USE_EXCEPTIONS */
254 inline bool __TBB_false() { return false; }
256 #define __TBB_CATCH(e) if ( tbb::internal::__TBB_false() )
257 #define __TBB_THROW(e) ((void)0)
258 #define __TBB_RETHROW() ((void)0)
259 #endif /* !TBB_USE_EXCEPTIONS */
261 //! Report a runtime warning.
262 void __TBB_EXPORTED_FUNC runtime_warning( const char* format, ... );
265 static void* const poisoned_ptr = reinterpret_cast<void*>(-1);
267 //! Set p to invalid pointer value.
269 inline void poison_pointer( T*& p ) { p = reinterpret_cast<T*>(poisoned_ptr); }
271 /** Expected to be used in assertions only, thus no empty form is defined. **/
273 inline bool is_poisoned( T* p ) { return p == reinterpret_cast<T*>(poisoned_ptr); }
276 inline void poison_pointer( T* ) {/*do nothing*/}
277 #endif /* !TBB_USE_ASSERT */
279 //! Cast pointer from U* to T.
280 /** This method should be used sparingly as a last resort for dealing with
281 situations that inherently break strict ISO C++ aliasing rules. */
282 template<typename T, typename U>
283 inline T punned_cast( U* ptr ) {
284 uintptr_t x = reinterpret_cast<uintptr_t>(ptr);
285 return reinterpret_cast<T>(x);
288 //! Base class for types that should not be assigned.
291 void operator=( const no_assign& );
294 //! Explicitly define default construction, because otherwise gcc issues gratuitous warning.
296 #endif /* __GNUC__ */
299 //! Base class for types that should not be copied or assigned.
300 class no_copy: no_assign {
301 //! Deny copy construction
302 no_copy( const no_copy& );
304 //! Allow default construction
308 //! Class for determining type of std::allocator<T>::value_type.
310 struct allocator_type {
311 typedef T value_type;
315 //! Microsoft std::allocator has non-standard extension that strips const from a type.
317 struct allocator_type<const T> {
318 typedef T value_type;
322 // Struct to be used as a version tag for inline functions.
323 /** Version tag can be necessary to prevent loader on Linux from using the wrong
324 symbol in debug builds (when inline functions are compiled as out-of-line). **/
325 struct version_tag_v3 {};
327 typedef version_tag_v3 version_tag;
334 #endif /* RC_INVOKED */
335 #endif /* __TBB_tbb_stddef_H */