blob: 35e035f404c39706775b21a00b550e591e85e145 [file] [log] [blame]
Elliott Hughese27955c2011-08-26 15:21:24 -07001/*
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 Hughes8daa0922011-09-11 13:46:25 -070020#include "mutex.h"
Elliott Hughese27955c2011-08-26 15:21:24 -070021
22namespace art {
23
24class Runtime;
Elliott Hughes457005c2012-04-16 13:54:25 -070025class SignalSet;
Elliott Hughese27955c2011-08-26 15:21:24 -070026class Thread;
27
28/*
Elliott Hughes8cf5bc02012-02-02 16:32:16 -080029 * A daemon thread that catches signals and does something useful. For
Elliott Hughese27955c2011-08-26 15:21:24 -070030 * example, when a SIGQUIT (Ctrl-\) arrives, we suspend and dump the
31 * status of all threads.
32 */
33class SignalCatcher {
34 public:
Elliott Hughesff17f1f2012-01-24 18:12:29 -080035 explicit SignalCatcher(const std::string& stack_trace_file);
Elliott Hughese27955c2011-08-26 15:21:24 -070036 ~SignalCatcher();
37
Elliott Hughes94ce37a2011-10-18 15:07:48 -070038 void HandleSigQuit();
Elliott Hughes42ee1422011-09-06 12:33:32 -070039
Elliott Hughese27955c2011-08-26 15:21:24 -070040 private:
41 static void* Run(void* arg);
Elliott Hughese27955c2011-08-26 15:21:24 -070042
Elliott Hughes94ce37a2011-10-18 15:07:48 -070043 void HandleSigUsr1();
44 void Output(const std::string& s);
Elliott Hughes5fe594f2011-09-08 12:33:17 -070045 void SetHaltFlag(bool new_value);
46 bool ShouldHalt();
Elliott Hughesf8349362012-06-18 15:00:06 -070047 int WaitForSignal(Thread* self, SignalSet& signals);
Elliott Hughes5fe594f2011-09-08 12:33:17 -070048
Elliott Hughes94ce37a2011-10-18 15:07:48 -070049 std::string stack_trace_file_;
Elliott Hughesf8349362012-06-18 15:00:06 -070050
Elliott Hughes8daa0922011-09-11 13:46:25 -070051 mutable Mutex lock_;
Elliott Hughes5f791332011-09-15 17:45:30 -070052 ConditionVariable cond_;
Elliott Hughesf8349362012-06-18 15:00:06 -070053 bool halt_ GUARDED_BY(lock_);
54 pthread_t pthread_ GUARDED_BY(lock_);
55 Thread* thread_ GUARDED_BY(lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -070056};
57
58} // namespace art
59
60#endif // ART_SRC_SIGNAL_CATCHER_H_