Skip to content

Commit

Permalink
Generate weak pointers only in the platform thread (flutter#9431)
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuqian authored Jun 24, 2019
1 parent da29c04 commit ccb5034
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 4 additions & 5 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,9 @@ bool Shell::Setup(std::unique_ptr<PlatformView> platform_view,

// The weak ptr must be generated in the platform thread which owns the unique
// ptr.
//
// TODO(liyuqian): make weak_rasterizer_ and weak_platform_view_ and use
// them in the getters.
weak_engine_ = engine_->GetWeakPtr();
weak_rasterizer_ = rasterizer_->GetWeakPtr();
weak_platform_view_ = platform_view_->GetWeakPtr();

is_setup_ = true;

Expand All @@ -420,7 +419,7 @@ const TaskRunners& Shell::GetTaskRunners() const {

fml::WeakPtr<Rasterizer> Shell::GetRasterizer() {
FML_DCHECK(is_setup_);
return rasterizer_->GetWeakPtr();
return weak_rasterizer_;
}

fml::WeakPtr<Engine> Shell::GetEngine() {
Expand All @@ -430,7 +429,7 @@ fml::WeakPtr<Engine> Shell::GetEngine() {

fml::WeakPtr<PlatformView> Shell::GetPlatformView() {
FML_DCHECK(is_setup_);
return platform_view_->GetWeakPtr();
return weak_platform_view_;
}

DartVM* Shell::GetDartVM() {
Expand Down
5 changes: 4 additions & 1 deletion shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class Shell final : public PlatformView::Delegate,
std::unique_ptr<Rasterizer> rasterizer_; // on GPU task runner
std::unique_ptr<ShellIOManager> io_manager_; // on IO task runner

fml::WeakPtr<Engine> weak_engine_; // to be shared across threads
fml::WeakPtr<Engine> weak_engine_; // to be shared across threads
fml::WeakPtr<Rasterizer> weak_rasterizer_; // to be shared across threads
fml::WeakPtr<PlatformView>
weak_platform_view_; // to be shared across threads

std::unordered_map<std::string, // method
std::pair<fml::RefPtr<fml::TaskRunner>,
Expand Down

0 comments on commit ccb5034

Please sign in to comment.