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

Copyright © 2005-2018 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.