Migrate rtc_tools/, sdk/, and system_wrappers/ to webrtc::Mutex.

Bug: webrtc:11567
Change-Id: Ia85cf457ac16ebec0a70d319506415e4dec46f30
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178903
Reviewed-by: Magnus Flodman <mflodman@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31693}
This commit is contained in:
Markus Handell 2020-07-08 23:04:37 +02:00 committed by Commit Bot
parent e6f3897945
commit 85585f4a52
13 changed files with 55 additions and 49 deletions

View File

@ -405,6 +405,7 @@ if (rtc_include_tests) {
"../rtc_base:logging",
"../rtc_base:rtc_event",
"../rtc_base:rtc_task_queue",
"../rtc_base/synchronization:mutex",
"../rtc_base/system:file_wrapper",
"../test:video_test_common",
"../test:video_test_support",

View File

@ -30,9 +30,9 @@
#include "modules/video_coding/include/video_error_codes.h"
#include "modules/video_coding/utility/ivf_file_writer.h"
#include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/logging.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/file_wrapper.h"
#include "rtc_base/task_queue.h"
#include "test/testsupport/frame_reader.h"
@ -78,7 +78,7 @@ class IvfFileWriterEncodedCallback : public EncodedImageCallback {
const RTPFragmentationHeader* fragmentation) override {
RTC_CHECK(file_writer_->WriteFrame(encoded_image, video_codec_type_));
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
received_frames_count_++;
RTC_CHECK_LE(received_frames_count_, expected_frames_count_);
if (received_frames_count_ % kFrameLogInterval == 0) {
@ -99,7 +99,7 @@ class IvfFileWriterEncodedCallback : public EncodedImageCallback {
const VideoCodecType video_codec_type_;
const int expected_frames_count_;
rtc::CriticalSection lock_;
Mutex lock_;
int received_frames_count_ RTC_GUARDED_BY(lock_) = 0;
rtc::Event next_frame_written_;
};

View File

@ -48,6 +48,7 @@ if (rtc_enable_protobuf) {
"../../rtc_base:protobuf_utils",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_task_queue",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:sequence_checker",
"../../rtc_base/third_party/sigslot",
]

View File

@ -43,7 +43,7 @@ void TestController::SendConnectTo(const std::string& hostname, int port) {
NetworkTesterPacket packet;
packet.set_type(NetworkTesterPacket::HAND_SHAKING);
SendData(packet, absl::nullopt);
rtc::CritScope scoped_lock(&local_test_done_lock_);
MutexLock scoped_lock(&local_test_done_lock_);
local_test_done_ = false;
remote_test_done_ = false;
}
@ -71,13 +71,13 @@ void TestController::OnTestDone() {
NetworkTesterPacket packet;
packet.set_type(NetworkTesterPacket::TEST_DONE);
SendData(packet, absl::nullopt);
rtc::CritScope scoped_lock(&local_test_done_lock_);
MutexLock scoped_lock(&local_test_done_lock_);
local_test_done_ = true;
}
bool TestController::IsTestDone() {
RTC_DCHECK_RUN_ON(&test_controller_thread_checker_);
rtc::CritScope scoped_lock(&local_test_done_lock_);
MutexLock scoped_lock(&local_test_done_lock_);
return local_test_done_ && remote_test_done_;
}
@ -100,7 +100,7 @@ void TestController::OnReadPacket(rtc::AsyncPacketSocket* socket,
SendData(packet, absl::nullopt);
packet_sender_.reset(new PacketSender(this, config_file_path_));
packet_sender_->StartSending();
rtc::CritScope scoped_lock(&local_test_done_lock_);
MutexLock scoped_lock(&local_test_done_lock_);
local_test_done_ = false;
remote_test_done_ = false;
break;
@ -108,7 +108,7 @@ void TestController::OnReadPacket(rtc::AsyncPacketSocket* socket,
case NetworkTesterPacket::TEST_START: {
packet_sender_.reset(new PacketSender(this, config_file_path_));
packet_sender_->StartSending();
rtc::CritScope scoped_lock(&local_test_done_lock_);
MutexLock scoped_lock(&local_test_done_lock_);
local_test_done_ = false;
remote_test_done_ = false;
break;

View File

@ -22,9 +22,9 @@
#include "p2p/base/basic_packet_socket_factory.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/ignore_wundef.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread_annotations.h"
@ -35,7 +35,6 @@
#ifdef WEBRTC_NETWORK_TESTER_PROTO
RTC_PUSH_IGNORING_WUNDEF()
#include "rtc_tools/network_tester/network_tester_packet.pb.h"
RTC_POP_IGNORING_WUNDEF()
using webrtc::network_tester::packet::NetworkTesterPacket;
#else
@ -75,7 +74,7 @@ class TestController : public sigslot::has_slots<> {
rtc::BasicPacketSocketFactory socket_factory_;
const std::string config_file_path_;
PacketLogger packet_logger_;
rtc::CriticalSection local_test_done_lock_;
Mutex local_test_done_lock_;
bool local_test_done_ RTC_GUARDED_BY(local_test_done_lock_);
bool remote_test_done_;
std::array<char, kEthernetMtu> send_data_;

View File

@ -653,6 +653,7 @@ if (current_os == "linux" || is_android) {
"../../rtc_base",
"../../rtc_base:checks",
"../../rtc_base:rtc_task_queue",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/task_utils:to_queued_task",
"//third_party/libyuv",
]
@ -1452,6 +1453,7 @@ if (is_android) {
"../../pc:libjingle_peerconnection",
"../../rtc_base:checks",
"../../rtc_base:rtc_base",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/system:inline",
"../../system_wrappers",
"../../system_wrappers:field_trial",

View File

@ -16,9 +16,9 @@
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_device/include/mock_audio_transport.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/format_macros.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h"
#include "sdk/android/generated_native_unittests_jni/BuildInfo_jni.h"
#include "sdk/android/native_api/audio_device_module/audio_device_android.h"
@ -179,7 +179,7 @@ class FifoAudioStream : public AudioStreamInterface {
}
int16_t* memory = new int16_t[frames_per_buffer_];
memcpy(static_cast<int16_t*>(&memory[0]), source, bytes_per_buffer_);
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
fifo_->push_back(memory);
const size_t size = fifo_->size();
if (size > largest_size_) {
@ -195,7 +195,7 @@ class FifoAudioStream : public AudioStreamInterface {
void Read(void* destination, size_t num_frames) override {
ASSERT_EQ(num_frames, frames_per_buffer_);
PRINTD("-");
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
if (fifo_->empty()) {
memset(destination, 0, bytes_per_buffer_);
} else {
@ -226,7 +226,7 @@ class FifoAudioStream : public AudioStreamInterface {
}
using AudioBufferList = std::list<int16_t*>;
rtc::CriticalSection lock_;
Mutex lock_;
const size_t frames_per_buffer_;
const size_t bytes_per_buffer_;
std::unique_ptr<AudioBufferList> fifo_;

View File

@ -16,12 +16,12 @@
#include <memory>
#include <vector>
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/logging.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/inline.h"
#include "system_wrappers/include/sleep.h"
#include "test/gtest.h"
@ -118,15 +118,15 @@ class RtcEventDeadlock : public DeadlockInterface {
class RtcCriticalSectionDeadlock : public DeadlockInterface {
public:
RtcCriticalSectionDeadlock()
: critscope_(std::make_unique<rtc::CritScope>(&crit_)) {}
: mutex_lock_(std::make_unique<MutexLock>(&mutex_)) {}
private:
void Deadlock() override { rtc::CritScope lock(&crit_); }
void Deadlock() override { MutexLock lock(&mutex_); }
void Release() override { critscope_.reset(); }
void Release() override { mutex_lock_.reset(); }
rtc::CriticalSection crit_;
std::unique_ptr<rtc::CritScope> critscope_;
Mutex mutex_;
std::unique_ptr<MutexLock> mutex_lock_;
};
class SpinDeadlock : public DeadlockInterface {

View File

@ -109,7 +109,7 @@ int32_t VideoDecoderWrapper::Decode(
frame_extra_info.qp =
qp_parsing_enabled_ ? ParseQP(input_image) : absl::nullopt;
{
rtc::CritScope cs(&frame_extra_infos_lock_);
MutexLock lock(&frame_extra_infos_lock_);
frame_extra_infos_.push_back(frame_extra_info);
}
@ -135,7 +135,7 @@ int32_t VideoDecoderWrapper::Release() {
jni, Java_VideoDecoder_release(jni, decoder_));
RTC_LOG(LS_INFO) << "release: " << status;
{
rtc::CritScope cs(&frame_extra_infos_lock_);
MutexLock lock(&frame_extra_infos_lock_);
frame_extra_infos_.clear();
}
initialized_ = false;
@ -163,7 +163,7 @@ void VideoDecoderWrapper::OnDecodedFrame(
FrameExtraInfo frame_extra_info;
{
rtc::CritScope cs(&frame_extra_infos_lock_);
MutexLock lock(&frame_extra_infos_lock_);
do {
if (frame_extra_infos_.empty()) {

View File

@ -18,8 +18,8 @@
#include "api/video_codecs/video_decoder.h"
#include "common_video/h264/h264_bitstream_parser.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/race_checker.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h"
#include "sdk/android/src/jni/jni_helpers.h"
@ -105,7 +105,7 @@ class VideoDecoderWrapper : public VideoDecoder {
// Accessed both on the decoder thread and the callback thread.
std::atomic<bool> qp_parsing_enabled_;
rtc::CriticalSection frame_extra_infos_lock_;
Mutex frame_extra_infos_lock_;
std::deque<FrameExtraInfo> frame_extra_infos_
RTC_GUARDED_BY(frame_extra_infos_lock_);
};

View File

@ -35,6 +35,7 @@ rtc_library("system_wrappers") {
"../api/units:timestamp",
"../modules:module_api_public",
"../rtc_base:checks",
"../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:rw_lock_wrapper",
"../rtc_base/system:arch",
"../rtc_base/system:rtc_export",
@ -106,6 +107,7 @@ rtc_library("metrics") {
deps = [
"../rtc_base:checks",
"../rtc_base:rtc_base_approved",
"../rtc_base/synchronization:mutex",
]
}

View File

@ -17,7 +17,6 @@
#include <mmsystem.h>
#include "rtc_base/critical_section.h"
#elif defined(WEBRTC_POSIX)
@ -26,6 +25,7 @@
#endif // defined(WEBRTC_POSIX)
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/rw_lock_wrapper.h"
#include "rtc_base/time_utils.h"
@ -150,7 +150,7 @@ class WindowsRealTimeClock : public RealTimeClock {
DWORD t;
LARGE_INTEGER elapsed_ms;
{
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
// time MUST be fetched inside the critical section to avoid non-monotonic
// last_time_ms_ values that'll register as incorrect wraparounds due to
// concurrent calls to GetTime.
@ -200,7 +200,7 @@ class WindowsRealTimeClock : public RealTimeClock {
return ref;
}
rtc::CriticalSection crit_;
Mutex mutex_;
DWORD last_time_ms_;
LONG num_timer_wraps_;
const ReferencePoint ref_point_;

View File

@ -11,7 +11,8 @@
#include <algorithm>
#include "rtc_base/critical_section.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
// Default implementation of histogram methods for WebRTC clients that do not
@ -38,7 +39,7 @@ class RtcHistogram {
sample = std::min(sample, max_);
sample = std::max(sample, min_ - 1); // Underflow bucket.
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
if (info_.samples.size() == kMaxSampleMapSize &&
info_.samples.find(sample) == info_.samples.end()) {
return;
@ -48,7 +49,7 @@ class RtcHistogram {
// Returns a copy (or nullptr if there are no samples) and clears samples.
std::unique_ptr<SampleInfo> GetAndReset() {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
if (info_.samples.empty())
return nullptr;
@ -64,19 +65,19 @@ class RtcHistogram {
// Functions only for testing.
void Reset() {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
info_.samples.clear();
}
int NumEvents(int sample) const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
const auto it = info_.samples.find(sample);
return (it == info_.samples.end()) ? 0 : it->second;
}
int NumSamples() const {
int num_samples = 0;
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
for (const auto& sample : info_.samples) {
num_samples += sample.second;
}
@ -84,20 +85,20 @@ class RtcHistogram {
}
int MinSample() const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
return (info_.samples.empty()) ? -1 : info_.samples.begin()->first;
}
std::map<int, int> Samples() const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
return info_.samples;
}
private:
rtc::CriticalSection crit_;
mutable Mutex mutex_;
const int min_;
const int max_;
SampleInfo info_ RTC_GUARDED_BY(crit_);
SampleInfo info_ RTC_GUARDED_BY(mutex_);
RTC_DISALLOW_COPY_AND_ASSIGN(RtcHistogram);
};
@ -111,7 +112,7 @@ class RtcHistogramMap {
int min,
int max,
int bucket_count) {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
const auto& it = map_.find(name);
if (it != map_.end())
return reinterpret_cast<Histogram*>(it->second.get());
@ -122,7 +123,7 @@ class RtcHistogramMap {
}
Histogram* GetEnumerationHistogram(const std::string& name, int boundary) {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
const auto& it = map_.find(name);
if (it != map_.end())
return reinterpret_cast<Histogram*>(it->second.get());
@ -134,7 +135,7 @@ class RtcHistogramMap {
void GetAndReset(
std::map<std::string, std::unique_ptr<SampleInfo>>* histograms) {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
for (const auto& kv : map_) {
std::unique_ptr<SampleInfo> info = kv.second->GetAndReset();
if (info)
@ -144,39 +145,39 @@ class RtcHistogramMap {
// Functions only for testing.
void Reset() {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
for (const auto& kv : map_)
kv.second->Reset();
}
int NumEvents(const std::string& name, int sample) const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
const auto& it = map_.find(name);
return (it == map_.end()) ? 0 : it->second->NumEvents(sample);
}
int NumSamples(const std::string& name) const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
const auto& it = map_.find(name);
return (it == map_.end()) ? 0 : it->second->NumSamples();
}
int MinSample(const std::string& name) const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
const auto& it = map_.find(name);
return (it == map_.end()) ? -1 : it->second->MinSample();
}
std::map<int, int> Samples(const std::string& name) const {
rtc::CritScope cs(&crit_);
MutexLock lock(&mutex_);
const auto& it = map_.find(name);
return (it == map_.end()) ? std::map<int, int>() : it->second->Samples();
}
private:
rtc::CriticalSection crit_;
mutable Mutex mutex_;
std::map<std::string, std::unique_ptr<RtcHistogram>> map_
RTC_GUARDED_BY(crit_);
RTC_GUARDED_BY(mutex_);
RTC_DISALLOW_COPY_AND_ASSIGN(RtcHistogramMap);
};