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 #ifndef __TBB_exception_H
18 #define __TBB_exception_H
19 
20 #include "tbb_stddef.h"
21 #include <exception>
22 #include <new> // required for bad_alloc definition, operators new
23 #include <string> // required to construct std exception classes
24 
25 namespace tbb {
26 
28 class bad_last_alloc : public std::bad_alloc {
29 public:
30  const char* what() const throw() __TBB_override;
31 #if __TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN
32  ~bad_last_alloc() throw() __TBB_override {}
33 #endif
34 };
35 
37 class improper_lock : public std::exception {
38 public:
39  const char* what() const throw() __TBB_override;
40 };
41 
43 class user_abort : public std::exception {
44 public:
45  const char* what() const throw() __TBB_override;
46 };
47 
49 class missing_wait : public std::exception {
50 public:
51  const char* what() const throw() __TBB_override;
52 };
53 
55 class invalid_multiple_scheduling : public std::exception {
56 public:
57  const char* what() const throw() __TBB_override;
58 };
59 
60 namespace internal {
63 
78  eid_reserved, // free slot for backward compatibility, can be reused.
84 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
85  // This id is used only from inside the library and only for support of CPF functionality.
86  // So, if we drop the functionality, eid_reserved1 can be safely renamed and reused.
87  eid_blocking_thread_join_impossible = eid_reserved1,
88 #endif
91 
94 };
95 
97 
100 
102 inline void throw_exception ( exception_id eid ) { throw_exception_v4(eid); }
103 
104 } // namespace internal
105 } // namespace tbb
106 
107 #if __TBB_TASK_GROUP_CONTEXT
108 #include "tbb_allocator.h"
109 #include <typeinfo> //for typeid
110 
111 namespace tbb {
112 
114 
134 class tbb_exception : public std::exception
135 {
139  void* operator new ( size_t );
140 
141 public:
142 #if __clang__
143  // At -O3 or even -O2 optimization level, Clang may fully throw away an empty destructor
144  // of tbb_exception from destructors of derived classes. As a result, it does not create
145  // vtable for tbb_exception, which is a required part of TBB binary interface.
146  // Making the destructor non-empty (with just a semicolon) prevents that optimization.
147  ~tbb_exception() throw() { /* keep the semicolon! */ ; }
148 #endif
149 
151 
152  virtual tbb_exception* move() throw() = 0;
153 
155 
157  virtual void destroy() throw() = 0;
158 
160 
164  virtual void throw_self() = 0;
165 
167  virtual const char* name() const throw() = 0;
168 
170  virtual const char* what() const throw() __TBB_override = 0;
171 
178  void operator delete ( void* p ) {
180  }
181 };
182 
184 
189 {
190 public:
192  : tbb_exception(src), my_dynamic(false)
193  {
194  set(src.my_exception_name, src.my_exception_info);
195  }
196 
197  captured_exception( const char* name_, const char* info )
198  : my_dynamic(false)
199  {
200  set(name_, info);
201  }
202 
204 
205  captured_exception& operator= ( const captured_exception& src ) {
206  if ( this != &src ) {
207  clear();
208  set(src.my_exception_name, src.my_exception_info);
209  }
210  return *this;
211  }
212 
214 
215  void __TBB_EXPORTED_METHOD destroy() throw() __TBB_override;
216 
218 
219  const char* __TBB_EXPORTED_METHOD name() const throw() __TBB_override;
220 
221  const char* __TBB_EXPORTED_METHOD what() const throw() __TBB_override;
222 
223  void __TBB_EXPORTED_METHOD set( const char* name, const char* info ) throw();
224  void __TBB_EXPORTED_METHOD clear() throw();
225 
226 private:
229 
231  static captured_exception* allocate( const char* name, const char* info );
232 
234  const char* my_exception_name;
235  const char* my_exception_info;
236 };
237 
239 
243 template<typename ExceptionData>
245 {
247 
248 public:
249  movable_exception( const ExceptionData& data_ )
250  : my_exception_data(data_)
251  , my_dynamic(false)
252  , my_exception_name(
254  typeid(self_type).name()
255 #else /* !TBB_USE_EXCEPTIONS */
256  "movable_exception"
257 #endif /* !TBB_USE_EXCEPTIONS */
258  )
259  {}
260 
261  movable_exception( const movable_exception& src ) throw ()
262  : tbb_exception(src)
263  , my_exception_data(src.my_exception_data)
264  , my_dynamic(false)
265  , my_exception_name(src.my_exception_name)
266  {}
267 
268  ~movable_exception() throw() {}
269 
270  const movable_exception& operator= ( const movable_exception& src ) {
271  if ( this != &src ) {
272  my_exception_data = src.my_exception_data;
273  my_exception_name = src.my_exception_name;
274  }
275  return *this;
276  }
277 
278  ExceptionData& data() throw() { return my_exception_data; }
279 
280  const ExceptionData& data() const throw() { return my_exception_data; }
281 
282  const char* name() const throw() __TBB_override { return my_exception_name; }
283 
284  const char* what() const throw() __TBB_override { return "tbb::movable_exception"; }
285 
288  if ( e ) {
289  ::new (e) movable_exception(*this);
290  ((movable_exception*)e)->my_dynamic = true;
291  }
292  return (movable_exception*)e;
293  }
294  void destroy() throw() __TBB_override {
295  __TBB_ASSERT ( my_dynamic, "Method destroy can be called only on dynamically allocated movable_exceptions" );
296  if ( my_dynamic ) {
297  this->~movable_exception();
299  }
300  }
301  void throw_self() __TBB_override { __TBB_THROW( *this ); }
302 
303 protected:
305  ExceptionData my_exception_data;
306 
307 private:
310 
312 
313  const char* my_exception_name;
314 };
315 
316 #if !TBB_USE_CAPTURED_EXCEPTION
317 namespace internal {
318 
320 
323  std::exception_ptr my_ptr;
324 
325 public:
326  static tbb_exception_ptr* allocate();
327  static tbb_exception_ptr* allocate( const tbb_exception& tag );
329  static tbb_exception_ptr* allocate( captured_exception& src );
330 
332 
333  void destroy() throw();
334 
336  void throw_self() { std::rethrow_exception(my_ptr); }
337 
338 private:
339  tbb_exception_ptr( const std::exception_ptr& src ) : my_ptr(src) {}
342  my_ptr(std::make_exception_ptr(src)) // the final function name in C++11
343  #else
344  my_ptr(std::copy_exception(src)) // early C++0x drafts name
345  #endif
346  {}
347 }; // class tbb::internal::tbb_exception_ptr
348 
349 } // namespace internal
350 #endif /* !TBB_USE_CAPTURED_EXCEPTION */
351 
352 } // namespace tbb
353 
354 #endif /* __TBB_TASK_GROUP_CONTEXT */
355 
356 #endif /* __TBB_exception_H */
ExceptionData my_exception_data
User data.
The last enumerator tracks the number of defined IDs. It must remain the last one.
Definition: tbb_exception.h:93
const ExceptionData & data() const
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4()
Obsolete.
Definition: tbb_misc.cpp:109
const char * what() const __TBB_override
Definition: tbb_misc.cpp:47
#define __TBB_override
Definition: tbb_stddef.h:240
tbb_exception_ptr(const captured_exception &src)
const char * my_exception_info
bool my_dynamic
Flag specifying whether this object has been dynamically allocated (by the move method) ...
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
void throw_self() __TBB_override
Throws this exception object.
movable_exception< ExceptionData > self_type
void throw_self() __TBB_override
Throws this exception object.
#define __TBB_EXPORTED_FUNC
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
The graph class.
movable_exception * move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
const char * name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
movable_exception(const movable_exception &src)
void __TBB_EXPORTED_FUNC throw_exception_v4(exception_id)
Gathers all throw operators in one place.
Definition: tbb_misc.cpp:113
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
Exception for repeated scheduling of the same task_handle.
Definition: tbb_exception.h:55
#define __TBB_THROW(e)
Definition: tbb_stddef.h:285
Exception for PPL locks.
Definition: tbb_exception.h:37
captured_exception(const captured_exception &src)
captured_exception(const char *name_, const char *info)
tbb_exception_ptr(const std::exception_ptr &src)
This class is used by TBB to propagate information about unhandled exceptions into the root thread...
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define __TBB_MAKE_EXCEPTION_PTR_PRESENT
Definition: tbb_config.h:341
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:305
STL namespace.
Exception for missing wait on structured_task_group.
Definition: tbb_exception.h:49
ExceptionData & data()
Exception for concurrent containers.
Definition: tbb_exception.h:28
captured_exception()
Used only by method move().
const char * what() const __TBB_override
Returns the result of originally intercepted exception&#39;s what() method.
#define TBB_USE_EXCEPTIONS
Definition: tbb_config.h:467
Exception container that preserves the exact copy of the original exception.
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads...
Exception for user-initiated abort.
Definition: tbb_exception.h:43
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()
const char * my_exception_name
RTTI name of this class.
movable_exception(const ExceptionData &data_)
Template that can be used to implement exception that transfers arbitrary ExceptionData to the root t...
void destroy() __TBB_override
Destroys objects created by the move() method.
const char * my_exception_name

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.