summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian McCarthy <amccarth@google.com>2017-09-20 18:09:39 +0000
committerAdrian McCarthy <amccarth@google.com>2017-09-20 18:09:39 +0000
commit6c84ffbf5fd9d50995eee0a8fbf9efafe08790d7 (patch)
tree5204c03fbb03e92c8b1b67e0fa359d3f48b2d062
parentb9be53634c872979cad369808313b0aad143fed9 (diff)
downloadbcm5719-llvm-6c84ffbf5fd9d50995eee0a8fbf9efafe08790d7.tar.gz
bcm5719-llvm-6c84ffbf5fd9d50995eee0a8fbf9efafe08790d7.zip
Fix the SIGINT handlers
1. Fix a data race (g_interrupt_sent flag usage was not thread safe, signals can be handled on arbitrary threads) 2. exit() is not signal-safe, replaced it with the signal-safe equivalent _exit() (This differs from the patch on Phabrictor because I had to add `#include <atomic>` to get the definition of `std::atomic_flag`.) patch by lemo Differential Revision: https://reviews.llvm.org/D37926 llvm-svn: 313785
-rw-r--r--lldb/tools/driver/Driver.cpp10
-rw-r--r--lldb/tools/lldb-mi/MIDriverMain.cpp8
2 files changed, 9 insertions, 9 deletions
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index 102ba775da9..7e1dec7a34f 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -9,6 +9,7 @@
#include "Driver.h"
+#include <atomic>
#include <csignal>
#include <fcntl.h>
#include <limits.h>
@@ -1177,17 +1178,16 @@ void sigwinch_handler(int signo) {
}
void sigint_handler(int signo) {
- static bool g_interrupt_sent = false;
+ static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
if (g_driver) {
- if (!g_interrupt_sent) {
- g_interrupt_sent = true;
+ if (!g_interrupt_sent.test_and_set()) {
g_driver->GetDebugger().DispatchInputInterrupt();
- g_interrupt_sent = false;
+ g_interrupt_sent.clear();
return;
}
}
- exit(signo);
+ _exit(signo);
}
void sigtstp_handler(int signo) {
diff --git a/lldb/tools/lldb-mi/MIDriverMain.cpp b/lldb/tools/lldb-mi/MIDriverMain.cpp
index be01f1d9779..eda67782ad6 100644
--- a/lldb/tools/lldb-mi/MIDriverMain.cpp
+++ b/lldb/tools/lldb-mi/MIDriverMain.cpp
@@ -33,6 +33,7 @@
// Third party headers:
#include "lldb/API/SBHostOS.h"
+#include <atomic>
#include <csignal>
#include <stdio.h>
@@ -72,14 +73,13 @@ void sigint_handler(int vSigno) {
#ifdef _WIN32 // Restore handler as it is not persistent on Windows
signal(SIGINT, sigint_handler);
#endif
- static bool g_interrupt_sent = false;
+ static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
CMIDriverMgr &rDriverMgr = CMIDriverMgr::Instance();
lldb::SBDebugger *pDebugger = rDriverMgr.DriverGetTheDebugger();
if (pDebugger != nullptr) {
- if (!g_interrupt_sent) {
- g_interrupt_sent = true;
+ if (!g_interrupt_sent.test_and_set()) {
pDebugger->DispatchInputInterrupt();
- g_interrupt_sent = false;
+ g_interrupt_sent.clear();
}
}
OpenPOWER on IntegriCloud