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 | /* |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame^] | 28 | * A daemon thread that catches signals and does something useful. For |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 29 | * example, when a SIGQUIT (Ctrl-\) arrives, we suspend and dump the |
| 30 | * status of all threads. |
| 31 | */ |
| 32 | class SignalCatcher { |
| 33 | public: |
Elliott Hughes | ff17f1f | 2012-01-24 18:12:29 -0800 | [diff] [blame] | 34 | explicit SignalCatcher(const std::string& stack_trace_file); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 35 | ~SignalCatcher(); |
| 36 | |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 37 | void HandleSigQuit(); |
Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 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 | |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 42 | void HandleSigUsr1(); |
| 43 | void Output(const std::string& s); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 44 | void SetHaltFlag(bool new_value); |
| 45 | bool ShouldHalt(); |
Elliott Hughes | c2f8006 | 2011-11-07 11:57:51 -0800 | [diff] [blame] | 46 | int WaitForSignal(sigset_t& mask); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 47 | |
Elliott Hughes | 94ce37a | 2011-10-18 15:07:48 -0700 | [diff] [blame] | 48 | std::string stack_trace_file_; |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 49 | mutable Mutex lock_; |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 50 | bool halt_; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 51 | ConditionVariable cond_; |
Elliott Hughes | 8d768a9 | 2011-09-14 16:35:25 -0700 | [diff] [blame] | 52 | pthread_t pthread_; |
| 53 | Thread* thread_; |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | } // namespace art |
| 57 | |
| 58 | #endif // ART_SRC_SIGNAL_CATCHER_H_ |