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

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.