Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb_assert_impl.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_assert_impl_H
18 #define _TBB_assert_impl_H
19 
20 // IMPORTANT: To use assertion handling in TBB, exactly one of the TBB source files
21 // should #include tbb_assert_impl.h thus instantiating assertion handling routines.
22 // The intent of putting it to a separate file is to allow some tests to use it
23 // as well in order to avoid dependency on the library.
24 
25 // include headers for required function declarations
26 #include <cstdlib>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdarg.h>
30 #if _MSC_VER
31 #include <crtdbg.h>
32 #endif
33 
34 #if _MSC_VER >= 1400
35 #define __TBB_EXPORTED_FUNC __cdecl
36 #else
37 #define __TBB_EXPORTED_FUNC
38 #endif
39 
40 #if __TBBMALLOC_BUILD
41 namespace rml { namespace internal {
42 #else
43 namespace tbb {
44 #endif
45  typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char * comment );
47 
49 
52  assertion_handler = new_handler;
53  return old_handler;
54  }
55 
56  void __TBB_EXPORTED_FUNC assertion_failure( const char* filename, int line, const char* expression, const char* comment ) {
58  (*a)(filename,line,expression,comment);
59  } else {
60  static bool already_failed;
61  if( !already_failed ) {
62  already_failed = true;
63  fprintf( stderr, "Assertion %s failed on line %d of file %s\n",
64  expression, line, filename );
65  if( comment )
66  fprintf( stderr, "Detailed description: %s\n", comment );
67 #if _MSC_VER && _DEBUG
68  if(1 == _CrtDbgReport(_CRT_ASSERT, filename, line, "tbb_debug.dll", "%s\r\n%s", expression, comment?comment:""))
69  _CrtDbgBreak();
70 #else
71  fflush(stderr);
72  std::abort();
73 #endif
74  }
75  }
76  }
77 
78 #if defined(_MSC_VER)&&_MSC_VER<1400
79 # define vsnprintf _vsnprintf
80 #endif
81 
82 #if !__TBBMALLOC_BUILD && !__TBBBIND_BUILD
83  namespace internal {
85  void __TBB_EXPORTED_FUNC runtime_warning( const char* format, ... )
86  {
87  char str[1024]; memset(str, 0, 1024);
88  va_list args; va_start(args, format);
89  vsnprintf( str, 1024-1, format, args);
90  va_end(args);
91  fprintf( stderr, "TBB Warning: %s\n", str);
92  }
93  } // namespace internal
94 #endif
95 
96 #if __TBBMALLOC_BUILD
97 }} // namespaces rml::internal
98 #else
99 } // namespace tbb
100 #endif
101 
102 #endif /*_TBB_assert_impl_H*/
assertion_handler_type __TBB_EXPORTED_FUNC set_assertion_handler(assertion_handler_type new_handler)
Set assertion handler and return previous value of it.
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
static assertion_handler_type assertion_handler
#define __TBB_EXPORTED_FUNC
The graph class.
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
void __TBB_EXPORTED_FUNC assertion_failure(const char *filename, int line, const char *expression, const char *comment)
Process an assertion failure.

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.