signal_catcher.h revision 00f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abac
1e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes/* 2e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * Copyright (C) 2008 The Android Open Source Project 3e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * 4e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * you may not use this file except in compliance with the License. 6e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * You may obtain a copy of the License at 7e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * 8e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * 10e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * Unless required by applicable law or agreed to in writing, software 11e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * See the License for the specific language governing permissions and 14e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * limitations under the License. 15e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes */ 16e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 17e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes#ifndef ART_SRC_SIGNAL_CATCHER_H_ 18e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes#define ART_SRC_SIGNAL_CATCHER_H_ 19e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 208daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes#include "mutex.h" 21e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 22e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesnamespace art { 23e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 24e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesclass Runtime; 25457005c557b8762475db3220ce5a747d629f975bElliott Hughesclass SignalSet; 26e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesclass Thread; 27e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 28e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes/* 298cf5bc0ab8742df107f0f4fc8ec0e991b6568f11Elliott Hughes * A daemon thread that catches signals and does something useful. For 30e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * example, when a SIGQUIT (Ctrl-\) arrives, we suspend and dump the 31e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes * status of all threads. 32e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes */ 33e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesclass SignalCatcher { 34e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes public: 35ff17f1fd3ff32f93e45588eb2b158832d73f9afaElliott Hughes explicit SignalCatcher(const std::string& stack_trace_file); 36e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes ~SignalCatcher(); 37e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 3800f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers void HandleSigQuit() LOCKS_EXCLUDED(GlobalSynchronization::mutator_lock_, 3900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers GlobalSynchronization::thread_list_lock_, 4000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers GlobalSynchronization::thread_suspend_count_lock_); 4100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers 4242ee14279065352a4b9a3e8028d02c567e847d05Elliott Hughes 43e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes private: 44e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes static void* Run(void* arg); 45e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 4694ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes void HandleSigUsr1(); 4794ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes void Output(const std::string& s); 485fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes void SetHaltFlag(bool new_value); 495fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes bool ShouldHalt(); 50f8349361a16a4e2796efe9f3586b994e8d4834e4Elliott Hughes int WaitForSignal(Thread* self, SignalSet& signals); 515fe594f576225dd7d333835e39c448a71ea9b433Elliott Hughes 5294ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes std::string stack_trace_file_; 53f8349361a16a4e2796efe9f3586b994e8d4834e4Elliott Hughes 548daa0929f08a3080ea64dbd4e997e72f411e6fc9Elliott Hughes mutable Mutex lock_; 555f79133a435ebcb20000370d56046fe01201dd80Elliott Hughes ConditionVariable cond_; 56f8349361a16a4e2796efe9f3586b994e8d4834e4Elliott Hughes bool halt_ GUARDED_BY(lock_); 57f8349361a16a4e2796efe9f3586b994e8d4834e4Elliott Hughes pthread_t pthread_ GUARDED_BY(lock_); 58f8349361a16a4e2796efe9f3586b994e8d4834e4Elliott Hughes Thread* thread_ GUARDED_BY(lock_); 59e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes}; 60e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 61e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes} // namespace art 62e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 63e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes#endif // ART_SRC_SIGNAL_CATCHER_H_ 64