Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb_exception.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_exception_H
22 #define __TBB_exception_H
23 
24 #include "tbb_stddef.h"
25 #include <exception>
26 #include <new> // required for bad_alloc definition, operators new
27 #include <string> // required to construct std exception classes
28 
29 namespace tbb {
30 
32 class bad_last_alloc : public std::bad_alloc {
33 public:
34  const char* what() const throw() __TBB_override;
35 #if __TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN
36  ~bad_last_alloc() throw() __TBB_override {}
37 #endif
38 };
39 
41 class improper_lock : public std::exception {
42 public:
43  const char* what() const throw() __TBB_override;
44 };
45 
47 class user_abort : public std::exception {
48 public:
49  const char* what() const throw() __TBB_override;
50 };
51 
53 class missing_wait : public std::exception {
54 public:
55  const char* what() const throw() __TBB_override;
56 };
57 
59 class invalid_multiple_scheduling : public std::exception {
60 public:
61  const char* what() const throw() __TBB_override;
62 };
63 
64 namespace internal {
67 
82  eid_reserved, // free slot for backward compatibility, can be reused.
88 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
89  // This id is used only from inside the library and only for support of CPF functionality.
90  // So, if we drop the functionality, eid_reserved1 can be safely renamed and reused.
91  eid_blocking_thread_join_impossible = eid_reserved1,
92 #endif
95 
98 };
99 
101 
104 
106 inline void throw_exception ( exception_id eid ) { throw_exception_v4(eid); }
107 
108 } // namespace internal
109 } // namespace tbb
110 
111 #if __TBB_TASK_GROUP_CONTEXT
112 #include "tbb_allocator.h"
113 #include <typeinfo> //for typeid
114 
115 namespace tbb {
116 
118 
138 class tbb_exception : public std::exception
139 {
143  void* operator new ( size_t );
144 
145 public:
146 #if __clang__
147  // At -O3 or even -O2 optimization level, Clang may fully throw away an empty destructor
148  // of tbb_exception from destructors of derived classes. As a result, it does not create
149  // vtable for tbb_exception, which is a required part of TBB binary interface.
150  // Making the destructor non-empty (with just a semicolon) prevents that optimization.
151  ~tbb_exception() throw() { /* keep the semicolon! */ ; }
152 #endif
153 
155 
156  virtual tbb_exception* move() throw() = 0;
157 
159 
161  virtual void destroy() throw() = 0;
162 
164 
168  virtual void throw_self() = 0;
169 
171  virtual const char* name() const throw() = 0;
172 
174  virtual const char* what() const throw() __TBB_override = 0;
175 
182  void operator delete ( void* p ) {
184  }
185 };
186 
188 
193 {
194 public:
196  : tbb_exception(src), my_dynamic(false)
197  {
198  set(src.my_exception_name, src.my_exception_info);
199  }
200 
201  captured_exception( const char* name_, const char* info )
202  : my_dynamic(false)
203  {
204  set(name_, info);
205  }
206 
208 
209  captured_exception& operator= ( const captured_exception& src ) {
210  if ( this != &src ) {
211  clear();
212  set(src.my_exception_name, src.my_exception_info);
213  }
214  return *this;
215  }
216 
218 
219  void __TBB_EXPORTED_METHOD destroy() throw() __TBB_override;
220 
222 
223  const char* __TBB_EXPORTED_METHOD name() const throw() __TBB_override;
224 
225  const char* __TBB_EXPORTED_METHOD what() const throw() __TBB_override;
226 
227  void __TBB_EXPORTED_METHOD set( const char* name, const char* info ) throw();
228  void __TBB_EXPORTED_METHOD clear() throw();
229 
230 private:
233 
235  static captured_exception* allocate( const char* name, const char* info );
236 
238  const char* my_exception_name;
239  const char* my_exception_info;
240 };
241 
243 
247 template<typename ExceptionData>
249 {
251 
252 public:
253  movable_exception( const ExceptionData& data_ )
254  : my_exception_data(data_)
255  , my_dynamic(false)
256  , my_exception_name(
258  typeid(self_type).name()
259 #else /* !TBB_USE_EXCEPTIONS */
260  "movable_exception"
261 #endif /* !TBB_USE_EXCEPTIONS */
262  )
263  {}
264 
265  movable_exception( const movable_exception& src ) throw ()
266  : tbb_exception(src)
267  , my_exception_data(src.my_exception_data)
268  , my_dynamic(false)
269  , my_exception_name(src.my_exception_name)
270  {}
271 
272  ~movable_exception() throw() {}
273 
274  const movable_exception& operator= ( const movable_exception& src ) {
275  if ( this != &src ) {
276  my_exception_data = src.my_exception_data;
277  my_exception_name = src.my_exception_name;
278  }
279  return *this;
280  }
281 
282  ExceptionData& data() throw() { return my_exception_data; }
283 
284  const ExceptionData& data() const throw() { return my_exception_data; }
285 
286  const char* name() const throw() __TBB_override { return my_exception_name; }
287 
288  const char* what() const throw() __TBB_override { return "tbb::movable_exception"; }
289 
292  if ( e ) {
293  ::new (e) movable_exception(*this);
294  ((movable_exception*)e)->my_dynamic = true;
295  }
296  return (movable_exception*)e;
297  }
298  void destroy() throw() __TBB_override {
299  __TBB_ASSERT ( my_dynamic, "Method destroy can be called only on dynamically allocated movable_exceptions" );
300  if ( my_dynamic ) {
301  this->~movable_exception();
303  }
304  }
305  void throw_self() __TBB_override { __TBB_THROW( *this ); }
306 
307 protected:
309  ExceptionData my_exception_data;
310 
311 private:
314 
316 
317  const char* my_exception_name;
318 };
319 
320 #if !TBB_USE_CAPTURED_EXCEPTION
321 namespace internal {
322 
324 
327  std::exception_ptr my_ptr;
328 
329 public:
330  static tbb_exception_ptr* allocate();
331  static tbb_exception_ptr* allocate( const tbb_exception& tag );
333  static tbb_exception_ptr* allocate( captured_exception& src );
334 
336 
337  void destroy() throw();
338 
340  void throw_self() { std::rethrow_exception(my_ptr); }
341 
342 private:
343  tbb_exception_ptr( const std::exception_ptr& src ) : my_ptr(src) {}
346  my_ptr(std::make_exception_ptr(src)) // the final function name in C++11
347  #else
348  my_ptr(std::copy_exception(src)) // early C++0x drafts name
349  #endif
350  {}
351 }; // class tbb::internal::tbb_exception_ptr
352 
353 } // namespace internal
354 #endif /* !TBB_USE_CAPTURED_EXCEPTION */
355 
356 } // namespace tbb
357 
358 #endif /* __TBB_TASK_GROUP_CONTEXT */
359 
360 #endif /* __TBB_exception_H */
movable_exception< ExceptionData > self_type
#define __TBB_override
Definition: tbb_stddef.h:244
movable_exception(const movable_exception &src)
Exception for concurrent containers.
Definition: tbb_exception.h:32
movable_exception(const ExceptionData &data_)
captured_exception()
Used only by method move().
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
tbb_exception_ptr(const std::exception_ptr &src)
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads...
ExceptionData & data()
Exception for user-initiated abort.
Definition: tbb_exception.h:47
#define __TBB_THROW(e)
Definition: tbb_stddef.h:289
ExceptionData my_exception_data
User data.
#define __TBB_MAKE_EXCEPTION_PTR_PRESENT
Definition: tbb_config.h:352
void throw_self() __TBB_override
Throws this exception object.
Template that can be used to implement exception that transfers arbitrary ExceptionData to the root t...
Exception for repeated scheduling of the same task_handle.
Definition: tbb_exception.h:59
#define TBB_USE_EXCEPTIONS
Definition: tbb_config.h:478
const ExceptionData & data() const
void const char const char int ITT_FORMAT __itt_group_sync p
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
captured_exception(const captured_exception &src)
captured_exception(const char *name_, const char *info)
void throw_self() __TBB_override
Throws this exception object.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:102
const char * what() const __TBB_override
Returns the result of originally intercepted exception&#39;s what() method.
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
The graph class.
const char * my_exception_name
RTTI name of this class.
const char * my_exception_info
const char * what() const __TBB_override
Definition: tbb_misc.cpp:51
const char * name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
tbb_exception_ptr(const captured_exception &src)
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4()
Obsolete.
Definition: tbb_misc.cpp:113
The last enumerator tracks the number of defined IDs. It must remain the last one.
Definition: tbb_exception.h:97
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
#define __TBB_EXPORTED_FUNC
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
const char * my_exception_name
void __TBB_EXPORTED_FUNC throw_exception_v4(exception_id)
Gathers all throw operators in one place.
Definition: tbb_misc.cpp:117
STL namespace.
Exception for PPL locks.
Definition: tbb_exception.h:41
This class is used by TBB to propagate information about unhandled exceptions into the root thread...
Exception for missing wait on structured_task_group.
Definition: tbb_exception.h:53
void destroy() __TBB_override
Destroys objects created by the move() method.
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
movable_exception * move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
bool my_dynamic
Flag specifying whether this object has been dynamically allocated (by the move method) ...
Exception container that preserves the exact copy of the original exception.

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.