tbb_assert_impl.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_assert_impl_H
#define _TBB_assert_impl_H
// IMPORTANT: To use assertion handling in TBB, exactly one of the TBB source files
// should #include tbb_assert_impl.h thus instantiating assertion handling routines.
// The intent of putting it to a separate file is to allow some tests to use it
// as well in order to avoid dependency on the library.
// include headers for required function declarations
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#if _MSC_VER
#include <crtdbg.h>
#endif
#if _MSC_VER >= 1400
#define __TBB_EXPORTED_FUNC __cdecl
#else
#define __TBB_EXPORTED_FUNC
#endif
#if __TBBMALLOC_BUILD
namespace rml { namespace internal {
#else
namespace tbb {
#endif
typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char * comment );
static assertion_handler_type assertion_handler;
assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler( assertion_handler_type new_handler ) {
assertion_handler_type old_handler = assertion_handler;
assertion_handler = new_handler;
return old_handler;
}
void __TBB_EXPORTED_FUNC assertion_failure( const char* filename, int line, const char* expression, const char* comment ) {
if( assertion_handler_type a = assertion_handler ) {
(*a)(filename,line,expression,comment);
} else {
static bool already_failed;
if( !already_failed ) {
already_failed = true;
fprintf( stderr, "Assertion %s failed on line %d of file %s\n",
expression, line, filename );
if( comment )
fprintf( stderr, "Detailed description: %s\n", comment );
#if _MSC_VER && _DEBUG
if(1 == _CrtDbgReport(_CRT_ASSERT, filename, line, "tbb_debug.dll", "%s\r\n%s", expression, comment?comment:""))
_CrtDbgBreak();
#else
fflush(stderr);
std::abort();
#endif
}
}
}
#if defined(_MSC_VER)&&_MSC_VER<1400
# define vsnprintf _vsnprintf
#endif
#if !__TBBMALLOC_BUILD && !__TBBBIND_BUILD
namespace internal {
void __TBB_EXPORTED_FUNC runtime_warning( const char* format, ... )
{
char str[1024]; memset(str, 0, 1024);
va_list args; va_start(args, format);
vsnprintf( str, 1024-1, format, args);
va_end(args);
fprintf( stderr, "TBB Warning: %s\n", str);
}
} // namespace internal
#endif
#if __TBBMALLOC_BUILD
}} // namespaces rml::internal
#else
} // namespace tbb
#endif
#endif /*_TBB_assert_impl_H*/
assertion_handler_type
void(* assertion_handler_type)(const char *filename, int line, const char *expression, const char *comment)
Type for an assertion handler.
Definition: tbb_stddef.h:127
__TBB_EXPORTED_FUNC
#define __TBB_EXPORTED_FUNC
Definition: tbb_assert_impl.h:37
void
void
Definition: ittnotify_static.h:91
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::set_assertion_handler
assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler(assertion_handler_type new_handler)
Set assertion handler and return previous value of it.
Definition: tbb_assert_impl.h:50
tbb::assertion_failure
void __TBB_EXPORTED_FUNC assertion_failure(const char *filename, int line, const char *expression, const char *comment)
Process an assertion failure.
Definition: tbb_assert_impl.h:56
tbb::assertion_handler
static assertion_handler_type assertion_handler
Definition: tbb_assert_impl.h:48
tbb::internal::runtime_warning
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
Definition: tbb_assert_impl.h:85
internal
Definition: _flow_graph_async_msg_impl.h:24

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.