Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_SIGNAL_CATCHER_H_ |
| 18 | #define ART_RUNTIME_SIGNAL_CATCHER_H_ |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 19 | |
Narayan Kamath | eb71033 | 2017-05-10 11:48:46 +0100 | [diff] [blame] | 20 | #include "android-base/unique_fd.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 21 | #include "base/mutex.h" |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | class Runtime; |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 26 | class SignalSet; |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 27 | class Thread; |
| 28 | |
| 29 | /* |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame] | 30 | * A daemon thread that catches signals and does something useful. For |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 31 | * example, when a SIGQUIT (Ctrl-\) arrives, we suspend and dump the |
| 32 | * status of all threads. |
| 33 | */ |
| 34 | class SignalCatcher { |
| 35 | public: |
Andreas Gampe | 53af040 | 2018-05-03 10:40:37 -0700 | [diff] [blame] | 36 | SignalCatcher(); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 37 | ~SignalCatcher(); |
| 38 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 39 | void HandleSigQuit() REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_, |
| 40 | !Locks::thread_suspend_count_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 41 | |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 42 | |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 43 | private: |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 44 | // NO_THREAD_SAFETY_ANALYSIS for static function calling into member function with excludes lock. |
| 45 | static void* Run(void* arg) NO_THREAD_SAFETY_ANALYSIS; |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 46 | |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 47 | void HandleSigUsr1(); |
| 48 | void Output(const std::string& s); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 49 | void SetHaltFlag(bool new_value) REQUIRES(!lock_); |
| 50 | bool ShouldHalt() REQUIRES(!lock_); |
| 51 | int WaitForSignal(Thread* self, SignalSet& signals) REQUIRES(!lock_); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 52 | |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 53 | mutable Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 54 | ConditionVariable cond_ GUARDED_BY(lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 55 | bool halt_ GUARDED_BY(lock_); |
| 56 | pthread_t pthread_ GUARDED_BY(lock_); |
| 57 | Thread* thread_ GUARDED_BY(lock_); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | } // namespace art |
| 61 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 62 | #endif // ART_RUNTIME_SIGNAL_CATCHER_H_ |