signal_catcher.h revision 7940e44f4517de5e2634a7e07d58d0fb26160513
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
20#include "base/mutex.h"
21
22namespace art {
23
24class Runtime;
25class SignalSet;
26class Thread;
27
28/*
29 * A daemon thread that catches signals and does something useful. For
30 * example, when a SIGQUIT (Ctrl-\) arrives, we suspend and dump the
31 * status of all threads.
32 */
33class SignalCatcher {
34 public:
35  explicit SignalCatcher(const std::string& stack_trace_file);
36  ~SignalCatcher();
37
38  void HandleSigQuit() LOCKS_EXCLUDED(Locks::mutator_lock_,
39                                      Locks::thread_list_lock_,
40                                      Locks::thread_suspend_count_lock_);
41
42
43 private:
44  static void* Run(void* arg);
45
46  void HandleSigUsr1();
47  void Output(const std::string& s);
48  void SetHaltFlag(bool new_value);
49  bool ShouldHalt();
50  int WaitForSignal(Thread* self, SignalSet& signals);
51
52  std::string stack_trace_file_;
53
54  mutable Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
55  ConditionVariable cond_ GUARDED_BY(lock_);
56  bool halt_ GUARDED_BY(lock_);
57  pthread_t pthread_ GUARDED_BY(lock_);
58  Thread* thread_ GUARDED_BY(lock_);
59};
60
61}  // namespace art
62
63#endif  // ART_SRC_SIGNAL_CATCHER_H_
64