Files
engine/runtime/dart_isolate_group_data.h
Jason Simmons b7d4278b4f Create separate objects for isolate state and isolate group state (#14268)
Isolate data may need to be deleted on the same thread where it was allocated.
In particular, the task observer set up in the UIDartState ctor must be removed
from the same message loop where it was added.

The engine had been using the same DartIsolate object as the root isolate data
and as the isolate group data.  This object would be deleted when the isolate
group was shut down.  However, group shutdown may occur on a thread associated
with a secondary isolate.  When this happens, cleanup of any state tied to the
root isolate's thread will fail.

This change adds a DartIsolateGroupData object holding state that is common
among all isolates in a group.  DartIsolateGroupData can be deleted on any
thread.

See https://github.com/flutter/flutter/issues/45578
2019-12-10 10:34:50 -08:00

64 lines
2.2 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_RUNTIME_DART_ISOLATE_GROUP_DATA_H_
#define FLUTTER_RUNTIME_DART_ISOLATE_GROUP_DATA_H_
#include <string>
#include "flutter/common/settings.h"
#include "flutter/fml/closure.h"
#include "flutter/fml/memory/ref_ptr.h"
namespace flutter {
class DartIsolate;
class DartSnapshot;
using ChildIsolatePreparer = std::function<bool(DartIsolate*)>;
// Object holding state associated with a Dart isolate group. An instance of
// this class will be provided to Dart_CreateIsolateGroup as the
// isolate_group_data.
//
// This object must be thread safe because the Dart VM can invoke the isolate
// group cleanup callback on any thread.
class DartIsolateGroupData {
public:
DartIsolateGroupData(const Settings& settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
const ChildIsolatePreparer& child_isolate_preparer,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback);
~DartIsolateGroupData();
const Settings& GetSettings() const;
fml::RefPtr<const DartSnapshot> GetIsolateSnapshot() const;
const std::string& GetAdvisoryScriptURI() const;
const std::string& GetAdvisoryScriptEntrypoint() const;
const ChildIsolatePreparer& GetChildIsolatePreparer() const;
const fml::closure& GetIsolateCreateCallback() const;
const fml::closure& GetIsolateShutdownCallback() const;
void SetChildIsolatePreparer(const ChildIsolatePreparer& value);
private:
FML_DISALLOW_COPY_AND_ASSIGN(DartIsolateGroupData);
const Settings settings_;
const fml::RefPtr<const DartSnapshot> isolate_snapshot_;
const std::string advisory_script_uri_;
const std::string advisory_script_entrypoint_;
ChildIsolatePreparer child_isolate_preparer_;
const fml::closure isolate_create_callback_;
const fml::closure isolate_shutdown_callback_;
};
} // namespace flutter
#endif // FLUTTER_RUNTIME_DART_ISOLATE_GROUP_DATA_H_