tbb_exception.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __TBB_exception_H
#define __TBB_exception_H
#define __TBB_tbb_exception_H_include_area
#include "internal/_warning_suppress_enable_notice.h"
#include "tbb_stddef.h"
#include <exception>
#include <new> // required for bad_alloc definition, operators new
#include <string> // required to construct std exception classes
namespace tbb {
class bad_last_alloc : public std::bad_alloc {
public:
const char* what() const throw() __TBB_override;
#if __TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN
~bad_last_alloc() throw() __TBB_override {}
#endif
};
class __TBB_DEPRECATED improper_lock : public std::exception {
public:
const char* what() const throw() __TBB_override;
};
class user_abort : public std::exception {
public:
const char* what() const throw() __TBB_override;
};
class missing_wait : public std::exception {
public:
const char* what() const throw() __TBB_override;
};
class invalid_multiple_scheduling : public std::exception {
public:
const char* what() const throw() __TBB_override;
};
namespace internal {
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4();
enum exception_id {
eid_bad_alloc = 1,
eid_bad_last_alloc,
eid_nonpositive_step,
eid_out_of_range,
eid_segment_range_error,
eid_index_range_error,
eid_missing_wait,
eid_invalid_multiple_scheduling,
eid_improper_lock,
eid_possible_deadlock,
eid_operation_not_permitted,
eid_condvar_wait_failed,
eid_invalid_load_factor,
eid_reserved, // free slot for backward compatibility, can be reused.
eid_invalid_swap,
eid_reservation_length_error,
eid_invalid_key,
eid_user_abort,
eid_reserved1,
#if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
// This id is used only from inside the library and only for support of CPF functionality.
// So, if we drop the functionality, eid_reserved1 can be safely renamed and reused.
eid_blocking_thread_join_impossible = eid_reserved1,
#endif
eid_bad_tagged_msg_cast,
eid_max
};
void __TBB_EXPORTED_FUNC throw_exception_v4 ( exception_id );
inline void throw_exception ( exception_id eid ) { throw_exception_v4(eid); }
} // namespace internal
} // namespace tbb
#if __TBB_TASK_GROUP_CONTEXT
#include "tbb_allocator.h"
#include <typeinfo> //for typeid
namespace tbb {
class __TBB_DEPRECATED tbb_exception : public std::exception
{
void* operator new ( size_t );
public:
#if __clang__
// At -O3 or even -O2 optimization level, Clang may fully throw away an empty destructor
// of tbb_exception from destructors of derived classes. As a result, it does not create
// vtable for tbb_exception, which is a required part of TBB binary interface.
// Making the destructor non-empty (with just a semicolon) prevents that optimization.
~tbb_exception() throw() { /* keep the semicolon! */ ; }
#endif
virtual tbb_exception* move() throw() = 0;
virtual void destroy() throw() = 0;
virtual void throw_self() = 0;
virtual const char* name() const throw() = 0;
virtual const char* what() const throw() __TBB_override = 0;
void operator delete ( void* p ) {
internal::deallocate_via_handler_v3(p);
}
};
class __TBB_DEPRECATED captured_exception : public tbb_exception
{
public:
captured_exception( const captured_exception& src )
: tbb_exception(src), my_dynamic(false)
{
set(src.my_exception_name, src.my_exception_info);
}
captured_exception( const char* name_, const char* info )
: my_dynamic(false)
{
set(name_, info);
}
__TBB_EXPORTED_METHOD ~captured_exception() throw();
captured_exception& operator= ( const captured_exception& src ) {
if ( this != &src ) {
clear();
set(src.my_exception_name, src.my_exception_info);
}
return *this;
}
captured_exception* __TBB_EXPORTED_METHOD move() throw() __TBB_override;
void __TBB_EXPORTED_METHOD destroy() throw() __TBB_override;
void throw_self() __TBB_override { __TBB_THROW(*this); }
const char* __TBB_EXPORTED_METHOD name() const throw() __TBB_override;
const char* __TBB_EXPORTED_METHOD what() const throw() __TBB_override;
void __TBB_EXPORTED_METHOD set( const char* name, const char* info ) throw();
void __TBB_EXPORTED_METHOD clear() throw();
private:
captured_exception() : my_dynamic(), my_exception_name(), my_exception_info() {}
static captured_exception* allocate( const char* name, const char* info );
bool my_dynamic;
const char* my_exception_name;
const char* my_exception_info;
};
template<typename ExceptionData>
class __TBB_DEPRECATED movable_exception : public tbb_exception
{
typedef movable_exception<ExceptionData> self_type;
public:
movable_exception( const ExceptionData& data_ )
: my_exception_data(data_)
, my_dynamic(false)
, my_exception_name(
#if TBB_USE_EXCEPTIONS
typeid(self_type).name()
#else /* !TBB_USE_EXCEPTIONS */
"movable_exception"
#endif /* !TBB_USE_EXCEPTIONS */
)
{}
movable_exception( const movable_exception& src ) throw ()
: tbb_exception(src)
, my_exception_data(src.my_exception_data)
, my_dynamic(false)
, my_exception_name(src.my_exception_name)
{}
~movable_exception() throw() {}
const movable_exception& operator= ( const movable_exception& src ) {
if ( this != &src ) {
my_exception_data = src.my_exception_data;
my_exception_name = src.my_exception_name;
}
return *this;
}
ExceptionData& data() throw() { return my_exception_data; }
const ExceptionData& data() const throw() { return my_exception_data; }
const char* name() const throw() __TBB_override { return my_exception_name; }
const char* what() const throw() __TBB_override { return "tbb::movable_exception"; }
movable_exception* move() throw() __TBB_override {
void* e = internal::allocate_via_handler_v3(sizeof(movable_exception));
if ( e ) {
::new (e) movable_exception(*this);
((movable_exception*)e)->my_dynamic = true;
}
return (movable_exception*)e;
}
void destroy() throw() __TBB_override {
__TBB_ASSERT ( my_dynamic, "Method destroy can be called only on dynamically allocated movable_exceptions" );
if ( my_dynamic ) {
this->~movable_exception();
internal::deallocate_via_handler_v3(this);
}
}
void throw_self() __TBB_override { __TBB_THROW( *this ); }
protected:
ExceptionData my_exception_data;
private:
bool my_dynamic;
const char* my_exception_name;
};
#if !TBB_USE_CAPTURED_EXCEPTION
namespace internal {
class tbb_exception_ptr {
std::exception_ptr my_ptr;
public:
static tbb_exception_ptr* allocate();
static tbb_exception_ptr* allocate( const tbb_exception& tag );
static tbb_exception_ptr* allocate( captured_exception& src );
void destroy() throw();
void throw_self() { std::rethrow_exception(my_ptr); }
private:
tbb_exception_ptr( const std::exception_ptr& src ) : my_ptr(src) {}
tbb_exception_ptr( const captured_exception& src ) :
#if __TBB_MAKE_EXCEPTION_PTR_PRESENT
my_ptr(std::make_exception_ptr(src)) // the final function name in C++11
#else
my_ptr(std::copy_exception(src)) // early C++0x drafts name
#endif
{}
}; // class tbb::internal::tbb_exception_ptr
} // namespace internal
#endif /* !TBB_USE_CAPTURED_EXCEPTION */
} // namespace tbb
#endif /* __TBB_TASK_GROUP_CONTEXT */
#include "internal/_warning_suppress_disable_notice.h"
#undef __TBB_tbb_exception_H_include_area
#endif /* __TBB_exception_H */
tbb::improper_lock
Exception for PPL locks.
Definition: tbb_exception.h:40
__TBB_DEPRECATED
#define __TBB_DEPRECATED
Definition: tbb_config.h:637
tbb::internal::eid_improper_lock
Definition: tbb_exception.h:76
tbb::internal::tbb_exception_ptr::tbb_exception_ptr
tbb_exception_ptr(const captured_exception &src)
Definition: tbb_exception.h:343
tbb::internal::deallocate_via_handler_v3
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
Definition: cache_aligned_allocator.cpp:232
tbb::tbb_exception
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads.
Definition: tbb_exception.h:137
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::captured_exception::my_dynamic
bool my_dynamic
Definition: tbb_exception.h:236
tbb::internal::eid_index_range_error
Definition: tbb_exception.h:73
tbb::movable_exception::movable_exception
movable_exception(const movable_exception &src)
Definition: tbb_exception.h:264
tbb::internal::eid_condvar_wait_failed
Definition: tbb_exception.h:79
tbb::captured_exception::captured_exception
captured_exception(const captured_exception &src)
Definition: tbb_exception.h:194
tbb::internal::eid_nonpositive_step
Definition: tbb_exception.h:70
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::missing_wait
Exception for missing wait on structured_task_group.
Definition: tbb_exception.h:52
tbb::internal::eid_operation_not_permitted
Definition: tbb_exception.h:78
tbb::bad_last_alloc
Exception for concurrent containers.
Definition: tbb_exception.h:31
tbb::movable_exception::~movable_exception
~movable_exception()
Definition: tbb_exception.h:271
tbb::internal::throw_exception
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
Definition: tbb_exception.h:105
tbb::internal::eid_segment_range_error
Definition: tbb_exception.h:72
__TBB_MAKE_EXCEPTION_PTR_PRESENT
#define __TBB_MAKE_EXCEPTION_PTR_PRESENT
Definition: tbb_config.h:338
tbb::captured_exception::captured_exception
captured_exception(const char *name_, const char *info)
Definition: tbb_exception.h:200
__TBB_THROW
#define __TBB_THROW(e)
Definition: tbb_stddef.h:285
tbb::internal::eid_possible_deadlock
Definition: tbb_exception.h:77
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::throw_exception_v4
void __TBB_EXPORTED_FUNC throw_exception_v4(exception_id)
Gathers all throw operators in one place.
Definition: tbb_misc.cpp:126
tbb::bad_last_alloc::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:51
tbb::internal::tbb_exception_ptr::allocate
static tbb_exception_ptr * allocate()
tbb::invalid_multiple_scheduling::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:54
tbb::internal::eid_out_of_range
Definition: tbb_exception.h:71
tbb::internal::throw_bad_last_alloc_exception_v4
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4()
Obsolete.
Definition: tbb_misc.cpp:122
tbb::movable_exception
Template that can be used to implement exception that transfers arbitrary ExceptionData to the root t...
Definition: tbb_exception.h:247
private
#define private
Definition: scheduler_common.h:35
TBB_USE_EXCEPTIONS
#define TBB_USE_EXCEPTIONS
Definition: tbb_config.h:464
tbb::internal::exception_id
exception_id
Definition: tbb_exception.h:67
tbb::internal::eid_invalid_key
Definition: tbb_exception.h:84
tbb::internal::eid_invalid_swap
Definition: tbb_exception.h:82
tbb::captured_exception::my_exception_info
const char * my_exception_info
Definition: tbb_exception.h:238
tbb::internal::eid_bad_last_alloc
Definition: tbb_exception.h:69
tbb::internal::eid_bad_tagged_msg_cast
Definition: tbb_exception.h:92
tbb::internal::eid_reserved
Definition: tbb_exception.h:81
tbb::missing_wait::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:55
tbb::move
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
tbb::internal::tbb_exception_ptr::throw_self
void throw_self()
Throws the contained exception .
Definition: tbb_exception.h:339
tbb::captured_exception::my_exception_name
const char * my_exception_name
Definition: tbb_exception.h:237
tbb::invalid_multiple_scheduling
Exception for repeated scheduling of the same task_handle.
Definition: tbb_exception.h:58
tbb::user_abort::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:53
tbb::movable_exception::name
const char * name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
Definition: tbb_exception.h:285
tbb::movable_exception::move
movable_exception * move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
Definition: tbb_exception.h:289
_warning_suppress_disable_notice.h
tbb::movable_exception::destroy
void destroy() __TBB_override
Destroys objects created by the move() method.
Definition: tbb_exception.h:297
__TBB_override
#define __TBB_override
Definition: tbb_stddef.h:240
tbb::internal::allocate_via_handler_v3
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
Definition: cache_aligned_allocator.cpp:224
__TBB_EXPORTED_FUNC
#define __TBB_EXPORTED_FUNC
Definition: scalable_allocator.h:38
tbb::internal::eid_reserved1
Definition: tbb_exception.h:86
tbb::user_abort
Exception for user-initiated abort.
Definition: tbb_exception.h:46
tbb::internal::eid_bad_alloc
Definition: tbb_exception.h:68
tbb::internal::tbb_exception_ptr
Exception container that preserves the exact copy of the original exception.
Definition: tbb_exception.h:325
tbb::internal::eid_max
The last enumerator tracks the number of defined IDs. It must remain the last one.
Definition: tbb_exception.h:96
tbb::movable_exception::data
const ExceptionData & data() const
Definition: tbb_exception.h:283
tbb::internal::eid_user_abort
Definition: tbb_exception.h:85
tbb::internal::eid_invalid_multiple_scheduling
Definition: tbb_exception.h:75
tbb::internal::eid_reservation_length_error
Definition: tbb_exception.h:83
tbb::internal::eid_invalid_load_factor
Definition: tbb_exception.h:80
name
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
Definition: ittnotify_static.h:93
tbb_stddef.h
_warning_suppress_enable_notice.h
tbb::internal::tbb_exception_ptr::my_ptr
std::exception_ptr my_ptr
Definition: tbb_exception.h:326
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
__TBB_EXPORTED_METHOD
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
tbb::movable_exception::movable_exception
movable_exception(const ExceptionData &data_)
Definition: tbb_exception.h:252
tbb::internal::tbb_exception_ptr::tbb_exception_ptr
tbb_exception_ptr(const std::exception_ptr &src)
Definition: tbb_exception.h:342
tbb::movable_exception::my_exception_name
const char * my_exception_name
RTTI name of this class.
Definition: tbb_exception.h:316
tbb::captured_exception
This class is used by TBB to propagate information about unhandled exceptions into the root thread.
Definition: tbb_exception.h:191
tbb_allocator.h
tbb::movable_exception::throw_self
void throw_self() __TBB_override
Throws this exception object.
Definition: tbb_exception.h:304
tbb::internal::tbb_exception_ptr::destroy
void destroy()
Destroys this objects.
tbb::movable_exception::self_type
movable_exception< ExceptionData > self_type
Definition: tbb_exception.h:249
tbb::movable_exception::my_exception_data
ExceptionData my_exception_data
User data.
Definition: tbb_exception.h:308
tbb::internal::eid_missing_wait
Definition: tbb_exception.h:74
tbb::movable_exception::data
ExceptionData & data()
Definition: tbb_exception.h:281
tbb::movable_exception::my_dynamic
bool my_dynamic
Flag specifying whether this object has been dynamically allocated (by the move method)
Definition: tbb_exception.h:312
tbb::movable_exception::what
const char * what() const __TBB_override
Returns the result of originally intercepted exception's what() method.
Definition: tbb_exception.h:287

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.