Home ⌂Doc Index ◂Up ▴
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-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_exception_H
18 #define __TBB_exception_H
19 
20 #define __TBB_tbb_exception_H_include_area
22 
23 #include "tbb_stddef.h"
24 #include <exception>
25 #include <new> // required for bad_alloc definition, operators new
26 #include <string> // required to construct std exception classes
27 
28 namespace tbb {
29 
31 class bad_last_alloc : public std::bad_alloc {
32 public:
33  const char* what() const throw() __TBB_override;
34 #if __TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN
35  ~bad_last_alloc() throw() __TBB_override {}
36 #endif
37 };
38 
40 class __TBB_DEPRECATED improper_lock : public std::exception {
41 public:
42  const char* what() const throw() __TBB_override;
43 };
44 
46 class user_abort : public std::exception {
47 public:
48  const char* what() const throw() __TBB_override;
49 };
50 
52 class missing_wait : public std::exception {
53 public:
54  const char* what() const throw() __TBB_override;
55 };
56 
58 class invalid_multiple_scheduling : public std::exception {
59 public:
60  const char* what() const throw() __TBB_override;
61 };
62 
63 namespace internal {
66 
81  eid_reserved, // free slot for backward compatibility, can be reused.
87 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
88  // This id is used only from inside the library and only for support of CPF functionality.
89  // So, if we drop the functionality, eid_reserved1 can be safely renamed and reused.
90  eid_blocking_thread_join_impossible = eid_reserved1,
91 #endif
94 
97 };
98 
100 
103 
105 inline void throw_exception ( exception_id eid ) { throw_exception_v4(eid); }
106 
107 } // namespace internal
108 } // namespace tbb
109 
110 #if __TBB_TASK_GROUP_CONTEXT
111 #include "tbb_allocator.h"
112 #include <typeinfo> //for typeid
113 
114 namespace tbb {
115 
117 
137 class __TBB_DEPRECATED tbb_exception : public std::exception
138 {
142  void* operator new ( size_t );
143 
144 public:
145 #if __clang__
146  // At -O3 or even -O2 optimization level, Clang may fully throw away an empty destructor
147  // of tbb_exception from destructors of derived classes. As a result, it does not create
148  // vtable for tbb_exception, which is a required part of TBB binary interface.
149  // Making the destructor non-empty (with just a semicolon) prevents that optimization.
150  ~tbb_exception() throw() { /* keep the semicolon! */ ; }
151 #endif
152 
154 
155  virtual tbb_exception* move() throw() = 0;
156 
158 
160  virtual void destroy() throw() = 0;
161 
163 
167  virtual void throw_self() = 0;
168 
170  virtual const char* name() const throw() = 0;
171 
173  virtual const char* what() const throw() __TBB_override = 0;
174 
181  void operator delete ( void* p ) {
183  }
184 };
185 
187 
192 {
193 public:
195  : tbb_exception(src), my_dynamic(false)
196  {
197  set(src.my_exception_name, src.my_exception_info);
198  }
199 
200  captured_exception( const char* name_, const char* info )
201  : my_dynamic(false)
202  {
203  set(name_, info);
204  }
205 
207 
208  captured_exception& operator= ( const captured_exception& src ) {
209  if ( this != &src ) {
210  clear();
211  set(src.my_exception_name, src.my_exception_info);
212  }
213  return *this;
214  }
215 
217 
218  void __TBB_EXPORTED_METHOD destroy() throw() __TBB_override;
219 
220  void throw_self() __TBB_override { __TBB_THROW(*this); }
221 
222  const char* __TBB_EXPORTED_METHOD name() const throw() __TBB_override;
223 
224  const char* __TBB_EXPORTED_METHOD what() const throw() __TBB_override;
225 
226  void __TBB_EXPORTED_METHOD set( const char* name, const char* info ) throw();
227  void __TBB_EXPORTED_METHOD clear() throw();
228 
229 private:
231  captured_exception() : my_dynamic(), my_exception_name(), my_exception_info() {}
232 
234  static captured_exception* allocate( const char* name, const char* info );
235 
237  const char* my_exception_name;
238  const char* my_exception_info;
239 };
240 
242 
246 template<typename ExceptionData>
248 {
250 
251 public:
252  movable_exception( const ExceptionData& data_ )
253  : my_exception_data(data_)
254  , my_dynamic(false)
255  , my_exception_name(
257  typeid(self_type).name()
258 #else /* !TBB_USE_EXCEPTIONS */
259  "movable_exception"
260 #endif /* !TBB_USE_EXCEPTIONS */
261  )
262  {}
263 
264  movable_exception( const movable_exception& src ) throw ()
265  : tbb_exception(src)
266  , my_exception_data(src.my_exception_data)
267  , my_dynamic(false)
268  , my_exception_name(src.my_exception_name)
269  {}
270 
271  ~movable_exception() throw() {}
272 
273  const movable_exception& operator= ( const movable_exception& src ) {
274  if ( this != &src ) {
275  my_exception_data = src.my_exception_data;
276  my_exception_name = src.my_exception_name;
277  }
278  return *this;
279  }
280 
281  ExceptionData& data() throw() { return my_exception_data; }
282 
283  const ExceptionData& data() const throw() { return my_exception_data; }
284 
285  const char* name() const throw() __TBB_override { return my_exception_name; }
286 
287  const char* what() const throw() __TBB_override { return "tbb::movable_exception"; }
288 
291  if ( e ) {
292  ::new (e) movable_exception(*this);
293  ((movable_exception*)e)->my_dynamic = true;
294  }
295  return (movable_exception*)e;
296  }
297  void destroy() throw() __TBB_override {
298  __TBB_ASSERT ( my_dynamic, "Method destroy can be called only on dynamically allocated movable_exceptions" );
299  if ( my_dynamic ) {
300  this->~movable_exception();
302  }
303  }
304  void throw_self() __TBB_override { __TBB_THROW( *this ); }
305 
306 protected:
308  ExceptionData my_exception_data;
309 
310 private:
313 
315 
316  const char* my_exception_name;
317 };
318 
319 #if !TBB_USE_CAPTURED_EXCEPTION
320 namespace internal {
321 
323 
326  std::exception_ptr my_ptr;
327 
328 public:
329  static tbb_exception_ptr* allocate();
330  static tbb_exception_ptr* allocate( const tbb_exception& tag );
333 
335 
336  void destroy() throw();
337 
339  void throw_self() { std::rethrow_exception(my_ptr); }
340 
341 private:
342  tbb_exception_ptr( const std::exception_ptr& src ) : my_ptr(src) {}
345  my_ptr(std::make_exception_ptr(src)) // the final function name in C++11
346  #else
347  my_ptr(std::copy_exception(src)) // early C++0x drafts name
348  #endif
349  {}
350 }; // class tbb::internal::tbb_exception_ptr
351 
352 } // namespace internal
353 #endif /* !TBB_USE_CAPTURED_EXCEPTION */
354 
355 } // namespace tbb
356 
357 #endif /* __TBB_TASK_GROUP_CONTEXT */
358 
360 #undef __TBB_tbb_exception_H_include_area
361 
362 #endif /* __TBB_exception_H */
#define private
void destroy()
Destroys this objects.
The last enumerator tracks the number of defined IDs. It must remain the last one.
Definition: tbb_exception.h:96
void __TBB_EXPORTED_FUNC throw_exception_v4(exception_id)
Gathers all throw operators in one place.
Definition: tbb_misc.cpp:126
tbb_exception_ptr(const captured_exception &src)
captured_exception(const char *name_, const char *info)
Exception for concurrent containers.
Definition: tbb_exception.h:31
ExceptionData my_exception_data
User data.
movable_exception< ExceptionData > self_type
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads.
const char * what() const __TBB_override
Definition: tbb_misc.cpp:51
Exception for user-initiated abort.
Definition: tbb_exception.h:46
#define TBB_USE_EXCEPTIONS
Definition: tbb_config.h:463
bool my_dynamic
Flag specifying whether this object has been dynamically allocated (by the move method)
#define __TBB_DEPRECATED
Definition: tbb_config.h:636
ExceptionData & data()
#define __TBB_DEPRECATED_IN_VERBOSE_MODE
Definition: tbb_config.h:647
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
tbb_exception_ptr(const std::exception_ptr &src)
const char * what() const __TBB_override
Definition: tbb_misc.cpp:54
Template that can be used to implement exception that transfers arbitrary ExceptionData to the root t...
const ExceptionData & data() const
const char * what() const __TBB_override
Returns the result of originally intercepted exception's what() method.
const char * what() const __TBB_override
Definition: tbb_misc.cpp:55
void throw_self() __TBB_override
Throws this exception object.
void destroy() __TBB_override
Destroys objects created by the move() method.
#define __TBB_MAKE_EXCEPTION_PTR_PRESENT
Definition: tbb_config.h:337
movable_exception(const movable_exception &src)
Exception for repeated scheduling of the same task_handle.
Definition: tbb_exception.h:58
movable_exception(const ExceptionData &data_)
const char * my_exception_name
Exception for PPL locks.
Definition: tbb_exception.h:40
void const char const char int ITT_FORMAT __itt_group_sync p
const char * name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
#define __TBB_EXPORTED_FUNC
const char * what() const __TBB_override
Definition: tbb_misc.cpp:53
const char * my_exception_name
RTTI name of this class.
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:52
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
static tbb_exception_ptr * allocate()
#define __TBB_THROW(e)
Definition: tbb_stddef.h:285
#define __TBB_override
Definition: tbb_stddef.h:240
Exception container that preserves the exact copy of the original exception.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
captured_exception(const captured_exception &src)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4()
Obsolete.
Definition: tbb_misc.cpp:122
const char * my_exception_info
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
The graph class.
void throw_self()
Throws the contained exception .
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
movable_exception * move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319

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.