1// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_THREAD_INTERRUPTER_H_
6#define RUNTIME_VM_THREAD_INTERRUPTER_H_
7
8#include "vm/allocation.h"
9#include "vm/os_thread.h"
10#include "vm/signal_handler.h"
11#include "vm/thread.h"
12
13namespace dart {
14
15struct InterruptedThreadState {
16 uintptr_t pc;
17 uintptr_t csp;
18 uintptr_t dsp;
19 uintptr_t fp;
20 uintptr_t lr;
21};
22
23class ThreadInterrupter : public AllStatic {
24 public:
25 static void Init();
26
27 static void Startup();
28 static void Cleanup();
29
30 // Delay between interrupts.
31 static void SetInterruptPeriod(intptr_t period);
32
33 // Wake up the thread interrupter thread.
34 static void WakeUp();
35
36 // Interrupt a thread.
37 static void InterruptThread(OSThread* thread);
38
39 private:
40 static constexpr intptr_t kMaxThreads = 4096;
41 static bool initialized_;
42 static bool shutdown_;
43 static bool thread_running_;
44 static bool woken_up_;
45 static ThreadJoinId interrupter_thread_id_;
46 static Monitor* monitor_;
47 static intptr_t interrupt_period_;
48 static intptr_t current_wait_time_;
49
50 static bool InDeepSleep() {
51 return current_wait_time_ == Monitor::kNoTimeout;
52 }
53
54 static void ThreadMain(uword parameters);
55
56 static void InstallSignalHandler();
57
58 static void RemoveSignalHandler();
59
60 friend class ThreadInterrupterVisitIsolates;
61};
62
63} // namespace dart
64
65#endif // RUNTIME_VM_THREAD_INTERRUPTER_H_
66

source code of dart_sdk/runtime/vm/thread_interrupter.h