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 | |
| 17 | #ifndef ART_SRC_SIGNAL_CATCHER_H_ |
| 18 | #define ART_SRC_SIGNAL_CATCHER_H_ |
| 19 | |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 20 | #include "mutex.h" |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | class Runtime; |
| 25 | class Thread; |
| 26 | |
| 27 | /* |
| 28 | * A thread that catches signals and does something useful. For |
| 29 | * example, when a SIGQUIT (Ctrl-\) arrives, we suspend and dump the |
| 30 | * status of all threads. |
| 31 | */ |
| 32 | class SignalCatcher { |
| 33 | public: |
| 34 | SignalCatcher(); |
| 35 | ~SignalCatcher(); |
| 36 | |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 37 | static void HandleSigQuit(); |
| 38 | |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 39 | private: |
| 40 | static void* Run(void* arg); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 41 | static void HandleSigUsr1(); |
| 42 | |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 43 | void SetHaltFlag(bool new_value); |
| 44 | bool ShouldHalt(); |
| 45 | |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 46 | mutable Mutex lock_; |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 47 | bool halt_; |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 48 | pthread_t thread_; |
| 49 | }; |
| 50 | |
| 51 | } // namespace art |
| 52 | |
| 53 | #endif // ART_SRC_SIGNAL_CATCHER_H_ |