-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy paththread_interrupter.h
75 lines (56 loc) · 1.89 KB
/
thread_interrupter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_VM_THREAD_INTERRUPTER_H_
#define RUNTIME_VM_THREAD_INTERRUPTER_H_
#include "vm/allocation.h"
#include "vm/os_thread.h"
#include "vm/signal_handler.h"
#include "vm/thread.h"
namespace dart {
struct InterruptedThreadState {
uintptr_t pc;
uintptr_t csp;
uintptr_t dsp;
uintptr_t fp;
uintptr_t lr;
};
class ThreadInterrupter : public AllStatic {
public:
static void Init(intptr_t period);
static void Startup();
static void Cleanup();
// Delay between interrupts.
//
// Warning: This method will have no effect if
// |ThreadInterrupter::initialized_| is false.
static void SetInterruptPeriod(intptr_t period);
// Wake up the thread interrupter thread.
static void WakeUp();
// Interrupt a thread.
static void InterruptThread(OSThread* thread);
// Prepare current thread for handling interrupts. Returns
// opaque pointer to the allocated state (if any).
static void* PrepareCurrentThread();
// Cleanup any state which was created by |PrepareCurrentThread|.
static void CleanupCurrentThreadState(void* state);
private:
static constexpr intptr_t kMaxThreads = 4096;
static bool initialized_;
static bool shutdown_;
static bool thread_running_;
static bool woken_up_;
static ThreadJoinId interrupter_thread_id_;
static Monitor* monitor_;
static intptr_t interrupt_period_;
static intptr_t current_wait_time_;
static bool InDeepSleep() {
return current_wait_time_ == Monitor::kNoTimeout;
}
static void ThreadMain(uword parameters);
static void InstallSignalHandler();
static void RemoveSignalHandler();
friend class ThreadInterrupterVisitIsolates;
};
} // namespace dart
#endif // RUNTIME_VM_THREAD_INTERRUPTER_H_