diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index f04bcef39103b..038903489a3f8 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -219,8 +219,6 @@ FILE: ../../../flutter/fml/synchronization/shared_mutex_std.cc FILE: ../../../flutter/fml/synchronization/shared_mutex_std.h FILE: ../../../flutter/fml/synchronization/thread_annotations.h FILE: ../../../flutter/fml/synchronization/thread_annotations_unittest.cc -FILE: ../../../flutter/fml/synchronization/thread_checker.h -FILE: ../../../flutter/fml/synchronization/thread_checker_unittest.cc FILE: ../../../flutter/fml/synchronization/waitable_event.cc FILE: ../../../flutter/fml/synchronization/waitable_event.h FILE: ../../../flutter/fml/synchronization/waitable_event_unittest.cc diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 6c442c779f62d..ca0b9ad9fec77 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -50,7 +50,6 @@ source_set("fml") { "synchronization/count_down_latch.h", "synchronization/shared_mutex.h", "synchronization/thread_annotations.h", - "synchronization/thread_checker.h", "synchronization/waitable_event.cc", "synchronization/waitable_event.h", "task_runner.cc", @@ -188,7 +187,6 @@ executable("fml_unittests") { "string_view_unittest.cc", "synchronization/count_down_latch_unittests.cc", "synchronization/thread_annotations_unittest.cc", - "synchronization/thread_checker_unittest.cc", "synchronization/waitable_event_unittest.cc", "thread_local_unittests.cc", "thread_unittests.cc", diff --git a/fml/synchronization/thread_checker.h b/fml/synchronization/thread_checker.h deleted file mode 100644 index 3501ac5d4a9e5..0000000000000 --- a/fml/synchronization/thread_checker.h +++ /dev/null @@ -1,71 +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. - -// A class for checking that the current thread is/isn't the same as an initial -// thread. - -#ifndef FLUTTER_FML_SYNCHRONIZATION_THREAD_CHECKER_H_ -#define FLUTTER_FML_SYNCHRONIZATION_THREAD_CHECKER_H_ - -#include "flutter/fml/build_config.h" - -#if defined(OS_WIN) -#include -#else -#include -#endif - -#include "flutter/fml/logging.h" -#include "flutter/fml/macros.h" - -namespace fml { - -// A simple class that records the identity of the thread that it was created -// on, and at later points can tell if the current thread is the same as its -// creation thread. This class is thread-safe. -// -// Note: Unlike Chromium's |base::ThreadChecker|, this is *not* Debug-only (so -// #ifdef it out if you want something Debug-only). (Rationale: Having a -// |CalledOnValidThread()| that lies in Release builds seems bad. Moreover, -// there's a small space cost to having even an empty class. ) -class ThreadChecker final { - public: -#if defined(OS_WIN) - ThreadChecker() : self_(GetCurrentThreadId()) {} - ~ThreadChecker() {} - - bool IsCreationThreadCurrent() const { return GetCurrentThreadId() == self_; } - - private: - const DWORD self_; - -#else - ThreadChecker() : self_(pthread_self()) {} - ~ThreadChecker() {} - - // Returns true if the current thread is the thread this object was created - // on and false otherwise. - bool IsCreationThreadCurrent() const { - return !!pthread_equal(pthread_self(), self_); - } - - private: - const pthread_t self_; -#endif - - FML_DISALLOW_COPY_AND_ASSIGN(ThreadChecker); -}; - -#ifndef NDEBUG -#define FML_DECLARE_THREAD_CHECKER(c) fml::ThreadChecker c -#define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) \ - FML_DCHECK((c).IsCreationThreadCurrent()) -#else -#define FML_DECLARE_THREAD_CHECKER(c) -#define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) ((void)0) -#endif - -} // namespace fml - -#endif // FLUTTER_FML_SYNCHRONIZATION_THREAD_CHECKER_H_ diff --git a/fml/synchronization/thread_checker_unittest.cc b/fml/synchronization/thread_checker_unittest.cc deleted file mode 100644 index 92eb34f166157..0000000000000 --- a/fml/synchronization/thread_checker_unittest.cc +++ /dev/null @@ -1,37 +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/synchronization/thread_checker.h" - -#include - -#include "gtest/gtest.h" - -namespace fml { -namespace { - -TEST(ThreadCheckerTest, SameThread) { - ThreadChecker checker; - EXPECT_TRUE(checker.IsCreationThreadCurrent()); -} - -// Note: This test depends on |std::thread| being compatible with -// |pthread_self()|. -TEST(ThreadCheckerTest, DifferentThreads) { - ThreadChecker checker1; - EXPECT_TRUE(checker1.IsCreationThreadCurrent()); - - std::thread thread([&checker1]() { - ThreadChecker checker2; - EXPECT_TRUE(checker2.IsCreationThreadCurrent()); - EXPECT_FALSE(checker1.IsCreationThreadCurrent()); - }); - thread.join(); - - // Note: Without synchronization, we can't look at |checker2| from the main - // thread. -} - -} // namespace -} // namespace fml