diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 2f0fba9eb2..5ad55988e9 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -1388,6 +1388,7 @@ if (rtc_include_tests) { "../test:test_main", "../test:test_support", "memory:fifo_buffer", + "synchronization:mutex", "synchronization:synchronization_unittests", "task_utils:to_queued_task", "third_party/sigslot", diff --git a/rtc_base/deprecated/signal_thread_unittest.cc b/rtc_base/deprecated/signal_thread_unittest.cc index c280e970be..f5a49aad63 100644 --- a/rtc_base/deprecated/signal_thread_unittest.cc +++ b/rtc_base/deprecated/signal_thread_unittest.cc @@ -13,9 +13,9 @@ #include #include "rtc_base/constructor_magic.h" -#include "rtc_base/critical_section.h" #include "rtc_base/gunit.h" #include "rtc_base/null_socket_server.h" +#include "rtc_base/synchronization/mutex.h" #include "rtc_base/thread.h" #include "rtc_base/thread_annotations.h" #include "test/gtest.h" @@ -148,13 +148,13 @@ class OwnerThread : public Thread, public sigslot::has_slots<> { // Delete |signal_thread|. signal_thread->Destroy(true); { - rtc::CritScope cs(&crit_); + webrtc::MutexLock lock(&mutex_); has_run_ = true; } } bool has_run() { - rtc::CritScope cs(&crit_); + webrtc::MutexLock lock(&mutex_); return has_run_; } void OnWorkDone(DEPRECATED_SignalThread* /*signal_thread*/) { @@ -162,9 +162,9 @@ class OwnerThread : public Thread, public sigslot::has_slots<> { } private: - rtc::CriticalSection crit_; + webrtc::Mutex mutex_; SignalThreadTest* harness_; - bool has_run_ RTC_GUARDED_BY(crit_); + bool has_run_ RTC_GUARDED_BY(mutex_); RTC_DISALLOW_COPY_AND_ASSIGN(OwnerThread); }; diff --git a/rtc_base/thread_unittest.cc b/rtc_base/thread_unittest.cc index bc0c3442eb..d3cae34dfa 100644 --- a/rtc_base/thread_unittest.cc +++ b/rtc_base/thread_unittest.cc @@ -22,12 +22,14 @@ #include "rtc_base/null_socket_server.h" #include "rtc_base/physical_socket_server.h" #include "rtc_base/socket_address.h" +#include "rtc_base/synchronization/mutex.h" #include "rtc_base/task_utils/to_queued_task.h" #include "rtc_base/third_party/sigslot/sigslot.h" #include "test/testsupport/rtc_expect_death.h" #if defined(WEBRTC_WIN) #include // NOLINT + #endif namespace rtc { @@ -161,17 +163,17 @@ class AtomicBool { public: explicit AtomicBool(bool value = false) : flag_(value) {} AtomicBool& operator=(bool value) { - CritScope scoped_lock(&cs_); + webrtc::MutexLock scoped_lock(&mutex_); flag_ = value; return *this; } bool get() const { - CritScope scoped_lock(&cs_); + webrtc::MutexLock scoped_lock(&mutex_); return flag_; } private: - CriticalSection cs_; + mutable webrtc::Mutex mutex_; bool flag_; }; @@ -413,18 +415,18 @@ TEST(ThreadTest, ThreeThreadsInvoke) { explicit LockedBool(bool value) : value_(value) {} void Set(bool value) { - CritScope lock(&crit_); + webrtc::MutexLock lock(&mutex_); value_ = value; } bool Get() { - CritScope lock(&crit_); + webrtc::MutexLock lock(&mutex_); return value_; } private: - CriticalSection crit_; - bool value_ RTC_GUARDED_BY(crit_); + webrtc::Mutex mutex_; + bool value_ RTC_GUARDED_BY(mutex_); }; struct LocalFuncs { @@ -447,7 +449,6 @@ TEST(ThreadTest, ThreeThreadsInvoke) { Thread* thread1, Thread* thread2, LockedBool* out) { - CriticalSection crit; LockedBool async_invoked(false); invoker->AsyncInvoke( diff --git a/test/network/BUILD.gn b/test/network/BUILD.gn index 949b201c72..35673741ce 100644 --- a/test/network/BUILD.gn +++ b/test/network/BUILD.gn @@ -75,6 +75,7 @@ rtc_library("network_emulation_unittest") { "../../rtc_base:gunit_helpers", "../../rtc_base:logging", "../../rtc_base:rtc_event", + "../../rtc_base/synchronization:mutex", "../../system_wrappers:system_wrappers", ] } diff --git a/test/network/network_emulation_unittest.cc b/test/network/network_emulation_unittest.cc index 9e630de9cb..6bd3b6ebc7 100644 --- a/test/network/network_emulation_unittest.cc +++ b/test/network/network_emulation_unittest.cc @@ -19,6 +19,7 @@ #include "call/simulated_network.h" #include "rtc_base/event.h" #include "rtc_base/gunit.h" +#include "rtc_base/synchronization/mutex.h" #include "system_wrappers/include/sleep.h" #include "test/gmock.h" #include "test/gtest.h" @@ -48,12 +49,12 @@ class SocketReader : public sigslot::has_slots<> { int64_t timestamp; len_ = socket_->Recv(buf_, size_, ×tamp); - rtc::CritScope crit(&lock_); + MutexLock lock(&lock_); received_count_++; } int ReceivedCount() { - rtc::CritScope crit(&lock_); + MutexLock lock(&lock_); return received_count_; } @@ -64,7 +65,7 @@ class SocketReader : public sigslot::has_slots<> { size_t size_; int len_; - rtc::CriticalSection lock_; + Mutex lock_; int received_count_ RTC_GUARDED_BY(lock_) = 0; };