blob: 8d91a949330f18ab61a515fbd23227dbccee9de2 [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
20#include <pthread.h>
21
22namespace art {
23
Elliott Hughes5fe594f2011-09-08 12:33:17 -070024class Mutex;
Elliott Hughese27955c2011-08-26 15:21:24 -070025class Runtime;
26class Thread;
27
28/*
29 * A 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 SignalCatcher();
36 ~SignalCatcher();
37
Elliott Hughes42ee1422011-09-06 12:33:32 -070038 static void HandleSigQuit();
39
Elliott Hughese27955c2011-08-26 15:21:24 -070040 private:
41 static void* Run(void* arg);
Elliott Hughese27955c2011-08-26 15:21:24 -070042 static void HandleSigUsr1();
43
Elliott Hughes5fe594f2011-09-08 12:33:17 -070044 void SetHaltFlag(bool new_value);
45 bool ShouldHalt();
46
47 Mutex* lock_;
48 bool halt_;
Elliott Hughese27955c2011-08-26 15:21:24 -070049 pthread_t thread_;
50};
51
52} // namespace art
53
54#endif // ART_SRC_SIGNAL_CATCHER_H_