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 bool expected = false;
64 while (gErrorBooking[i].compare_exchange_strong(expected, true) == false) {
65 ++i;
67 throw std::runtime_error("Too many o2::framework::runtime_error thrown without proper cleanup.");
68 }
69 }
70 va_list args;
71 va_start(args, format);
72 vsnprintf(gError[i].what, RuntimeError::MAX_RUNTIME_ERROR_SIZE, format, args);
73 va_end(args);
74 gError[i].maxBacktrace = canDumpBacktrace() ? backtrace(gError[i].backtrace, BacktraceHelpers::MAX_BACKTRACE_SIZE) : 0;
75 return RuntimeErrorRef{i};
76}
77
79{
80 int i = 0;
81 bool expected = false;
82 while (gErrorBooking[i].compare_exchange_strong(expected, true) == false) {
83 ++i;
84 }
85 strncpy(gError[i].what, s, RuntimeError::MAX_RUNTIME_ERROR_SIZE);
86 gError[i].maxBacktrace = canDumpBacktrace() ? backtrace(gError[i].backtrace, BacktraceHelpers::MAX_BACKTRACE_SIZE) : 0;
87 return RuntimeErrorRef{i};
88}
89
91{
92 throw ref;
93}
94
95} // namespace o2::framework
int32_t i
GLint ref
Definition glcorearb.h:291
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
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