aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/Signals.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/Signals.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/Signals.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/Signals.cpp b/contrib/llvm-project/llvm/lib/Support/Signals.cpp
index 1d61f2bf7525..a6fd845da869 100644
--- a/contrib/llvm-project/llvm/lib/Support/Signals.cpp
+++ b/contrib/llvm-project/llvm/lib/Support/Signals.cpp
@@ -15,7 +15,6 @@
#include "DebugOptions.h"
-#include "llvm/ADT/STLArrayExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/CommandLine.h"
@@ -23,15 +22,14 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Format.h"
-#include "llvm/Support/FormatAdapters.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Mutex.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
+#include <array>
#include <vector>
//===----------------------------------------------------------------------===//
@@ -83,12 +81,20 @@ struct CallbackAndCookie {
enum class Status { Empty, Initializing, Initialized, Executing };
std::atomic<Status> Flag;
};
+
static constexpr size_t MaxSignalHandlerCallbacks = 8;
-static CallbackAndCookie CallBacksToRun[MaxSignalHandlerCallbacks];
+
+// A global array of CallbackAndCookie may not compile with
+// -Werror=global-constructors in c++20 and above
+static std::array<CallbackAndCookie, MaxSignalHandlerCallbacks> &
+CallBacksToRun() {
+ static std::array<CallbackAndCookie, MaxSignalHandlerCallbacks> callbacks;
+ return callbacks;
+}
// Signal-safe.
void sys::RunSignalHandlers() {
- for (CallbackAndCookie &RunMe : CallBacksToRun) {
+ for (CallbackAndCookie &RunMe : CallBacksToRun()) {
auto Expected = CallbackAndCookie::Status::Initialized;
auto Desired = CallbackAndCookie::Status::Executing;
if (!RunMe.Flag.compare_exchange_strong(Expected, Desired))
@@ -103,7 +109,7 @@ void sys::RunSignalHandlers() {
// Signal-safe.
static void insertSignalHandler(sys::SignalHandlerCallback FnPtr,
void *Cookie) {
- for (CallbackAndCookie &SetMe : CallBacksToRun) {
+ for (CallbackAndCookie &SetMe : CallBacksToRun()) {
auto Expected = CallbackAndCookie::Status::Empty;
auto Desired = CallbackAndCookie::Status::Initializing;
if (!SetMe.Flag.compare_exchange_strong(Expected, Desired))