[PATCH] D122067: [libSupport] make CallBacksToRun static local
Mehdi AMINI via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 19 13:36:12 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG129311ac0bbb: [libSupport] make CallBacksToRun static local (authored by tal.kedar, committed by mehdi_amini).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D122067/new/
https://reviews.llvm.org/D122067
Files:
llvm/lib/Support/Signals.cpp
Index: llvm/lib/Support/Signals.cpp
===================================================================
--- llvm/lib/Support/Signals.cpp
+++ llvm/lib/Support/Signals.cpp
@@ -29,6 +29,7 @@
#include "llvm/Support/Program.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
+#include <array>
#include <vector>
//===----------------------------------------------------------------------===//
@@ -80,12 +81,20 @@
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))
@@ -100,7 +109,7 @@
// 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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122067.416733.patch
Type: text/x-patch
Size: 1761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220319/063d6383/attachment.bin>
More information about the llvm-commits
mailing list