Delete fml::ThreadLocalUniquePtr. (flutter/engine#50310)
Fixes https://github.com/flutter/flutter/issues/141127
This commit is contained in:
@@ -116,7 +116,6 @@
|
||||
../../../flutter/fml/synchronization/sync_switch_unittest.cc
|
||||
../../../flutter/fml/synchronization/waitable_event_unittest.cc
|
||||
../../../flutter/fml/task_source_unittests.cc
|
||||
../../../flutter/fml/thread_local_unittests.cc
|
||||
../../../flutter/fml/thread_unittests.cc
|
||||
../../../flutter/fml/time/time_delta_unittest.cc
|
||||
../../../flutter/fml/time/time_point_unittest.cc
|
||||
|
||||
@@ -4920,8 +4920,6 @@ ORIGIN: ../../../flutter/fml/task_source.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/task_source_grade.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/thread.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/thread.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/thread_local.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/thread_local.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/time/chrono_timestamp_provider.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/time/chrono_timestamp_provider.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/fml/time/time_delta.h + ../../../flutter/LICENSE
|
||||
@@ -7779,8 +7777,6 @@ FILE: ../../../flutter/fml/task_source.h
|
||||
FILE: ../../../flutter/fml/task_source_grade.h
|
||||
FILE: ../../../flutter/fml/thread.cc
|
||||
FILE: ../../../flutter/fml/thread.h
|
||||
FILE: ../../../flutter/fml/thread_local.cc
|
||||
FILE: ../../../flutter/fml/thread_local.h
|
||||
FILE: ../../../flutter/fml/time/chrono_timestamp_provider.cc
|
||||
FILE: ../../../flutter/fml/time/chrono_timestamp_provider.h
|
||||
FILE: ../../../flutter/fml/time/time_delta.h
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
|
||||
#include "gl_context_switch_test.h"
|
||||
|
||||
#include "flutter/fml/thread_local.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
FML_THREAD_LOCAL fml::ThreadLocalUniquePtr<int> current_context;
|
||||
static thread_local std::unique_ptr<int> current_context;
|
||||
|
||||
TestSwitchableGLContext::TestSwitchableGLContext(int context)
|
||||
: context_(context){};
|
||||
|
||||
@@ -88,8 +88,6 @@ source_set("fml") {
|
||||
"task_source.h",
|
||||
"thread.cc",
|
||||
"thread.h",
|
||||
"thread_local.cc",
|
||||
"thread_local.h",
|
||||
"time/time_delta.h",
|
||||
"time/time_point.cc",
|
||||
"time/time_point.h",
|
||||
@@ -361,7 +359,6 @@ if (enable_unittests) {
|
||||
"synchronization/sync_switch_unittest.cc",
|
||||
"synchronization/waitable_event_unittest.cc",
|
||||
"task_source_unittests.cc",
|
||||
"thread_local_unittests.cc",
|
||||
"thread_unittests.cc",
|
||||
"time/chrono_timestamp_provider.cc",
|
||||
"time/chrono_timestamp_provider.h",
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
|
||||
#include "flutter/fml/message_loop.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
#include "flutter/fml/message_loop_impl.h"
|
||||
#include "flutter/fml/task_runner.h"
|
||||
#include "flutter/fml/thread_local.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
FML_THREAD_LOCAL ThreadLocalUniquePtr<MessageLoop> tls_message_loop;
|
||||
static thread_local std::unique_ptr<MessageLoop> tls_message_loop;
|
||||
|
||||
MessageLoop& MessageLoop::GetCurrent() {
|
||||
auto* loop = tls_message_loop.get();
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#include "flutter/fml/make_copyable.h"
|
||||
#include "flutter/fml/task_source.h"
|
||||
#include "flutter/fml/thread_local.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
@@ -32,7 +31,7 @@ class TaskSourceGradeHolder {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
FML_THREAD_LOCAL ThreadLocalUniquePtr<TaskSourceGradeHolder>
|
||||
static thread_local std::unique_ptr<TaskSourceGradeHolder>
|
||||
tls_task_source_grade;
|
||||
|
||||
TaskQueueEntry::TaskQueueEntry(TaskQueueId created_for_arg)
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/string_conversion.h"
|
||||
#include "flutter/fml/thread_local.h"
|
||||
|
||||
namespace fml {
|
||||
namespace jni {
|
||||
@@ -24,7 +24,7 @@ struct JNIDetach {
|
||||
};
|
||||
|
||||
// Thread-local object that will detach from JNI during thread shutdown;
|
||||
FML_THREAD_LOCAL fml::ThreadLocalUniquePtr<JNIDetach> tls_jni_detach;
|
||||
static thread_local std::unique_ptr<JNIDetach> tls_jni_detach;
|
||||
|
||||
void InitJavaVM(JavaVM* vm) {
|
||||
FML_DCHECK(g_jvm == nullptr);
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "flutter/fml/thread_local.h"
|
||||
@@ -1,42 +0,0 @@
|
||||
// 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_FML_THREAD_LOCAL_H_
|
||||
#define FLUTTER_FML_THREAD_LOCAL_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace fml {
|
||||
|
||||
#define FML_THREAD_LOCAL static thread_local
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief A wrapper for a thread-local unique pointer. Do NOT use this
|
||||
/// class in new code and instead use unique pointers with the
|
||||
/// thread_local storage class directly. This was necessary for
|
||||
/// pre-C++11 code.
|
||||
///
|
||||
/// @tparam T The type held in the thread local unique pointer.
|
||||
///
|
||||
template <typename T>
|
||||
class ThreadLocalUniquePtr {
|
||||
public:
|
||||
ThreadLocalUniquePtr() = default;
|
||||
|
||||
T* get() const { return ptr_.get(); }
|
||||
|
||||
void reset(T* ptr) { ptr_.reset(ptr); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<T> ptr_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ThreadLocalUniquePtr);
|
||||
};
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_THREAD_LOCAL_H_
|
||||
@@ -1,104 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/thread_local.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class Box {
|
||||
public:
|
||||
explicit Box(int value, std::atomic_int* destroys = nullptr)
|
||||
: value_(value), destroys_(destroys) {}
|
||||
~Box() {
|
||||
if (destroys_) {
|
||||
++*destroys_;
|
||||
}
|
||||
}
|
||||
|
||||
int value() const { return value_; }
|
||||
|
||||
private:
|
||||
int value_;
|
||||
std::atomic_int* destroys_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Box);
|
||||
};
|
||||
|
||||
FML_THREAD_LOCAL fml::ThreadLocalUniquePtr<Box> local;
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(ThreadLocal, SimpleInitialization) {
|
||||
std::thread thread([&] {
|
||||
ASSERT_EQ(local.get(), nullptr);
|
||||
auto value = 100;
|
||||
local.reset(new Box(value));
|
||||
ASSERT_EQ(local.get()->value(), value);
|
||||
});
|
||||
thread.join();
|
||||
}
|
||||
|
||||
TEST(ThreadLocal, SimpleInitializationCheckInAnother) {
|
||||
std::thread thread([&] {
|
||||
ASSERT_EQ(local.get(), nullptr);
|
||||
auto value = 100;
|
||||
local.reset(new Box(value));
|
||||
ASSERT_EQ(local.get()->value(), value);
|
||||
std::thread thread2([&]() { ASSERT_EQ(local.get(), nullptr); });
|
||||
thread2.join();
|
||||
});
|
||||
thread.join();
|
||||
}
|
||||
|
||||
TEST(ThreadLocal, DestroyCallback) {
|
||||
std::atomic_int destroys{0};
|
||||
std::thread thread([&] {
|
||||
ASSERT_EQ(local.get(), nullptr);
|
||||
auto value = 100;
|
||||
local.reset(new Box(value, &destroys));
|
||||
ASSERT_EQ(local.get()->value(), value);
|
||||
ASSERT_EQ(destroys.load(), 0);
|
||||
});
|
||||
thread.join();
|
||||
ASSERT_EQ(destroys.load(), 1);
|
||||
}
|
||||
|
||||
TEST(ThreadLocal, DestroyCallback2) {
|
||||
std::atomic_int destroys{0};
|
||||
std::thread thread([&] {
|
||||
local.reset(new Box(100, &destroys));
|
||||
ASSERT_EQ(local.get()->value(), 100);
|
||||
ASSERT_EQ(destroys.load(), 0);
|
||||
local.reset(new Box(200, &destroys));
|
||||
ASSERT_EQ(local.get()->value(), 200);
|
||||
ASSERT_EQ(destroys.load(), 1);
|
||||
});
|
||||
thread.join();
|
||||
ASSERT_EQ(destroys.load(), 2);
|
||||
}
|
||||
|
||||
TEST(ThreadLocal, DestroyThreadTimeline) {
|
||||
std::atomic_int destroys{0};
|
||||
std::thread thread([&] {
|
||||
std::thread thread2([&]() {
|
||||
local.reset(new Box(100, &destroys));
|
||||
ASSERT_EQ(local.get()->value(), 100);
|
||||
ASSERT_EQ(destroys.load(), 0);
|
||||
local.reset(new Box(200, &destroys));
|
||||
ASSERT_EQ(local.get()->value(), 200);
|
||||
ASSERT_EQ(destroys.load(), 1);
|
||||
});
|
||||
ASSERT_EQ(local.get(), nullptr);
|
||||
thread2.join();
|
||||
ASSERT_EQ(local.get(), nullptr);
|
||||
ASSERT_EQ(destroys.load(), 2);
|
||||
});
|
||||
thread.join();
|
||||
ASSERT_EQ(destroys.load(), 2);
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "fml/thread_local.h"
|
||||
#include "impeller/renderer/backend/vulkan/context_vk.h"
|
||||
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
|
||||
|
||||
@@ -130,7 +129,7 @@ void CommandPoolVK::Destroy() {
|
||||
// Associates a resource with a thread and context.
|
||||
using CommandPoolMap =
|
||||
std::unordered_map<uint64_t, std::shared_ptr<CommandPoolVK>>;
|
||||
FML_THREAD_LOCAL fml::ThreadLocalUniquePtr<CommandPoolMap> tls_command_pool_map;
|
||||
static thread_local std::unique_ptr<CommandPoolMap> tls_command_pool_map;
|
||||
|
||||
// Map each context to a list of all thread-local command pools associated
|
||||
// with that context.
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "fml/macros.h"
|
||||
#include "fml/thread_local.h"
|
||||
#include "impeller/base/thread_safety.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h" // IWYU pragma: keep.
|
||||
#include "third_party/swiftshader/include/vulkan/vulkan_core.h"
|
||||
@@ -105,7 +104,7 @@ class MockDevice final {
|
||||
|
||||
void noop() {}
|
||||
|
||||
FML_THREAD_LOCAL std::vector<std::string> g_instance_extensions;
|
||||
static thread_local std::vector<std::string> g_instance_extensions;
|
||||
|
||||
VkResult vkEnumerateInstanceExtensionProperties(
|
||||
const char* pLayerName,
|
||||
@@ -125,7 +124,7 @@ VkResult vkEnumerateInstanceExtensionProperties(
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
FML_THREAD_LOCAL std::vector<std::string> g_instance_layers;
|
||||
static thread_local std::vector<std::string> g_instance_layers;
|
||||
|
||||
VkResult vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount,
|
||||
VkLayerProperties* pProperties) {
|
||||
|
||||
Reference in New Issue
Block a user