Project
Loading...
Searching...
No Matches
RuntimeError.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#include <cstdio>
15#include <climits>
16#include <atomic>
17#include <cstdarg>
18#include <cstring>
19#include <unistd.h>
20#include <cstdlib>
21#include <cxxabi.h>
22#include <execinfo.h>
23#include <stdexcept>
24
25namespace o2::framework
26{
27
28namespace
29{
30static RuntimeError gError[RuntimeError::MAX_RUNTIME_ERRORS];
31static std::atomic<bool> gErrorBooking[RuntimeError::MAX_RUNTIME_ERRORS];
32
33bool canDumpBacktrace()
34{
35#ifdef DPL_ENABLE_BACKTRACE
36 return true;
37#else
38 return false;
39#endif
40}
41} // namespace
42
44{
45 for (auto& i : gErrorBooking) {
46 i.store(false);
47 }
48}
49
51{
52 gErrorBooking[i].store(false);
53}
54
56{
57 return gError[ref.index];
58}
59
61{
62 int i = 0;
63 while (true) {
64 bool expected = false;
65 if (gErrorBooking[i].compare_exchange_strong(expected, true) == true) {
66 break;
67 }
68 ++i;
70 throw std::runtime_error("Too many o2::framework::runtime_error thrown without proper cleanup.");
71 }
72 }
73 va_list args;
74 va_start(args, format);
75 vsnprintf(gError[i].what, RuntimeError::MAX_RUNTIME_ERROR_SIZE, format, args);
76 va_end(args);
77 gError[i].maxBacktrace = canDumpBacktrace() ? backtrace(gError[i].backtrace, BacktraceHelpers::MAX_BACKTRACE_SIZE) : 0;
78 return RuntimeErrorRef{i};
79}
80
82{
83 int i = 0;
84 while (true) {
85 bool expected = false;
86 if (gErrorBooking[i].compare_exchange_strong(expected, true) == true) {
87 break;
88 }
89 ++i;
91 throw std::runtime_error("Too many o2::framework::runtime_error thrown without proper cleanup.");
92 }
93 }
94 strncpy(gError[i].what, s, RuntimeError::MAX_RUNTIME_ERROR_SIZE - 1);
95 gError[i].what[RuntimeError::MAX_RUNTIME_ERROR_SIZE - 1] = 0;
96 gError[i].maxBacktrace = canDumpBacktrace() ? backtrace(gError[i].backtrace, BacktraceHelpers::MAX_BACKTRACE_SIZE) : 0;
97 return RuntimeErrorRef{i};
98}
99
101{
102 throw ref;
103}
104
105} // namespace o2::framework
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
GLint ref
Definition glcorearb.h:291
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
RuntimeErrorRef runtime_error(const char *)
void throw_error(RuntimeErrorRef)
void clean_all_runtime_errors()
RuntimeError & error_from_ref(RuntimeErrorRef)
void clean_runtime_error(int i)
RuntimeErrorRef runtime_error_f(const char *,...)
static constexpr unsigned int MAX_BACKTRACE_SIZE
static constexpr unsigned int MAX_RUNTIME_ERRORS
static constexpr unsigned int MAX_RUNTIME_ERROR_SIZE
std::map< std::string, ID > expected