diff --git a/api/BUILD.gn b/api/BUILD.gn index fba441198a..0a6c670936 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -175,6 +175,7 @@ rtc_library("libjingle_peerconnection_api") { ":rtp_parameters", ":rtp_transceiver_direction", ":scoped_refptr", + ":sequence_checker", "../rtc_base:network_constants", "adaptation:resource_adaptation_api", "audio:audio_mixer_api", diff --git a/api/stats_types.h b/api/stats_types.h index c1922a8a22..f910b4a164 100644 --- a/api/stats_types.h +++ b/api/stats_types.h @@ -21,11 +21,11 @@ #include #include "api/scoped_refptr.h" +#include "api/sequence_checker.h" #include "rtc_base/constructor_magic.h" #include "rtc_base/ref_count.h" #include "rtc_base/string_encode.h" #include "rtc_base/system/rtc_export.h" -#include "rtc_base/thread_checker.h" namespace webrtc { @@ -344,7 +344,7 @@ class RTC_EXPORT StatsReport { const StatsValueName name; private: - rtc::ThreadChecker thread_checker_; + webrtc::SequenceChecker thread_checker_; mutable int ref_count_ RTC_GUARDED_BY(thread_checker_) = 0; const Type type_; @@ -447,7 +447,7 @@ class StatsCollection { private: Container list_; - rtc::ThreadChecker thread_checker_; + webrtc::SequenceChecker thread_checker_; }; } // namespace webrtc diff --git a/audio/voip/BUILD.gn b/audio/voip/BUILD.gn index 77e87d5019..d90e5c425f 100644 --- a/audio/voip/BUILD.gn +++ b/audio/voip/BUILD.gn @@ -97,7 +97,6 @@ rtc_library("audio_egress") { "../../modules/rtp_rtcp:rtp_rtcp_format", "../../rtc_base:logging", "../../rtc_base:rtc_task_queue", - "../../rtc_base:thread_checker", "../../rtc_base:timeutils", "../../rtc_base/synchronization:mutex", "../../rtc_base/synchronization:sequence_checker", diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn index b27be1e266..35a163f410 100644 --- a/p2p/BUILD.gn +++ b/p2p/BUILD.gn @@ -90,6 +90,7 @@ rtc_library("rtc_p2p") { "../api:packet_socket_factory", "../api:rtc_error", "../api:scoped_refptr", + "../api:sequence_checker", "../api/crypto:options", "../api/rtc_event_log", "../api/transport:enums", diff --git a/p2p/base/port_allocator.h b/p2p/base/port_allocator.h index 4bbe56c0b5..33a23484f2 100644 --- a/p2p/base/port_allocator.h +++ b/p2p/base/port_allocator.h @@ -16,6 +16,7 @@ #include #include +#include "api/sequence_checker.h" #include "api/transport/enums.h" #include "p2p/base/port.h" #include "p2p/base/port_interface.h" @@ -25,7 +26,6 @@ #include "rtc_base/system/rtc_export.h" #include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/thread.h" -#include "rtc_base/thread_checker.h" namespace webrtc { class TurnCustomizer; @@ -638,7 +638,7 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> { bool allow_tcp_listen_; uint32_t candidate_filter_; std::string origin_; - rtc::ThreadChecker thread_checker_; + webrtc::SequenceChecker thread_checker_; private: ServerAddresses stun_servers_; diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 5232a7e712..5b508db6c5 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -581,7 +581,6 @@ rtc_library("audio_track") { "../api:scoped_refptr", "../rtc_base:checks", "../rtc_base:refcount", - "../rtc_base:thread_checker", "../rtc_base/synchronization:sequence_checker", ] } diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 65572aa913..87894ea2d9 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -168,7 +168,6 @@ rtc_library("rtc_base_approved") { ":rtc_event", ":safe_conversions", ":stringutils", - ":thread_checker", ":timeutils", "synchronization:sequence_checker", ] @@ -236,7 +235,6 @@ rtc_library("platform_thread") { ":macromagic", ":platform_thread_types", ":rtc_event", - ":thread_checker", ":timeutils", "synchronization:sequence_checker", ] @@ -318,14 +316,6 @@ rtc_library("logging") { } } -rtc_source_set("thread_checker") { - sources = [ "thread_checker.h" ] - deps = [ - ":deprecation", - "synchronization:sequence_checker", - ] -} - rtc_source_set("atomicops") { sources = [ "atomic_ops.h" ] } @@ -1375,7 +1365,6 @@ if (rtc_include_tests) { "strings/string_format_unittest.cc", "swap_queue_unittest.cc", "thread_annotations_unittest.cc", - "thread_checker_unittest.cc", "time_utils_unittest.cc", "timestamp_aligner_unittest.cc", "virtual_socket_unittest.cc", diff --git a/rtc_base/task_utils/BUILD.gn b/rtc_base/task_utils/BUILD.gn index 018844fe65..e47ee7ea50 100644 --- a/rtc_base/task_utils/BUILD.gn +++ b/rtc_base/task_utils/BUILD.gn @@ -16,7 +16,6 @@ rtc_library("repeating_task") { deps = [ ":to_queued_task", "..:logging", - "..:thread_checker", "..:timeutils", "../../api/task_queue", "../../api/units:time_delta", @@ -35,7 +34,6 @@ rtc_library("pending_task_safety_flag") { deps = [ "..:checks", "..:refcount", - "..:thread_checker", "../../api:scoped_refptr", "../synchronization:sequence_checker", "../system:no_unique_address", diff --git a/rtc_base/thread_checker.h b/rtc_base/thread_checker.h deleted file mode 100644 index 876a08e38c..0000000000 --- a/rtc_base/thread_checker.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// Borrowed from Chromium's src/base/threading/thread_checker.h. - -#ifndef RTC_BASE_THREAD_CHECKER_H_ -#define RTC_BASE_THREAD_CHECKER_H_ - -#include "rtc_base/deprecation.h" -#include "rtc_base/synchronization/sequence_checker.h" - -namespace rtc { -// TODO(srte): Replace usages of this with SequenceChecker. -class ThreadChecker : public webrtc::SequenceChecker { - public: - RTC_DEPRECATED bool CalledOnValidThread() const { return IsCurrent(); } - RTC_DEPRECATED void DetachFromThread() { Detach(); } -}; -} // namespace rtc -#endif // RTC_BASE_THREAD_CHECKER_H_ diff --git a/rtc_base/thread_checker_unittest.cc b/rtc_base/thread_checker_unittest.cc deleted file mode 100644 index b5927043f0..0000000000 --- a/rtc_base/thread_checker_unittest.cc +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// Borrowed from Chromium's src/base/threading/thread_checker_unittest.cc. - -#include "rtc_base/thread_checker.h" - -#include -#include - -#include "rtc_base/checks.h" -#include "rtc_base/constructor_magic.h" -#include "rtc_base/null_socket_server.h" -#include "rtc_base/socket_server.h" -#include "rtc_base/task_queue.h" -#include "rtc_base/thread.h" -#include "test/gtest.h" - -// Duplicated from base/threading/thread_checker.h so that we can be -// good citizens there and undef the macro. -#define ENABLE_THREAD_CHECKER RTC_DCHECK_IS_ON - -namespace rtc { - -namespace { - -// Simple class to exercise the basics of ThreadChecker. -// Both the destructor and DoStuff should verify that they were -// called on the same thread as the constructor. -class ThreadCheckerClass : public ThreadChecker { - public: - ThreadCheckerClass() {} - - // Verifies that it was called on the same thread as the constructor. - void DoStuff() { RTC_DCHECK(IsCurrent()); } - - void Detach() { ThreadChecker::Detach(); } - - static void MethodOnDifferentThreadImpl(); - static void DetachThenCallFromDifferentThreadImpl(); - - private: - RTC_DISALLOW_COPY_AND_ASSIGN(ThreadCheckerClass); -}; - -// Calls ThreadCheckerClass::DoStuff on another thread. -class CallDoStuffOnThread : public Thread { - public: - explicit CallDoStuffOnThread(ThreadCheckerClass* thread_checker_class) - : Thread(std::unique_ptr(new rtc::NullSocketServer())), - thread_checker_class_(thread_checker_class) { - SetName("call_do_stuff_on_thread", nullptr); - } - - void Run() override { thread_checker_class_->DoStuff(); } - - // New method. Needed since Thread::Join is protected, and it is called by - // the TEST. - void Join() { Thread::Join(); } - - private: - ThreadCheckerClass* thread_checker_class_; - - RTC_DISALLOW_COPY_AND_ASSIGN(CallDoStuffOnThread); -}; - -// Deletes ThreadCheckerClass on a different thread. -class DeleteThreadCheckerClassOnThread : public Thread { - public: - explicit DeleteThreadCheckerClassOnThread( - std::unique_ptr thread_checker_class) - : Thread(std::unique_ptr(new rtc::NullSocketServer())), - thread_checker_class_(std::move(thread_checker_class)) { - SetName("delete_thread_checker_class_on_thread", nullptr); - } - - void Run() override { thread_checker_class_.reset(); } - - // New method. Needed since Thread::Join is protected, and it is called by - // the TEST. - void Join() { Thread::Join(); } - - bool has_been_deleted() const { return !thread_checker_class_; } - - private: - std::unique_ptr thread_checker_class_; - - RTC_DISALLOW_COPY_AND_ASSIGN(DeleteThreadCheckerClassOnThread); -}; - -} // namespace - -TEST(ThreadCheckerTest, CallsAllowedOnSameThread) { - std::unique_ptr thread_checker_class( - new ThreadCheckerClass); - - // Verify that DoStuff doesn't assert. - thread_checker_class->DoStuff(); - - // Verify that the destructor doesn't assert. - thread_checker_class.reset(); -} - -TEST(ThreadCheckerTest, DestructorAllowedOnDifferentThread) { - std::unique_ptr thread_checker_class( - new ThreadCheckerClass); - - // Verify that the destructor doesn't assert - // when called on a different thread. - DeleteThreadCheckerClassOnThread delete_on_thread( - std::move(thread_checker_class)); - - EXPECT_FALSE(delete_on_thread.has_been_deleted()); - - delete_on_thread.Start(); - delete_on_thread.Join(); - - EXPECT_TRUE(delete_on_thread.has_been_deleted()); -} - -TEST(ThreadCheckerTest, Detach) { - std::unique_ptr thread_checker_class( - new ThreadCheckerClass); - - // Verify that DoStuff doesn't assert when called on a different thread after - // a call to Detach. - thread_checker_class->Detach(); - CallDoStuffOnThread call_on_thread(thread_checker_class.get()); - - call_on_thread.Start(); - call_on_thread.Join(); -} - -#if GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER - -void ThreadCheckerClass::MethodOnDifferentThreadImpl() { - std::unique_ptr thread_checker_class( - new ThreadCheckerClass); - - // DoStuff should assert in debug builds only when called on a - // different thread. - CallDoStuffOnThread call_on_thread(thread_checker_class.get()); - - call_on_thread.Start(); - call_on_thread.Join(); -} - -#if ENABLE_THREAD_CHECKER -TEST(ThreadCheckerDeathTest, MethodNotAllowedOnDifferentThreadInDebug) { - ASSERT_DEATH({ ThreadCheckerClass::MethodOnDifferentThreadImpl(); }, ""); -} -#else -TEST(ThreadCheckerTest, MethodAllowedOnDifferentThreadInRelease) { - ThreadCheckerClass::MethodOnDifferentThreadImpl(); -} -#endif // ENABLE_THREAD_CHECKER - -void ThreadCheckerClass::DetachThenCallFromDifferentThreadImpl() { - std::unique_ptr thread_checker_class( - new ThreadCheckerClass); - - // DoStuff doesn't assert when called on a different thread - // after a call to Detach. - thread_checker_class->Detach(); - CallDoStuffOnThread call_on_thread(thread_checker_class.get()); - - call_on_thread.Start(); - call_on_thread.Join(); - - // DoStuff should assert in debug builds only after moving to - // another thread. - thread_checker_class->DoStuff(); -} - -#if ENABLE_THREAD_CHECKER -TEST(ThreadCheckerDeathTest, DetachFromThreadInDebug) { - ASSERT_DEATH({ ThreadCheckerClass::DetachThenCallFromDifferentThreadImpl(); }, - ""); -} -#else -TEST(ThreadCheckerTest, DetachFromThreadInRelease) { - ThreadCheckerClass::DetachThenCallFromDifferentThreadImpl(); -} -#endif // ENABLE_THREAD_CHECKER - -#endif // GTEST_HAS_DEATH_TEST || !ENABLE_THREAD_CHECKER - -class ThreadAnnotateTest { - public: - // Next two function should create warnings when compile (e.g. if used with - // specific T). - // TODO(danilchap): Find a way to test they do not compile when thread - // annotation checks enabled. - template - void access_var_no_annotate() { - var_thread_ = 42; - } - - template - void access_fun_no_annotate() { - function(); - } - - // Functions below should be able to compile. - void access_var_annotate_thread() { - RTC_DCHECK_RUN_ON(thread_); - var_thread_ = 42; - } - - void access_var_annotate_checker() { - RTC_DCHECK_RUN_ON(&checker_); - var_checker_ = 44; - } - - void access_var_annotate_queue() { - RTC_DCHECK_RUN_ON(queue_); - var_queue_ = 46; - } - - void access_fun_annotate() { - RTC_DCHECK_RUN_ON(thread_); - function(); - } - - void access_fun_and_var() { - RTC_DCHECK_RUN_ON(thread_); - fun_acccess_var(); - } - - private: - void function() RTC_RUN_ON(thread_) {} - void fun_acccess_var() RTC_RUN_ON(thread_) { var_thread_ = 13; } - - rtc::Thread* thread_; - rtc::ThreadChecker checker_; - rtc::TaskQueue* queue_; - - int var_thread_ RTC_GUARDED_BY(thread_); - int var_checker_ RTC_GUARDED_BY(checker_); - int var_queue_ RTC_GUARDED_BY(queue_); -}; - -// Just in case we ever get lumped together with other compilation units. -#undef ENABLE_THREAD_CHECKER - -} // namespace rtc