Skip to content

Commit

Permalink
Use the default microtask scheduler on all isolates except the UI iso…
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons authored Apr 23, 2018
1 parent 96af3b2 commit 2970c09
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
17 changes: 7 additions & 10 deletions lib/ui/dart_runtime_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,15 @@ static Dart_Handle GetClosure(Dart_Handle builtin_library, const char* name) {
return closure;
}

static void InitDartInternal(Dart_Handle builtin_library,
DartRuntimeHooks::IsolateType isolate_type) {
static void InitDartInternal(Dart_Handle builtin_library, bool is_ui_isolate) {
Dart_Handle print = GetClosure(builtin_library, "_getPrintClosure");

Dart_Handle internal_library = Dart_LookupLibrary(ToDart("dart:_internal"));

DART_CHECK_VALID(
Dart_SetField(internal_library, ToDart("_printClosure"), print));

if (isolate_type == DartRuntimeHooks::MainIsolate) {
if (is_ui_isolate) {
// Call |_setupHooks| to configure |VMLibraryHooks|.
Dart_Handle method_name = Dart_NewStringFromCString("_setupHooks");
DART_CHECK_VALID(Dart_Invoke(builtin_library, method_name, 0, NULL))
Expand All @@ -97,14 +96,12 @@ static void InitDartCore(Dart_Handle builtin, const std::string& script_uri) {
Dart_SetField(core_library, ToDart("_uriBaseClosure"), get_base_url));
}

static void InitDartAsync(Dart_Handle builtin_library,
DartRuntimeHooks::IsolateType isolate_type) {
static void InitDartAsync(Dart_Handle builtin_library, bool is_ui_isolate) {
Dart_Handle schedule_microtask;
if (isolate_type == DartRuntimeHooks::MainIsolate) {
if (is_ui_isolate) {
schedule_microtask =
GetClosure(builtin_library, "_getScheduleMicrotaskClosure");
} else {
FXL_CHECK(isolate_type == DartRuntimeHooks::SecondaryIsolate);
Dart_Handle isolate_lib = Dart_LookupLibrary(ToDart("dart:isolate"));
Dart_Handle method_name =
Dart_NewStringFromCString("_getIsolateScheduleImmediateClosure");
Expand Down Expand Up @@ -132,13 +129,13 @@ static void InitDartIO(Dart_Handle builtin_library,
Dart_SetField(platform_type, ToDart("_localeClosure"), locale_closure));
}

void DartRuntimeHooks::Install(IsolateType isolate_type,
void DartRuntimeHooks::Install(bool is_ui_isolate,
const std::string& script_uri) {
Dart_Handle builtin = Dart_LookupLibrary(ToDart("dart:ui"));
DART_CHECK_VALID(builtin);
InitDartInternal(builtin, isolate_type);
InitDartInternal(builtin, is_ui_isolate);
InitDartCore(builtin, script_uri);
InitDartAsync(builtin, isolate_type);
InitDartAsync(builtin, is_ui_isolate);
InitDartIO(builtin, script_uri);
}

Expand Down
7 changes: 1 addition & 6 deletions lib/ui/dart_runtime_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ namespace blink {

class DartRuntimeHooks {
public:
enum IsolateType {
MainIsolate,
SecondaryIsolate,
};

static void Install(IsolateType isolate_type, const std::string& script_uri);
static void Install(bool is_ui_isolate, const std::string& script_uri);
static void RegisterNatives(tonic::DartLibraryNatives* natives);

private:
Expand Down
8 changes: 3 additions & 5 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ bool DartIsolate::UpdateThreadPoolNames() const {
return true;
}

bool DartIsolate::LoadLibraries() {
bool DartIsolate::LoadLibraries(bool is_root_isolate) {
TRACE_EVENT0("flutter", "DartIsolate::LoadLibraries");
if (phase_ != Phase::Initialized) {
return false;
Expand All @@ -234,9 +234,7 @@ bool DartIsolate::LoadLibraries() {

const bool is_service_isolate = Dart_IsServiceIsolate(isolate());

DartRuntimeHooks::Install(is_service_isolate
? DartRuntimeHooks::SecondaryIsolate
: DartRuntimeHooks::MainIsolate,
DartRuntimeHooks::Install(is_root_isolate && !is_service_isolate,
GetAdvisoryScriptURI());

if (!is_service_isolate) {
Expand Down Expand Up @@ -675,7 +673,7 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair(
return {nullptr, {}};
}

if (!embedder_isolate->LoadLibraries()) {
if (!embedder_isolate->LoadLibraries(is_root_isolate)) {
*error =
strdup("Embedder could not load libraries in the new Dart isolate.");
FXL_DLOG(ERROR) << *error;
Expand Down
2 changes: 1 addition & 1 deletion runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class DartIsolate : public UIDartState {
bool Initialize(Dart_Isolate isolate, bool is_root_isolate);

FXL_WARN_UNUSED_RESULT
bool LoadLibraries();
bool LoadLibraries(bool is_root_isolate);

bool UpdateThreadPoolNames() const;

Expand Down

0 comments on commit 2970c09

Please sign in to comment.