dart-sdk/runtime/vm/base_isolate.h
Martin Kustermann 14ea27e65b [vm/concurrency] Make thread_registry not depend on [Isolate], move mutator thread from thread registry to isolate
The thread registry is creating [Thread] objects when threads enter an
isolate (as mutator or helper). Once threads exit an isolate, the
[Thread] structure is returned and the thread registry will put it
into a cache for later re-use.

The mutator [Thread] object is an exception: Exiting and entering the
isolate as mutator will always use the same cached [Thread] object.

We want to eventually use one thread registry for an entire isolate
group. There will therefore be multiple mutator threads per thread registry.
We therefore move the cached mutator thread from the thread registry to the
[Isolate] object.

Issue https://github.com/dart-lang/sdk/issues/36097

Change-Id: Id27dff886d79ca76f6e05320151aeb72c8ba5140
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108720
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2019-07-11 13:36:02 +00:00

65 lines
1.9 KiB
C++

// Copyright (c) 2012, 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_BASE_ISOLATE_H_
#define RUNTIME_VM_BASE_ISOLATE_H_
#include "platform/assert.h"
#include "vm/globals.h"
namespace dart {
class HandleScope;
class StackResource;
class Thread;
class Zone;
// A BaseIsolate contains just enough functionality to allocate
// StackResources. This allows us to inline the StackResource
// constructor/destructor for performance.
class BaseIsolate {
public:
#if defined(DEBUG)
void AssertCurrentThreadIsMutator() const;
#else
void AssertCurrentThreadIsMutator() const {}
#endif // DEBUG
#if defined(DEBUG)
static void AssertCurrent(BaseIsolate* isolate);
#endif
protected:
BaseIsolate() {}
~BaseIsolate() {
// Do not delete stack resources: top_resource_ and current_zone_.
}
Thread* scheduled_mutator_thread_ = nullptr;
// TODO(asiva): Currently we treat a mutator thread as a special thread
// and always schedule execution of Dart code on the same mutator thread
// object. The ApiLocalScope has been made thread specific but we still
// have scenarios where we do a temporary exit of an Isolate with live
// zones/handles in the API scope :
// - Dart_RunLoop()
// - IsolateSaver in Dart_NewNativePort
// Similarly, tracking async_stack_trace requires that we always reschedule
// on the same thread.
// We probably need a mechanism to return to the specific thread only
// for these specific cases. We should also determine if the embedder
// should allow exiting an isolate with live state in zones/handles in
// which case a new API for returning to the specific thread needs to be
// added.
Thread* mutator_thread_ = nullptr;
private:
DISALLOW_COPY_AND_ASSIGN(BaseIsolate);
};
} // namespace dart
#endif // RUNTIME_VM_BASE_ISOLATE_H_