1 /* 2 Copyright (c) 2005-2021 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 #include "oneapi/tbb/detail/_config.h" 21 22 #include <cstdio> 23 #include <cstdlib> 24 #include <cstring> 25 #include <cstdarg> 26 #if _MSC_VER && _DEBUG 27 #include <crtdbg.h> 28 #endif 29 30 #include <mutex> 31 32 namespace tbb { 33 namespace detail { 34 namespace r1 { 35 36 // TODO: consider extension for formatted error description string 37 static void assertion_failure_impl(const char* location, int line, const char* expression, const char* comment) { 38 39 std::fprintf(stderr, "Assertion %s failed (located in the %s function, line in file: %d)\n", 40 expression, location, line); 41 42 if (comment) { 43 std::fprintf(stderr, "Detailed description: %s\n", comment); 44 } 45 #if _MSC_VER && _DEBUG 46 if (1 == _CrtDbgReport(_CRT_ASSERT, location, line, "tbb_debug.dll", "%s\r\n%s", expression, comment?comment:"")) { 47 _CrtDbgBreak(); 48 } else 49 #endif 50 { 51 std::fflush(stderr); 52 std::abort(); 53 } 54 } 55 56 void __TBB_EXPORTED_FUNC assertion_failure(const char* location, int line, const char* expression, const char* comment) { 57 static std::once_flag flag; 58 std::call_once(flag, [&](){ assertion_failure_impl(location, line, expression, comment); }); 59 } 60 61 //! Report a runtime warning. 62 void runtime_warning( const char* format, ... ) { 63 char str[1024]; std::memset(str, 0, 1024); 64 va_list args; va_start(args, format); 65 vsnprintf( str, 1024-1, format, args); 66 va_end(args); 67 fprintf(stderr, "TBB Warning: %s\n", str); 68 } 69 70 } // namespace r1 71 } // namespace detail 72 } // namespace tbb 73 74 #endif // __TBB_assert_impl_H 75 76