ART: Add SigQuit Callback
Add callback being triggered when the runtime handles SigQuit.
Bug: 31684920
Test: m test-art-host-gtest-runtime_callbacks_test
Change-Id: I23e3b256c654b6078c79b3897439d893ea79d96e
diff --git a/runtime/runtime_callbacks.cc b/runtime/runtime_callbacks.cc
index ee9edda..cd38ead 100644
--- a/runtime/runtime_callbacks.cc
+++ b/runtime/runtime_callbacks.cc
@@ -18,6 +18,7 @@
#include <algorithm>
+#include "base/macros.h"
#include "class_linker.h"
#include "thread.h"
@@ -27,13 +28,19 @@
thread_callbacks_.push_back(cb);
}
-void RuntimeCallbacks::RemoveThreadLifecycleCallback(ThreadLifecycleCallback* cb) {
- auto it = std::find(thread_callbacks_.begin(), thread_callbacks_.end(), cb);
- if (it != thread_callbacks_.end()) {
- thread_callbacks_.erase(it);
+template <typename T>
+ALWAYS_INLINE
+static inline void Remove(T* cb, std::vector<T*>* data) {
+ auto it = std::find(data->begin(), data->end(), cb);
+ if (it != data->end()) {
+ data->erase(it);
}
}
+void RuntimeCallbacks::RemoveThreadLifecycleCallback(ThreadLifecycleCallback* cb) {
+ Remove(cb, &thread_callbacks_);
+}
+
void RuntimeCallbacks::ThreadStart(Thread* self) {
for (ThreadLifecycleCallback* cb : thread_callbacks_) {
cb->ThreadStart(self);
@@ -51,10 +58,7 @@
}
void RuntimeCallbacks::RemoveClassLoadCallback(ClassLoadCallback* cb) {
- auto it = std::find(class_callbacks_.begin(), class_callbacks_.end(), cb);
- if (it != class_callbacks_.end()) {
- class_callbacks_.erase(it);
- }
+ Remove(cb, &class_callbacks_);
}
void RuntimeCallbacks::ClassLoad(Handle<mirror::Class> klass) {
@@ -69,4 +73,18 @@
}
}
+void RuntimeCallbacks::AddRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) {
+ sigquit_callbacks_.push_back(cb);
+}
+
+void RuntimeCallbacks::RemoveRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) {
+ Remove(cb, &sigquit_callbacks_);
+}
+
+void RuntimeCallbacks::SigQuit() {
+ for (RuntimeSigQuitCallback* cb : sigquit_callbacks_) {
+ cb->SigQuit();
+ }
+}
+
} // namespace art