diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-04 19:20:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-08 19:02:26 +0000 |
commit | 81ad626541db97eb356e2c1d4a20eb2a26a766ab (patch) | |
tree | 311b6a8987c32b1e1dcbab65c54cfac3fdb56175 /contrib/llvm-project/llvm/lib/Support/Signals.cpp | |
parent | 5fff09660e06a66bed6482da9c70df328e16bbb6 (diff) | |
parent | 145449b1e420787bb99721a429341fa6be3adfb6 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/Signals.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/Signals.cpp | 18 |
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)) |