blob: e4825a83313465b6adc35349ca7c8a6c188be7a3 [file] [log] [blame]
Nicolas Capens08c62002021-11-17 00:25:05 -05001// Copyright 2021 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "Reactor.hpp"
16
17#if defined(_WIN32)
18# ifndef WIN32_LEAN_AND_MEAN
19# define WIN32_LEAN_AND_MEAN
20# endif
21# include <windows.h>
22#endif
23
24#include <mutex>
25
26namespace rr {
27
28// Reports a failed Reactor Assert()
29void failedAssert(const char *expression, const char *file, unsigned int line, const char *func)
30{
31 // Since multple threads could fail an Assert() simultaneously, enter a critical section.
32 static std::mutex m;
33 std::scoped_lock lock(m);
34
35 fflush(stdout);
36
37 char string[1024];
38 snprintf(string, sizeof(string),
39 "Assertion failed: '%s'\n"
40 "At '%s:%d'\n"
41 "In '%s'\n\n",
42 expression, file, line, func);
43
44 fprintf(stderr, "%s", string);
45 fflush(stderr);
46
47#if defined(_WIN32)
48 OutputDebugStringA(string);
49#endif
50
51 assert(false && "Reactor Assert() failed");
52}
53
54} // namespace rr