diff --git a/engine/src/flutter/ci/licenses_golden/excluded_files b/engine/src/flutter/ci/licenses_golden/excluded_files index ad05a09048..f8e1a99ae4 100644 --- a/engine/src/flutter/ci/licenses_golden/excluded_files +++ b/engine/src/flutter/ci/licenses_golden/excluded_files @@ -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 diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 761d35bb89..26dfb762b3 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -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 diff --git a/engine/src/flutter/flow/testing/gl_context_switch_test.cc b/engine/src/flutter/flow/testing/gl_context_switch_test.cc index d049d0c6e4..8a98ae882e 100644 --- a/engine/src/flutter/flow/testing/gl_context_switch_test.cc +++ b/engine/src/flutter/flow/testing/gl_context_switch_test.cc @@ -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 current_context; +static thread_local std::unique_ptr current_context; TestSwitchableGLContext::TestSwitchableGLContext(int context) : context_(context){}; diff --git a/engine/src/flutter/fml/BUILD.gn b/engine/src/flutter/fml/BUILD.gn index aac98dc2a1..3267884785 100644 --- a/engine/src/flutter/fml/BUILD.gn +++ b/engine/src/flutter/fml/BUILD.gn @@ -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", diff --git a/engine/src/flutter/fml/message_loop.cc b/engine/src/flutter/fml/message_loop.cc index c1043e664a..f392265583 100644 --- a/engine/src/flutter/fml/message_loop.cc +++ b/engine/src/flutter/fml/message_loop.cc @@ -4,17 +4,17 @@ #include "flutter/fml/message_loop.h" +#include #include #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 tls_message_loop; +static thread_local std::unique_ptr tls_message_loop; MessageLoop& MessageLoop::GetCurrent() { auto* loop = tls_message_loop.get(); diff --git a/engine/src/flutter/fml/message_loop_task_queues.cc b/engine/src/flutter/fml/message_loop_task_queues.cc index c5b6d76df5..bc017cc00c 100644 --- a/engine/src/flutter/fml/message_loop_task_queues.cc +++ b/engine/src/flutter/fml/message_loop_task_queues.cc @@ -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 +static thread_local std::unique_ptr tls_task_source_grade; TaskQueueEntry::TaskQueueEntry(TaskQueueId created_for_arg) diff --git a/engine/src/flutter/fml/platform/android/jni_util.cc b/engine/src/flutter/fml/platform/android/jni_util.cc index deffe2b20b..018ac7affd 100644 --- a/engine/src/flutter/fml/platform/android/jni_util.cc +++ b/engine/src/flutter/fml/platform/android/jni_util.cc @@ -6,11 +6,11 @@ #include +#include #include #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 tls_jni_detach; +static thread_local std::unique_ptr tls_jni_detach; void InitJavaVM(JavaVM* vm) { FML_DCHECK(g_jvm == nullptr); diff --git a/engine/src/flutter/fml/thread_local.cc b/engine/src/flutter/fml/thread_local.cc deleted file mode 100644 index 88f1407d9b..0000000000 --- a/engine/src/flutter/fml/thread_local.cc +++ /dev/null @@ -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" diff --git a/engine/src/flutter/fml/thread_local.h b/engine/src/flutter/fml/thread_local.h deleted file mode 100644 index 1aa62fe0a8..0000000000 --- a/engine/src/flutter/fml/thread_local.h +++ /dev/null @@ -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 - -#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 -class ThreadLocalUniquePtr { - public: - ThreadLocalUniquePtr() = default; - - T* get() const { return ptr_.get(); } - - void reset(T* ptr) { ptr_.reset(ptr); } - - private: - std::unique_ptr ptr_; - - FML_DISALLOW_COPY_AND_ASSIGN(ThreadLocalUniquePtr); -}; - -} // namespace fml - -#endif // FLUTTER_FML_THREAD_LOCAL_H_ diff --git a/engine/src/flutter/fml/thread_local_unittests.cc b/engine/src/flutter/fml/thread_local_unittests.cc deleted file mode 100644 index 88e2bda1db..0000000000 --- a/engine/src/flutter/fml/thread_local_unittests.cc +++ /dev/null @@ -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 -#include - -#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 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); -} diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc index 1c5d0dec6c..0cd6e240af 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc @@ -8,7 +8,6 @@ #include #include -#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>; -FML_THREAD_LOCAL fml::ThreadLocalUniquePtr tls_command_pool_map; +static thread_local std::unique_ptr tls_command_pool_map; // Map each context to a list of all thread-local command pools associated // with that context. diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/test/mock_vulkan.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/test/mock_vulkan.cc index 0b42aa6d9c..af6ec8a35a 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/test/mock_vulkan.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/test/mock_vulkan.cc @@ -10,7 +10,6 @@ #include #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 g_instance_extensions; +static thread_local std::vector g_instance_extensions; VkResult vkEnumerateInstanceExtensionProperties( const char* pLayerName, @@ -125,7 +124,7 @@ VkResult vkEnumerateInstanceExtensionProperties( return VK_SUCCESS; } -FML_THREAD_LOCAL std::vector g_instance_layers; +static thread_local std::vector g_instance_layers; VkResult vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties) {