Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "runtime_callbacks.h" |
| 18 | |
| 19 | #include <algorithm> |
| 20 | |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame^] | 21 | #include "base/macros.h" |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 22 | #include "class_linker.h" |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 23 | #include "thread.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | void RuntimeCallbacks::AddThreadLifecycleCallback(ThreadLifecycleCallback* cb) { |
| 28 | thread_callbacks_.push_back(cb); |
| 29 | } |
| 30 | |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame^] | 31 | template <typename T> |
| 32 | ALWAYS_INLINE |
| 33 | static inline void Remove(T* cb, std::vector<T*>* data) { |
| 34 | auto it = std::find(data->begin(), data->end(), cb); |
| 35 | if (it != data->end()) { |
| 36 | data->erase(it); |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame^] | 40 | void RuntimeCallbacks::RemoveThreadLifecycleCallback(ThreadLifecycleCallback* cb) { |
| 41 | Remove(cb, &thread_callbacks_); |
| 42 | } |
| 43 | |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 44 | void RuntimeCallbacks::ThreadStart(Thread* self) { |
| 45 | for (ThreadLifecycleCallback* cb : thread_callbacks_) { |
| 46 | cb->ThreadStart(self); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void RuntimeCallbacks::ThreadDeath(Thread* self) { |
| 51 | for (ThreadLifecycleCallback* cb : thread_callbacks_) { |
| 52 | cb->ThreadDeath(self); |
| 53 | } |
| 54 | } |
| 55 | |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 56 | void RuntimeCallbacks::AddClassLoadCallback(ClassLoadCallback* cb) { |
| 57 | class_callbacks_.push_back(cb); |
| 58 | } |
| 59 | |
| 60 | void RuntimeCallbacks::RemoveClassLoadCallback(ClassLoadCallback* cb) { |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame^] | 61 | Remove(cb, &class_callbacks_); |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void RuntimeCallbacks::ClassLoad(Handle<mirror::Class> klass) { |
| 65 | for (ClassLoadCallback* cb : class_callbacks_) { |
| 66 | cb->ClassLoad(klass); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void RuntimeCallbacks::ClassPrepare(Handle<mirror::Class> temp_klass, Handle<mirror::Class> klass) { |
| 71 | for (ClassLoadCallback* cb : class_callbacks_) { |
| 72 | cb->ClassPrepare(temp_klass, klass); |
| 73 | } |
| 74 | } |
| 75 | |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame^] | 76 | void RuntimeCallbacks::AddRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) { |
| 77 | sigquit_callbacks_.push_back(cb); |
| 78 | } |
| 79 | |
| 80 | void RuntimeCallbacks::RemoveRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) { |
| 81 | Remove(cb, &sigquit_callbacks_); |
| 82 | } |
| 83 | |
| 84 | void RuntimeCallbacks::SigQuit() { |
| 85 | for (RuntimeSigQuitCallback* cb : sigquit_callbacks_) { |
| 86 | cb->SigQuit(); |
| 87 | } |
| 88 | } |
| 89 | |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 90 | } // namespace art |