42DEFINE_FLAG(
bool, trace_thread_interrupter,
false,
"Trace thread interrupter");
44bool ThreadInterrupter::initialized_ =
false;
45bool ThreadInterrupter::shutdown_ =
false;
46bool ThreadInterrupter::thread_running_ =
false;
47bool ThreadInterrupter::woken_up_ =
false;
50Monitor* ThreadInterrupter::monitor_ =
nullptr;
51intptr_t ThreadInterrupter::interrupt_period_ = 1000;
56 if (monitor_ ==
nullptr) {
59 ASSERT(monitor_ !=
nullptr);
66 if (FLAG_trace_thread_interrupter) {
73 while (!thread_running_) {
78 if (FLAG_trace_thread_interrupter) {
94 if (FLAG_trace_thread_interrupter) {
103 initialized_ =
false;
105 if (FLAG_trace_thread_interrupter) {
122 interrupt_period_ = period;
126 if (monitor_ ==
nullptr) {
141 if (!InDeepSleep()) {
150void ThreadInterrupter::ThreadMain(
uword parameters) {
152 InstallSignalHandler();
153 if (FLAG_trace_thread_interrupter) {
158 MonitorLocker startup_ml(monitor_);
160 ASSERT(os_thread !=
nullptr);
162 thread_running_ =
true;
166 intptr_t interrupted_thread_count = 0;
167 MonitorLocker wait_ml(monitor_);
168 current_wait_time_ = interrupt_period_;
170 intptr_t r = wait_ml.WaitMicros(current_wait_time_);
178 ASSERT(interrupted_thread_count == 0);
180 current_wait_time_ = interrupt_period_;
181 }
else if (current_wait_time_ != interrupt_period_) {
183 current_wait_time_ = interrupt_period_;
187 interrupted_thread_count = 0;
194 while (it.HasNext()) {
195 OSThread* thread = it.Next();
196 if (thread->ThreadInterruptsEnabled()) {
197 interrupted_thread_count++;
208 if (!woken_up_ && (interrupted_thread_count == 0)) {
221 RemoveSignalHandler();
222 if (FLAG_trace_thread_interrupter) {
227 MonitorLocker shutdown_ml(monitor_);
228 thread_running_ =
false;
229 shutdown_ml.Notify();
233#if !defined(DART_HOST_OS_ANDROID)
Monitor::WaitResult Wait(int64_t millis=Monitor::kNoTimeout)
static constexpr int64_t kNoTimeout
static int Start(const char *name, ThreadStartFunction function, uword parameter)
static void Join(ThreadJoinId id)
static OSThread * Current()
static ThreadJoinId GetCurrentThreadJoinId(OSThread *thread)
static const ThreadJoinId kInvalidThreadJoinId
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void CleanupCurrentThreadState(void *state)
static void SetInterruptPeriod(intptr_t period)
static void * PrepareCurrentThread()
static void InterruptThread(OSThread *thread)
DEFINE_FLAG(bool, print_cluster_information, false, "Print information about clusters written to snapshot")