7 #include <condition_variable>
25 namespace diagnostics
{
41 class MachineCompiler
;
49 virtual ~Profiler() { }
63 ThreadState
* _main_thread_
;
65 uint64_t _start_time_
;
68 std::atomic
<Phase
> _phase_
;
72 virtual ~MachineState() { }
74 const ThreadState
* main_thread() {
82 void set_loader(Object
* loader
) {
86 const uint32_t hash_seed() {
90 const int exit_code() {
94 void exit_code(int code
) {
99 return _phase_
== eBooting
;
103 return _phase_
== eRunning
;
107 return _phase_
== eHalting
;
114 void set_start_time();
120 typedef std::list
<ThreadState
*> ThreadList
;
125 std::mutex threads_mutex_
;
126 uint32_t thread_ids_
;
129 Threads(Machine
* machine
)
136 virtual ~Threads() { }
138 ThreadState
* create_thread_state(const char* name
= NULL
);
139 void remove_thread_state(ThreadState
* thread_state
);
141 void after_fork_child(STATE
);
143 void each(STATE
, std::function
<void (STATE
, ThreadState
*)> f
);
147 MachineState
* _machine_state_
;
150 Configuration
* _configuration_
;
151 Environment
* _environment_
;
152 Diagnostics
* _diagnostics_
;
154 memory::Collector
* _collector_
;
158 jit::MachineCompiler
* _compiler_
;
159 ngDebugger
* _debugger_
;
160 Profiler
* _profiler_
;
163 static std::mutex _waiting_mutex_
;
164 static std::condition_variable _waiting_condition_
;
165 static std::atomic
<uint32_t> _threads_lock_
;
166 static std::atomic
<uint64_t> _halting_
;
167 static std::atomic
<bool> _stop_
;
170 Machine(int argc
, char** argv
);
173 std::mutex
& waiting_mutex() {
174 return _waiting_mutex_
;
177 std::condition_variable
& waiting_condition() {
178 return _waiting_condition_
;
181 std::atomic
<uint32_t>& threads_lock() {
182 return _threads_lock_
;
185 std::atomic
<uint64_t>& halting() {
189 std::atomic
<bool>& stop() {
193 MachineState
* const machine_state() {
194 return _machine_state_
;
197 Threads
* const threads() {
201 Configuration
* const configuration() {
202 return _configuration_
;
205 Environment
* const environment() const {
206 return _environment_
;
209 Diagnostics
* const diagnostics() {
210 return _diagnostics_
;
213 Memory
* const memory() {
217 memory::Collector
* const collector() {
221 Signals
* const signals() {
225 C_API
* const c_api() {
229 jit::MachineCompiler
* const compiler() {
233 Profiler
* const profiler() {
237 Console
* const console() {
243 int halt(STATE
, Object
* exit_code
);
244 int halt(int exit_code
=0);
245 int halt(STATE
, int exit_code
=0);
247 void before_fork(STATE
);
248 void after_fork_parent(STATE
);
249 void after_fork_child(STATE
);
251 void trace_objects(STATE
, std::function
<void (STATE
, Object
**)> f
);
253 Diagnostics
* start_diagnostics(STATE
);
254 void report_diagnostics(diagnostics::Diagnostic
* diagnostic
);
256 jit::MachineCompiler
* start_compiler(STATE
);
258 void halt_console(STATE
);
259 void halt_profiler(STATE
);
260 void halt_debugger(STATE
);
261 void halt_compiler(STATE
);
262 void halt_c_api(STATE
);
263 void halt_codedb(STATE
);
264 void halt_signals(STATE
);
265 void halt_collector(STATE
);
266 void halt_memory(STATE
);
267 void halt_threads(STATE
);
268 void halt_diagnostics(STATE
);
269 void halt_configuration(STATE
);
270 void halt_environment(STATE
);
271 void halt_logger(STATE
);
272 void halt_machine_state(STATE
);
273 void halt_machine(STATE
);