Migrate stray leftovers from rtc_base/ and test/ to webrtc::Mutex.

Migrates cases found from manual inspection of the code.

Bug: webrtc:11567
Change-Id: Ie8866435f3d3ca325e0811bf7cfb7e388ec987d4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/179067
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31717}
This commit is contained in:
Markus Handell 2020-07-10 13:23:25 +02:00 committed by Commit Bot
parent 4379a7db1f
commit 4ab7ddeb9f
5 changed files with 20 additions and 16 deletions

View File

@ -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",

View File

@ -13,9 +13,9 @@
#include <memory>
#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);
};

View File

@ -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 <comdef.h> // 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<void>(

View File

@ -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",
]
}

View File

@ -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_, &timestamp);
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;
};