Remove fml::ThreadChecker and use the one in ftl. (flutter/engine#3623)
This commit is contained in:
@@ -18,8 +18,6 @@ source_set("fml") {
|
||||
"task_runner.h",
|
||||
"thread.cc",
|
||||
"thread.h",
|
||||
"thread_checker.cc",
|
||||
"thread_checker.h",
|
||||
"thread_local.h",
|
||||
"trace_event.cc",
|
||||
"trace_event.h",
|
||||
@@ -105,7 +103,6 @@ executable("fml_unittests") {
|
||||
|
||||
sources = [
|
||||
"message_loop_unittests.cc",
|
||||
"thread_checker_unittests.cc",
|
||||
"thread_local_unittests.cc",
|
||||
"thread_unittests.cc",
|
||||
]
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/fml/thread_checker.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
ThreadChecker::ThreadChecker() : handle_(std::this_thread::get_id()) {}
|
||||
|
||||
ThreadChecker::~ThreadChecker() = default;
|
||||
|
||||
bool ThreadChecker::IsCalledOnValidThread() const {
|
||||
return handle_ == std::this_thread::get_id();
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
@@ -1,30 +0,0 @@
|
||||
// Copyright 2017 The Chromium 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_FML_THREAD_CHECKER_H_
|
||||
#define FLUTTER_FML_THREAD_CHECKER_H_
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
class ThreadChecker {
|
||||
public:
|
||||
ThreadChecker();
|
||||
|
||||
~ThreadChecker();
|
||||
|
||||
bool IsCalledOnValidThread() const;
|
||||
|
||||
private:
|
||||
const std::thread::id handle_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(ThreadChecker);
|
||||
};
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_THREAD_CHECKER_H_
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "flutter/fml/thread_checker.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(ThreadChecker, CheckCalledOnValidThread) {
|
||||
fml::ThreadChecker checker;
|
||||
ASSERT_TRUE(checker.IsCalledOnValidThread());
|
||||
std::thread thread(
|
||||
[&checker]() { ASSERT_FALSE(checker.IsCalledOnValidThread()); });
|
||||
thread.join();
|
||||
}
|
||||
@@ -207,22 +207,22 @@ TracingController& Shell::tracing_controller() {
|
||||
}
|
||||
|
||||
void Shell::InitGpuThread() {
|
||||
gpu_thread_checker_.reset(new fml::ThreadChecker());
|
||||
gpu_thread_checker_.reset(new ftl::ThreadChecker());
|
||||
}
|
||||
|
||||
void Shell::InitUIThread() {
|
||||
ui_thread_checker_.reset(new fml::ThreadChecker());
|
||||
ui_thread_checker_.reset(new ftl::ThreadChecker());
|
||||
}
|
||||
|
||||
void Shell::AddRasterizer(const ftl::WeakPtr<Rasterizer>& rasterizer) {
|
||||
FTL_DCHECK(gpu_thread_checker_ &&
|
||||
gpu_thread_checker_->IsCalledOnValidThread());
|
||||
gpu_thread_checker_->IsCreationThreadCurrent());
|
||||
rasterizers_.push_back(rasterizer);
|
||||
}
|
||||
|
||||
void Shell::PurgeRasterizers() {
|
||||
FTL_DCHECK(gpu_thread_checker_ &&
|
||||
gpu_thread_checker_->IsCalledOnValidThread());
|
||||
gpu_thread_checker_->IsCreationThreadCurrent());
|
||||
rasterizers_.erase(
|
||||
std::remove_if(rasterizers_.begin(), rasterizers_.end(), IsInvalid),
|
||||
rasterizers_.end());
|
||||
@@ -230,19 +230,21 @@ void Shell::PurgeRasterizers() {
|
||||
|
||||
void Shell::GetRasterizers(std::vector<ftl::WeakPtr<Rasterizer>>* rasterizers) {
|
||||
FTL_DCHECK(gpu_thread_checker_ &&
|
||||
gpu_thread_checker_->IsCalledOnValidThread());
|
||||
gpu_thread_checker_->IsCreationThreadCurrent());
|
||||
*rasterizers = rasterizers_;
|
||||
}
|
||||
|
||||
void Shell::AddPlatformView(const ftl::WeakPtr<PlatformView>& platform_view) {
|
||||
FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->IsCalledOnValidThread());
|
||||
FTL_DCHECK(ui_thread_checker_ &&
|
||||
ui_thread_checker_->IsCreationThreadCurrent());
|
||||
if (platform_view) {
|
||||
platform_views_.push_back(platform_view);
|
||||
}
|
||||
}
|
||||
|
||||
void Shell::PurgePlatformViews() {
|
||||
FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->IsCalledOnValidThread());
|
||||
FTL_DCHECK(ui_thread_checker_ &&
|
||||
ui_thread_checker_->IsCreationThreadCurrent());
|
||||
platform_views_.erase(std::remove_if(platform_views_.begin(),
|
||||
platform_views_.end(), IsViewInvalid),
|
||||
platform_views_.end());
|
||||
@@ -250,7 +252,8 @@ void Shell::PurgePlatformViews() {
|
||||
|
||||
void Shell::GetPlatformViews(
|
||||
std::vector<ftl::WeakPtr<PlatformView>>* platform_views) {
|
||||
FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->IsCalledOnValidThread());
|
||||
FTL_DCHECK(ui_thread_checker_ &&
|
||||
ui_thread_checker_->IsCreationThreadCurrent());
|
||||
*platform_views = platform_views_;
|
||||
}
|
||||
|
||||
@@ -317,7 +320,8 @@ void Shell::RunInPlatformViewUIThread(uintptr_t view_id,
|
||||
int64_t* dart_isolate_id,
|
||||
std::string* isolate_name,
|
||||
ftl::AutoResetWaitableEvent* latch) {
|
||||
FTL_DCHECK(ui_thread_checker_ && ui_thread_checker_->IsCalledOnValidThread());
|
||||
FTL_DCHECK(ui_thread_checker_ &&
|
||||
ui_thread_checker_->IsCreationThreadCurrent());
|
||||
|
||||
*view_existed = false;
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
#define SHELL_COMMON_SHELL_H_
|
||||
|
||||
#include "flutter/fml/thread.h"
|
||||
#include "flutter/fml/thread_checker.h"
|
||||
#include "flutter/shell/common/tracing_controller.h"
|
||||
#include "lib/ftl/command_line.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/memory/ref_ptr.h"
|
||||
#include "lib/ftl/memory/weak_ptr.h"
|
||||
#include "lib/ftl/synchronization/thread_checker.h"
|
||||
#include "lib/ftl/synchronization/waitable_event.h"
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
|
||||
@@ -95,8 +95,8 @@ class Shell {
|
||||
std::unique_ptr<fml::Thread> ui_thread_;
|
||||
std::unique_ptr<fml::Thread> io_thread_;
|
||||
|
||||
std::unique_ptr<fml::ThreadChecker> gpu_thread_checker_;
|
||||
std::unique_ptr<fml::ThreadChecker> ui_thread_checker_;
|
||||
std::unique_ptr<ftl::ThreadChecker> gpu_thread_checker_;
|
||||
std::unique_ptr<ftl::ThreadChecker> ui_thread_checker_;
|
||||
|
||||
TracingController tracing_controller_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user