2013-12-16 18:52:15 +00:00
|
|
|
// 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.
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#ifndef RUNTIME_VM_THREAD_INTERRUPTER_H_
|
|
|
|
#define RUNTIME_VM_THREAD_INTERRUPTER_H_
|
2013-12-16 18:52:15 +00:00
|
|
|
|
|
|
|
#include "vm/allocation.h"
|
2015-01-15 02:30:07 +00:00
|
|
|
#include "vm/os_thread.h"
|
2017-07-13 15:08:33 +00:00
|
|
|
#include "vm/signal_handler.h"
|
2015-08-20 21:38:38 +00:00
|
|
|
#include "vm/thread.h"
|
2013-12-16 18:52:15 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2015-11-06 22:15:16 +00:00
|
|
|
struct InterruptedThreadState {
|
|
|
|
uintptr_t pc;
|
|
|
|
uintptr_t csp;
|
|
|
|
uintptr_t dsp;
|
|
|
|
uintptr_t fp;
|
|
|
|
uintptr_t lr;
|
|
|
|
};
|
|
|
|
|
2013-12-16 18:52:15 +00:00
|
|
|
class ThreadInterrupter : public AllStatic {
|
|
|
|
public:
|
2018-09-28 23:18:59 +00:00
|
|
|
static void Init();
|
2014-02-07 17:43:21 +00:00
|
|
|
|
|
|
|
static void Startup();
|
2018-09-28 23:18:59 +00:00
|
|
|
static void Cleanup();
|
2013-12-16 18:52:15 +00:00
|
|
|
|
|
|
|
// Delay between interrupts.
|
|
|
|
static void SetInterruptPeriod(intptr_t period);
|
|
|
|
|
2014-05-26 11:53:49 +00:00
|
|
|
// Wake up the thread interrupter thread.
|
|
|
|
static void WakeUp();
|
|
|
|
|
2014-03-25 18:09:02 +00:00
|
|
|
// Interrupt a thread.
|
2015-11-19 21:45:10 +00:00
|
|
|
static void InterruptThread(OSThread* thread);
|
2014-03-25 18:09:02 +00:00
|
|
|
|
2013-12-16 18:52:15 +00:00
|
|
|
private:
|
|
|
|
static const intptr_t kMaxThreads = 4096;
|
|
|
|
static bool initialized_;
|
|
|
|
static bool shutdown_;
|
|
|
|
static bool thread_running_;
|
2015-11-04 15:59:16 +00:00
|
|
|
static bool woken_up_;
|
2015-09-15 19:49:52 +00:00
|
|
|
static ThreadJoinId interrupter_thread_id_;
|
2013-12-16 18:52:15 +00:00
|
|
|
static Monitor* monitor_;
|
|
|
|
static intptr_t interrupt_period_;
|
2014-05-26 11:53:49 +00:00
|
|
|
static intptr_t current_wait_time_;
|
2013-12-16 18:52:15 +00:00
|
|
|
|
2017-02-09 18:11:52 +00:00
|
|
|
static bool IsDebuggerAttached();
|
|
|
|
|
2014-05-26 11:53:49 +00:00
|
|
|
static bool InDeepSleep() {
|
|
|
|
return current_wait_time_ == Monitor::kNoTimeout;
|
|
|
|
}
|
|
|
|
|
2013-12-16 18:52:15 +00:00
|
|
|
static void ThreadMain(uword parameters);
|
|
|
|
|
|
|
|
static void InstallSignalHandler();
|
2014-02-07 17:43:21 +00:00
|
|
|
|
2015-04-07 18:33:01 +00:00
|
|
|
static void RemoveSignalHandler();
|
|
|
|
|
2014-02-07 17:43:21 +00:00
|
|
|
friend class ThreadInterrupterVisitIsolates;
|
2013-12-16 18:52:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#endif // RUNTIME_VM_THREAD_INTERRUPTER_H_
|