[vm] Isolate ownership API
go/dart-isolate-ownership-api Change-Id: Ia778a916de3fecec9f0aa1a5c8bc9fd7dd421267 Bug: https://github.com/dart-lang/native/issues/1908 TEST=runtime/vm/dart_api_impl_test.cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407700 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Liam Appelbe <liama@google.com>
This commit is contained in:
committed by
Commit Queue
parent
b1e10bff4f
commit
cb02b8726a
@@ -1527,14 +1527,23 @@ DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) {
|
||||
CHECK_NO_ISOLATE(Isolate::Current());
|
||||
// TODO(http://dartbug.com/16615): Validate isolate parameter.
|
||||
Isolate* iso = reinterpret_cast<Isolate*>(isolate);
|
||||
ThreadId os_thread = OSThread::GetCurrentThreadId();
|
||||
if (iso->IsScheduled()) {
|
||||
FATAL(
|
||||
"Isolate %s is already scheduled on mutator thread %p, "
|
||||
"failed to schedule from os thread 0x%" Px "\n",
|
||||
iso->name(), iso->scheduled_mutator_thread(),
|
||||
OSThread::ThreadIdToIntPtr(OSThread::GetCurrentThreadId()));
|
||||
OSThread::ThreadIdToIntPtr(os_thread));
|
||||
}
|
||||
Thread::EnterIsolate(iso);
|
||||
ThreadId owner_thread = iso->GetOwnerThread(nullptr);
|
||||
if (owner_thread != OSThread::kInvalidThreadId && owner_thread != os_thread) {
|
||||
FATAL("Isolate %s is owned by os thread 0x%" Px
|
||||
", "
|
||||
"failed to schedule from os thread 0x%" Px "\n",
|
||||
iso->name(), OSThread::ThreadIdToIntPtr(owner_thread),
|
||||
OSThread::ThreadIdToIntPtr(os_thread));
|
||||
}
|
||||
// A Thread structure has been associated to the thread, we do the
|
||||
// safepoint transition explicitly here instead of using the
|
||||
// TransitionXXX scope objects as the reverse transition happens
|
||||
@@ -2199,6 +2208,20 @@ DART_EXPORT Dart_Port Dart_GetMainPortId() {
|
||||
return isolate->main_port();
|
||||
}
|
||||
|
||||
DART_EXPORT void Dart_SetCurrentThreadOwnsIsolate() {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
CHECK_ISOLATE(isolate);
|
||||
if (!isolate->SetOwnerThread(OSThread::kInvalidThreadId,
|
||||
OSThread::GetCurrentThreadId())) {
|
||||
FATAL("Tried to claim ownership of isolate %s, but it is already owned\n",
|
||||
isolate->name());
|
||||
}
|
||||
}
|
||||
|
||||
DART_EXPORT bool Dart_GetCurrentThreadOwnsIsolate(Dart_Port port) {
|
||||
return PortMap::IsOwnedByCurrentThread(port);
|
||||
}
|
||||
|
||||
// --- Scopes ----
|
||||
|
||||
DART_EXPORT void Dart_EnterScope() {
|
||||
|
||||
Reference in New Issue
Block a user