Migrate rtc_base to webrtc::Mutex.

Bug: webrtc:11567
Change-Id: Ib8630e0cf1266e7c3f8ce718e1ed9f8848f42ec8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178806
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31682}
This commit is contained in:
Markus Handell 2020-07-08 17:55:58 +02:00 committed by Commit Bot
parent 44dd3d7435
commit 18523c34b4
35 changed files with 130 additions and 102 deletions

View File

@ -14,6 +14,7 @@
#include <vector> #include <vector>
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
// Forward declaration to avoid pulling in libsrtp headers here // Forward declaration to avoid pulling in libsrtp headers here

View File

@ -17,6 +17,7 @@
#include "media/base/fake_rtp.h" #include "media/base/fake_rtp.h"
#include "pc/test/srtp_test_util.h" #include "pc/test/srtp_test_util.h"
#include "rtc_base/byte_order.h" #include "rtc_base/byte_order.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/ssl_stream_adapter.h" // For rtc::SRTP_* #include "rtc_base/ssl_stream_adapter.h" // For rtc::SRTP_*
#include "system_wrappers/include/metrics.h" #include "system_wrappers/include/metrics.h"
#include "test/gmock.h" #include "test/gmock.h"

View File

@ -55,6 +55,7 @@ rtc_library("rtc_base_approved") {
":type_traits", ":type_traits",
"../api:array_view", "../api:array_view",
"../api:scoped_refptr", "../api:scoped_refptr",
"synchronization:mutex",
"system:arch", "system:arch",
"system:rtc_export", "system:rtc_export",
"system:unused", "system:unused",
@ -325,6 +326,7 @@ rtc_library("rate_limiter") {
deps = [ deps = [
":rtc_base_approved", ":rtc_base_approved",
"../system_wrappers", "../system_wrappers",
"synchronization:mutex",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
} }
@ -479,6 +481,7 @@ if (rtc_enable_libevent) {
":safe_conversions", ":safe_conversions",
":timeutils", ":timeutils",
"../api/task_queue", "../api/task_queue",
"synchronization:mutex",
] ]
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/container:inlined_vector", "//third_party/abseil-cpp/absl/container:inlined_vector",
@ -501,6 +504,7 @@ if (is_mac || is_ios) {
":checks", ":checks",
":logging", ":logging",
"../api/task_queue", "../api/task_queue",
"synchronization:mutex",
"system:gcd_helpers", "system:gcd_helpers",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
@ -524,6 +528,7 @@ if (is_win) {
":safe_conversions", ":safe_conversions",
":timeutils", ":timeutils",
"../api/task_queue", "../api/task_queue",
"synchronization:mutex",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
} }
@ -544,6 +549,7 @@ rtc_library("rtc_task_queue_stdlib") {
":safe_conversions", ":safe_conversions",
":timeutils", ":timeutils",
"../api/task_queue", "../api/task_queue",
"synchronization:mutex",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
} }
@ -782,6 +788,7 @@ rtc_library("rtc_base") {
"../api/task_queue", "../api/task_queue",
"../system_wrappers:field_trial", "../system_wrappers:field_trial",
"network:sent_packet", "network:sent_packet",
"synchronization:mutex",
"synchronization:sequence_checker", "synchronization:sequence_checker",
"system:file_wrapper", "system:file_wrapper",
"system:inline", "system:inline",
@ -1037,6 +1044,7 @@ rtc_library("testclient") {
":rtc_base", ":rtc_base",
":rtc_base_tests_utils", ":rtc_base_tests_utils",
":timeutils", ":timeutils",
"synchronization:mutex",
] ]
} }
@ -1085,6 +1093,7 @@ rtc_library("rtc_base_tests_utils") {
"../api/units:time_delta", "../api/units:time_delta",
"../api/units:timestamp", "../api/units:timestamp",
"memory:fifo_buffer", "memory:fifo_buffer",
"synchronization:mutex",
"third_party/sigslot", "third_party/sigslot",
] ]
absl_deps = [ absl_deps = [
@ -1122,6 +1131,7 @@ if (rtc_include_tests) {
":rtc_base", ":rtc_base",
":rtc_base_tests_utils", ":rtc_base_tests_utils",
"../test:test_support", "../test:test_support",
"synchronization:mutex",
"third_party/sigslot", "third_party/sigslot",
] ]
} }
@ -1230,6 +1240,7 @@ if (rtc_include_tests) {
"../test:test_main", "../test:test_main",
"../test:test_support", "../test:test_support",
"memory:unittests", "memory:unittests",
"synchronization:mutex",
"task_utils:to_queued_task", "task_utils:to_queued_task",
"third_party/base64", "third_party/base64",
"third_party/sigslot", "third_party/sigslot",

View File

@ -21,7 +21,7 @@ BufferQueue::BufferQueue(size_t capacity, size_t default_size)
: capacity_(capacity), default_size_(default_size) {} : capacity_(capacity), default_size_(default_size) {}
BufferQueue::~BufferQueue() { BufferQueue::~BufferQueue() {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
for (Buffer* buffer : queue_) { for (Buffer* buffer : queue_) {
delete buffer; delete buffer;
@ -32,12 +32,12 @@ BufferQueue::~BufferQueue() {
} }
size_t BufferQueue::size() const { size_t BufferQueue::size() const {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return queue_.size(); return queue_.size();
} }
void BufferQueue::Clear() { void BufferQueue::Clear() {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
while (!queue_.empty()) { while (!queue_.empty()) {
free_list_.push_back(queue_.front()); free_list_.push_back(queue_.front());
queue_.pop_front(); queue_.pop_front();
@ -45,7 +45,7 @@ void BufferQueue::Clear() {
} }
bool BufferQueue::ReadFront(void* buffer, size_t bytes, size_t* bytes_read) { bool BufferQueue::ReadFront(void* buffer, size_t bytes, size_t* bytes_read) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (queue_.empty()) { if (queue_.empty()) {
return false; return false;
} }
@ -69,7 +69,7 @@ bool BufferQueue::ReadFront(void* buffer, size_t bytes, size_t* bytes_read) {
bool BufferQueue::WriteBack(const void* buffer, bool BufferQueue::WriteBack(const void* buffer,
size_t bytes, size_t bytes,
size_t* bytes_written) { size_t* bytes_written) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (queue_.size() == capacity_) { if (queue_.size() == capacity_) {
return false; return false;
} }

View File

@ -18,7 +18,7 @@
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
namespace rtc { namespace rtc {
@ -52,9 +52,9 @@ class BufferQueue {
private: private:
size_t capacity_; size_t capacity_;
size_t default_size_; size_t default_size_;
CriticalSection crit_; mutable webrtc::Mutex mutex_;
std::deque<Buffer*> queue_ RTC_GUARDED_BY(crit_); std::deque<Buffer*> queue_ RTC_GUARDED_BY(mutex_);
std::vector<Buffer*> free_list_ RTC_GUARDED_BY(crit_); std::vector<Buffer*> free_list_ RTC_GUARDED_BY(mutex_);
RTC_DISALLOW_COPY_AND_ASSIGN(BufferQueue); RTC_DISALLOW_COPY_AND_ASSIGN(BufferQueue);
}; };

View File

@ -19,11 +19,11 @@
#include "rtc_base/atomic_ops.h" #include "rtc_base/atomic_ops.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/platform_thread_types.h" #include "rtc_base/platform_thread_types.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
@ -120,7 +120,7 @@ class EventLogger final {
arg.value.as_string = str_copy; arg.value.as_string = str_copy;
} }
} }
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
trace_events_.push_back( trace_events_.push_back(
{name, category_enabled, phase, args, timestamp, 1, thread_id}); {name, category_enabled, phase, args, timestamp, 1, thread_id});
} }
@ -136,7 +136,7 @@ class EventLogger final {
bool shutting_down = shutdown_event_.Wait(kLoggingIntervalMs); bool shutting_down = shutdown_event_.Wait(kLoggingIntervalMs);
std::vector<TraceEvent> events; std::vector<TraceEvent> events;
{ {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
trace_events_.swap(events); trace_events_.swap(events);
} }
std::string args_str; std::string args_str;
@ -196,7 +196,7 @@ class EventLogger final {
output_file_ = file; output_file_ = file;
output_file_owned_ = owned; output_file_owned_ = owned;
{ {
rtc::CritScope lock(&crit_); webrtc::MutexLock lock(&mutex_);
// Since the atomic fast-path for adding events to the queue can be // Since the atomic fast-path for adding events to the queue can be
// bypassed while the logging thread is shutting down there may be some // bypassed while the logging thread is shutting down there may be some
// stale events in the queue, hence the vector needs to be cleared to not // stale events in the queue, hence the vector needs to be cleared to not
@ -317,8 +317,8 @@ class EventLogger final {
return output; return output;
} }
rtc::CriticalSection crit_; webrtc::Mutex mutex_;
std::vector<TraceEvent> trace_events_ RTC_GUARDED_BY(crit_); std::vector<TraceEvent> trace_events_ RTC_GUARDED_BY(mutex_);
rtc::PlatformThread logging_thread_; rtc::PlatformThread logging_thread_;
rtc::Event shutdown_event_; rtc::Event shutdown_event_;
rtc::ThreadChecker thread_checker_; rtc::ThreadChecker thread_checker_;

View File

@ -10,7 +10,7 @@
#include "rtc_base/event_tracer.h" #include "rtc_base/event_tracer.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/trace_event.h" #include "rtc_base/trace_event.h"
#include "test/gtest.h" #include "test/gtest.h"
@ -20,17 +20,17 @@ namespace {
class TestStatistics { class TestStatistics {
public: public:
void Reset() { void Reset() {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
events_logged_ = 0; events_logged_ = 0;
} }
void Increment() { void Increment() {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
++events_logged_; ++events_logged_;
} }
int Count() const { int Count() const {
rtc::CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return events_logged_; return events_logged_;
} }
@ -41,8 +41,8 @@ class TestStatistics {
} }
private: private:
rtc::CriticalSection crit_; mutable webrtc::Mutex mutex_;
int events_logged_ RTC_GUARDED_BY(crit_) = 0; int events_logged_ RTC_GUARDED_BY(mutex_) = 0;
}; };
} // namespace } // namespace

View File

@ -16,18 +16,18 @@
namespace rtc { namespace rtc {
int64_t FakeClock::TimeNanos() const { int64_t FakeClock::TimeNanos() const {
CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
return time_ns_; return time_ns_;
} }
void FakeClock::SetTime(webrtc::Timestamp new_time) { void FakeClock::SetTime(webrtc::Timestamp new_time) {
CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
RTC_DCHECK(new_time.us() * 1000 >= time_ns_); RTC_DCHECK(new_time.us() * 1000 >= time_ns_);
time_ns_ = new_time.us() * 1000; time_ns_ = new_time.us() * 1000;
} }
void FakeClock::AdvanceTime(webrtc::TimeDelta delta) { void FakeClock::AdvanceTime(webrtc::TimeDelta delta) {
CritScope cs(&lock_); webrtc::MutexLock lock(&lock_);
time_ns_ += delta.ns(); time_ns_ += delta.ns();
} }

View File

@ -15,7 +15,7 @@
#include "api/units/time_delta.h" #include "api/units/time_delta.h"
#include "api/units/timestamp.h" #include "api/units/timestamp.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
@ -43,7 +43,7 @@ class FakeClock : public ClockInterface {
void AdvanceTime(webrtc::TimeDelta delta); void AdvanceTime(webrtc::TimeDelta delta);
private: private:
CriticalSection lock_; mutable webrtc::Mutex lock_;
int64_t time_ns_ RTC_GUARDED_BY(lock_) = 0; int64_t time_ns_ RTC_GUARDED_BY(lock_) = 0;
}; };

View File

@ -163,19 +163,19 @@ void FirewallSocketServer::AddRule(bool allow,
r.p = p; r.p = p;
r.src = src; r.src = src;
r.dst = dst; r.dst = dst;
CritScope scope(&crit_); webrtc::MutexLock scope(&mutex_);
rules_.push_back(r); rules_.push_back(r);
} }
void FirewallSocketServer::ClearRules() { void FirewallSocketServer::ClearRules() {
CritScope scope(&crit_); webrtc::MutexLock scope(&mutex_);
rules_.clear(); rules_.clear();
} }
bool FirewallSocketServer::Check(FirewallProtocol p, bool FirewallSocketServer::Check(FirewallProtocol p,
const SocketAddress& src, const SocketAddress& src,
const SocketAddress& dst) { const SocketAddress& dst) {
CritScope scope(&crit_); webrtc::MutexLock scope(&mutex_);
for (size_t i = 0; i < rules_.size(); ++i) { for (size_t i = 0; i < rules_.size(); ++i) {
const Rule& r = rules_[i]; const Rule& r = rules_[i];
if ((r.p != p) && (r.p != FP_ANY)) if ((r.p != p) && (r.p != FP_ANY))
@ -239,12 +239,12 @@ FirewallManager::~FirewallManager() {
} }
void FirewallManager::AddServer(FirewallSocketServer* server) { void FirewallManager::AddServer(FirewallSocketServer* server) {
CritScope scope(&crit_); webrtc::MutexLock scope(&mutex_);
servers_.push_back(server); servers_.push_back(server);
} }
void FirewallManager::RemoveServer(FirewallSocketServer* server) { void FirewallManager::RemoveServer(FirewallSocketServer* server) {
CritScope scope(&crit_); webrtc::MutexLock scope(&mutex_);
servers_.erase(std::remove(servers_.begin(), servers_.end(), server), servers_.erase(std::remove(servers_.begin(), servers_.end(), server),
servers_.end()); servers_.end());
} }
@ -253,7 +253,7 @@ void FirewallManager::AddRule(bool allow,
FirewallProtocol p, FirewallProtocol p,
FirewallDirection d, FirewallDirection d,
const SocketAddress& addr) { const SocketAddress& addr) {
CritScope scope(&crit_); webrtc::MutexLock scope(&mutex_);
for (std::vector<FirewallSocketServer*>::const_iterator it = servers_.begin(); for (std::vector<FirewallSocketServer*>::const_iterator it = servers_.begin();
it != servers_.end(); ++it) { it != servers_.end(); ++it) {
(*it)->AddRule(allow, p, d, addr); (*it)->AddRule(allow, p, d, addr);
@ -261,7 +261,7 @@ void FirewallManager::AddRule(bool allow,
} }
void FirewallManager::ClearRules() { void FirewallManager::ClearRules() {
CritScope scope(&crit_); webrtc::MutexLock scope(&mutex_);
for (std::vector<FirewallSocketServer*>::const_iterator it = servers_.begin(); for (std::vector<FirewallSocketServer*>::const_iterator it = servers_.begin();
it != servers_.end(); ++it) { it != servers_.end(); ++it) {
(*it)->ClearRules(); (*it)->ClearRules();

View File

@ -14,11 +14,11 @@
#include <vector> #include <vector>
#include "rtc_base/async_socket.h" #include "rtc_base/async_socket.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/ip_address.h" #include "rtc_base/ip_address.h"
#include "rtc_base/socket.h" #include "rtc_base/socket.h"
#include "rtc_base/socket_address.h" #include "rtc_base/socket_address.h"
#include "rtc_base/socket_server.h" #include "rtc_base/socket_server.h"
#include "rtc_base/synchronization/mutex.h"
namespace rtc { namespace rtc {
@ -90,7 +90,7 @@ class FirewallSocketServer : public SocketServer {
private: private:
SocketServer* server_; SocketServer* server_;
FirewallManager* manager_; FirewallManager* manager_;
CriticalSection crit_; webrtc::Mutex mutex_;
struct Rule { struct Rule {
bool allow; bool allow;
FirewallProtocol p; FirewallProtocol p;
@ -123,7 +123,7 @@ class FirewallManager {
void ClearRules(); void ClearRules();
private: private:
CriticalSection crit_; webrtc::Mutex mutex_;
std::vector<FirewallSocketServer*> servers_; std::vector<FirewallSocketServer*> servers_;
}; };

View File

@ -31,7 +31,10 @@ rtc_library("fifo_buffer") {
"fifo_buffer.cc", "fifo_buffer.cc",
"fifo_buffer.h", "fifo_buffer.h",
] ]
deps = [ "..:rtc_base" ] deps = [
"..:rtc_base",
"../synchronization:mutex",
]
} }
rtc_library("unittests") { rtc_library("unittests") {

View File

@ -39,13 +39,13 @@ FifoBuffer::FifoBuffer(size_t size, Thread* owner)
FifoBuffer::~FifoBuffer() {} FifoBuffer::~FifoBuffer() {}
bool FifoBuffer::GetBuffered(size_t* size) const { bool FifoBuffer::GetBuffered(size_t* size) const {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
*size = data_length_; *size = data_length_;
return true; return true;
} }
bool FifoBuffer::SetCapacity(size_t size) { bool FifoBuffer::SetCapacity(size_t size) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (data_length_ > size) { if (data_length_ > size) {
return false; return false;
} }
@ -67,7 +67,7 @@ StreamResult FifoBuffer::ReadOffset(void* buffer,
size_t bytes, size_t bytes,
size_t offset, size_t offset,
size_t* bytes_read) { size_t* bytes_read) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return ReadOffsetLocked(buffer, bytes, offset, bytes_read); return ReadOffsetLocked(buffer, bytes, offset, bytes_read);
} }
@ -75,12 +75,12 @@ StreamResult FifoBuffer::WriteOffset(const void* buffer,
size_t bytes, size_t bytes,
size_t offset, size_t offset,
size_t* bytes_written) { size_t* bytes_written) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return WriteOffsetLocked(buffer, bytes, offset, bytes_written); return WriteOffsetLocked(buffer, bytes, offset, bytes_written);
} }
StreamState FifoBuffer::GetState() const { StreamState FifoBuffer::GetState() const {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return state_; return state_;
} }
@ -88,7 +88,7 @@ StreamResult FifoBuffer::Read(void* buffer,
size_t bytes, size_t bytes,
size_t* bytes_read, size_t* bytes_read,
int* error) { int* error) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
const bool was_writable = data_length_ < buffer_length_; const bool was_writable = data_length_ < buffer_length_;
size_t copy = 0; size_t copy = 0;
StreamResult result = ReadOffsetLocked(buffer, bytes, 0, &copy); StreamResult result = ReadOffsetLocked(buffer, bytes, 0, &copy);
@ -114,7 +114,7 @@ StreamResult FifoBuffer::Write(const void* buffer,
size_t bytes, size_t bytes,
size_t* bytes_written, size_t* bytes_written,
int* error) { int* error) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
const bool was_readable = (data_length_ > 0); const bool was_readable = (data_length_ > 0);
size_t copy = 0; size_t copy = 0;
@ -136,12 +136,12 @@ StreamResult FifoBuffer::Write(const void* buffer,
} }
void FifoBuffer::Close() { void FifoBuffer::Close() {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
state_ = SS_CLOSED; state_ = SS_CLOSED;
} }
const void* FifoBuffer::GetReadData(size_t* size) { const void* FifoBuffer::GetReadData(size_t* size) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
*size = (read_position_ + data_length_ <= buffer_length_) *size = (read_position_ + data_length_ <= buffer_length_)
? data_length_ ? data_length_
: buffer_length_ - read_position_; : buffer_length_ - read_position_;
@ -149,7 +149,7 @@ const void* FifoBuffer::GetReadData(size_t* size) {
} }
void FifoBuffer::ConsumeReadData(size_t size) { void FifoBuffer::ConsumeReadData(size_t size) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
RTC_DCHECK(size <= data_length_); RTC_DCHECK(size <= data_length_);
const bool was_writable = data_length_ < buffer_length_; const bool was_writable = data_length_ < buffer_length_;
read_position_ = (read_position_ + size) % buffer_length_; read_position_ = (read_position_ + size) % buffer_length_;
@ -160,7 +160,7 @@ void FifoBuffer::ConsumeReadData(size_t size) {
} }
void* FifoBuffer::GetWriteBuffer(size_t* size) { void* FifoBuffer::GetWriteBuffer(size_t* size) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (state_ == SS_CLOSED) { if (state_ == SS_CLOSED) {
return nullptr; return nullptr;
} }
@ -180,7 +180,7 @@ void* FifoBuffer::GetWriteBuffer(size_t* size) {
} }
void FifoBuffer::ConsumeWriteBuffer(size_t size) { void FifoBuffer::ConsumeWriteBuffer(size_t size) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
RTC_DCHECK(size <= buffer_length_ - data_length_); RTC_DCHECK(size <= buffer_length_ - data_length_);
const bool was_readable = (data_length_ > 0); const bool was_readable = (data_length_ > 0);
data_length_ += size; data_length_ += size;
@ -190,7 +190,7 @@ void FifoBuffer::ConsumeWriteBuffer(size_t size) {
} }
bool FifoBuffer::GetWriteRemaining(size_t* size) const { bool FifoBuffer::GetWriteRemaining(size_t* size) const {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
*size = buffer_length_ - data_length_; *size = buffer_length_ - data_length_;
return true; return true;
} }

View File

@ -14,6 +14,7 @@
#include <memory> #include <memory>
#include "rtc_base/stream.h" #include "rtc_base/stream.h"
#include "rtc_base/synchronization/mutex.h"
namespace rtc { namespace rtc {
@ -103,7 +104,7 @@ class FifoBuffer final : public StreamInterface {
size_t bytes, size_t bytes,
size_t offset, size_t offset,
size_t* bytes_read) size_t* bytes_read)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Helper method that implements WriteOffset. Caller must acquire a lock // Helper method that implements WriteOffset. Caller must acquire a lock
// when calling this method. // when calling this method.
@ -111,22 +112,22 @@ class FifoBuffer final : public StreamInterface {
size_t bytes, size_t bytes,
size_t offset, size_t offset,
size_t* bytes_written) size_t* bytes_written)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// keeps the opened/closed state of the stream // keeps the opened/closed state of the stream
StreamState state_ RTC_GUARDED_BY(crit_); StreamState state_ RTC_GUARDED_BY(mutex_);
// the allocated buffer // the allocated buffer
std::unique_ptr<char[]> buffer_ RTC_GUARDED_BY(crit_); std::unique_ptr<char[]> buffer_ RTC_GUARDED_BY(mutex_);
// size of the allocated buffer // size of the allocated buffer
size_t buffer_length_ RTC_GUARDED_BY(crit_); size_t buffer_length_ RTC_GUARDED_BY(mutex_);
// amount of readable data in the buffer // amount of readable data in the buffer
size_t data_length_ RTC_GUARDED_BY(crit_); size_t data_length_ RTC_GUARDED_BY(mutex_);
// offset to the readable data // offset to the readable data
size_t read_position_ RTC_GUARDED_BY(crit_); size_t read_position_ RTC_GUARDED_BY(mutex_);
// stream callbacks are dispatched on this thread // stream callbacks are dispatched on this thread
Thread* owner_; Thread* owner_;
// object lock // object lock
CriticalSection crit_; mutable webrtc::Mutex mutex_;
RTC_DISALLOW_COPY_AND_ASSIGN(FifoBuffer); RTC_DISALLOW_COPY_AND_ASSIGN(FifoBuffer);
}; };

View File

@ -243,12 +243,12 @@ NATServer::TransEntry::~TransEntry() {
} }
void NATServer::TransEntry::AllowlistInsert(const SocketAddress& addr) { void NATServer::TransEntry::AllowlistInsert(const SocketAddress& addr) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
allowlist->insert(addr); allowlist->insert(addr);
} }
bool NATServer::TransEntry::AllowlistContains(const SocketAddress& ext_addr) { bool NATServer::TransEntry::AllowlistContains(const SocketAddress& ext_addr) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
return allowlist->find(ext_addr) == allowlist->end(); return allowlist->find(ext_addr) == allowlist->end();
} }

View File

@ -20,6 +20,7 @@
#include "rtc_base/proxy_server.h" #include "rtc_base/proxy_server.h"
#include "rtc_base/socket_address_pair.h" #include "rtc_base/socket_address_pair.h"
#include "rtc_base/socket_factory.h" #include "rtc_base/socket_factory.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
namespace rtc { namespace rtc {
@ -102,7 +103,7 @@ class NATServer : public sigslot::has_slots<> {
SocketAddressPair route; SocketAddressPair route;
AsyncUDPSocket* socket; AsyncUDPSocket* socket;
AddressSet* allowlist; AddressSet* allowlist;
CriticalSection crit_; webrtc::Mutex mutex_;
}; };
typedef std::map<SocketAddressPair, TransEntry*, RouteCmp> InternalMap; typedef std::map<SocketAddressPair, TransEntry*, RouteCmp> InternalMap;

View File

@ -11,7 +11,7 @@
#ifndef RTC_BASE_ONE_TIME_EVENT_H_ #ifndef RTC_BASE_ONE_TIME_EVENT_H_
#define RTC_BASE_ONE_TIME_EVENT_H_ #define RTC_BASE_ONE_TIME_EVENT_H_
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
namespace webrtc { namespace webrtc {
// Provides a simple way to perform an operation (such as logging) one // Provides a simple way to perform an operation (such as logging) one
@ -26,7 +26,7 @@ class OneTimeEvent {
public: public:
OneTimeEvent() {} OneTimeEvent() {}
bool operator()() { bool operator()() {
rtc::CritScope cs(&critsect_); MutexLock lock(&mutex_);
if (happened_) { if (happened_) {
return false; return false;
} }
@ -36,7 +36,7 @@ class OneTimeEvent {
private: private:
bool happened_ = false; bool happened_ = false;
rtc::CriticalSection critsect_; Mutex mutex_;
}; };
// A non-thread-safe, ligher-weight version of the OneTimeEvent class. // A non-thread-safe, ligher-weight version of the OneTimeEvent class.

View File

@ -31,7 +31,7 @@ RateLimiter::~RateLimiter() {}
// calling SetMaxRate() and a timed maintenance thread periodically updating // calling SetMaxRate() and a timed maintenance thread periodically updating
// the RTT. // the RTT.
bool RateLimiter::TryUseRate(size_t packet_size_bytes) { bool RateLimiter::TryUseRate(size_t packet_size_bytes) {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
int64_t now_ms = clock_->TimeInMilliseconds(); int64_t now_ms = clock_->TimeInMilliseconds();
absl::optional<uint32_t> current_rate = current_rate_.Rate(now_ms); absl::optional<uint32_t> current_rate = current_rate_.Rate(now_ms);
if (current_rate) { if (current_rate) {
@ -53,14 +53,14 @@ bool RateLimiter::TryUseRate(size_t packet_size_bytes) {
} }
void RateLimiter::SetMaxRate(uint32_t max_rate_bps) { void RateLimiter::SetMaxRate(uint32_t max_rate_bps) {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
max_rate_bps_ = max_rate_bps; max_rate_bps_ = max_rate_bps;
} }
// Set the window size over which to measure the current bitrate. // Set the window size over which to measure the current bitrate.
// For retransmissions, this is typically the RTT. // For retransmissions, this is typically the RTT.
bool RateLimiter::SetWindowSize(int64_t window_size_ms) { bool RateLimiter::SetWindowSize(int64_t window_size_ms) {
rtc::CritScope cs(&lock_); MutexLock lock(&lock_);
window_size_ms_ = window_size_ms; window_size_ms_ = window_size_ms;
return current_rate_.SetWindowSize(window_size_ms, return current_rate_.SetWindowSize(window_size_ms,
clock_->TimeInMilliseconds()); clock_->TimeInMilliseconds());

View File

@ -15,8 +15,8 @@
#include <stdint.h> #include <stdint.h>
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/rate_statistics.h" #include "rtc_base/rate_statistics.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
namespace webrtc { namespace webrtc {
@ -45,7 +45,7 @@ class RateLimiter {
private: private:
Clock* const clock_; Clock* const clock_;
rtc::CriticalSection lock_; Mutex lock_;
RateStatistics current_rate_ RTC_GUARDED_BY(lock_); RateStatistics current_rate_ RTC_GUARDED_BY(lock_);
int64_t window_size_ms_ RTC_GUARDED_BY(lock_); int64_t window_size_ms_ RTC_GUARDED_BY(lock_);
uint32_t max_rate_bps_ RTC_GUARDED_BY(lock_); uint32_t max_rate_bps_ RTC_GUARDED_BY(lock_);

View File

@ -68,6 +68,7 @@ rtc_library("sequence_checker") {
"sequence_checker.h", "sequence_checker.h",
] ]
deps = [ deps = [
":mutex",
"..:checks", "..:checks",
"..:criticalsection", "..:criticalsection",
"..:macromagic", "..:macromagic",

View File

@ -48,7 +48,7 @@ bool SequenceCheckerImpl::IsCurrent() const {
const TaskQueueBase* const current_queue = TaskQueueBase::Current(); const TaskQueueBase* const current_queue = TaskQueueBase::Current();
const rtc::PlatformThreadRef current_thread = rtc::CurrentThreadRef(); const rtc::PlatformThreadRef current_thread = rtc::CurrentThreadRef();
const void* const current_system_queue = GetSystemQueueRef(); const void* const current_system_queue = GetSystemQueueRef();
rtc::CritScope scoped_lock(&lock_); MutexLock scoped_lock(&lock_);
if (!attached_) { // Previously detached. if (!attached_) { // Previously detached.
attached_ = true; attached_ = true;
valid_thread_ = current_thread; valid_thread_ = current_thread;
@ -66,7 +66,7 @@ bool SequenceCheckerImpl::IsCurrent() const {
} }
void SequenceCheckerImpl::Detach() { void SequenceCheckerImpl::Detach() {
rtc::CritScope scoped_lock(&lock_); MutexLock scoped_lock(&lock_);
attached_ = false; attached_ = false;
// We don't need to touch the other members here, they will be // We don't need to touch the other members here, they will be
// reset on the next call to IsCurrent(). // reset on the next call to IsCurrent().
@ -77,7 +77,7 @@ std::string SequenceCheckerImpl::ExpectationToString() const {
const TaskQueueBase* const current_queue = TaskQueueBase::Current(); const TaskQueueBase* const current_queue = TaskQueueBase::Current();
const rtc::PlatformThreadRef current_thread = rtc::CurrentThreadRef(); const rtc::PlatformThreadRef current_thread = rtc::CurrentThreadRef();
const void* const current_system_queue = GetSystemQueueRef(); const void* const current_system_queue = GetSystemQueueRef();
rtc::CritScope scoped_lock(&lock_); MutexLock scoped_lock(&lock_);
if (!attached_) if (!attached_)
return "Checker currently not attached."; return "Checker currently not attached.";

View File

@ -13,8 +13,8 @@
#include <type_traits> #include <type_traits>
#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_base.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/platform_thread_types.h" #include "rtc_base/platform_thread_types.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/rtc_export.h" #include "rtc_base/system/rtc_export.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
@ -42,7 +42,7 @@ class RTC_EXPORT SequenceCheckerImpl {
std::string ExpectationToString() const; std::string ExpectationToString() const;
private: private:
rtc::CriticalSection lock_; mutable Mutex lock_;
// These are mutable so that IsCurrent can set them. // These are mutable so that IsCurrent can set them.
mutable bool attached_ RTC_GUARDED_BY(lock_); mutable bool attached_ RTC_GUARDED_BY(lock_);
mutable rtc::PlatformThreadRef valid_thread_ RTC_GUARDED_BY(lock_); mutable rtc::PlatformThreadRef valid_thread_ RTC_GUARDED_BY(lock_);

View File

@ -29,11 +29,11 @@
#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_base.h"
#include "base/third_party/libevent/event.h" #include "base/third_party/libevent/event.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/platform_thread_types.h" #include "rtc_base/platform_thread_types.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
@ -130,7 +130,7 @@ class TaskQueueLibevent final : public TaskQueueBase {
event_base* event_base_; event_base* event_base_;
event wakeup_event_; event wakeup_event_;
rtc::PlatformThread thread_; rtc::PlatformThread thread_;
rtc::CriticalSection pending_lock_; Mutex pending_lock_;
absl::InlinedVector<std::unique_ptr<QueuedTask>, 4> pending_ absl::InlinedVector<std::unique_ptr<QueuedTask>, 4> pending_
RTC_GUARDED_BY(pending_lock_); RTC_GUARDED_BY(pending_lock_);
// Holds a list of events pending timers for cleanup when the loop exits. // Holds a list of events pending timers for cleanup when the loop exits.
@ -216,7 +216,7 @@ void TaskQueueLibevent::Delete() {
void TaskQueueLibevent::PostTask(std::unique_ptr<QueuedTask> task) { void TaskQueueLibevent::PostTask(std::unique_ptr<QueuedTask> task) {
{ {
rtc::CritScope lock(&pending_lock_); MutexLock lock(&pending_lock_);
bool had_pending_tasks = !pending_.empty(); bool had_pending_tasks = !pending_.empty();
pending_.push_back(std::move(task)); pending_.push_back(std::move(task));
@ -282,7 +282,7 @@ void TaskQueueLibevent::OnWakeup(int socket,
case kRunTasks: { case kRunTasks: {
absl::InlinedVector<std::unique_ptr<QueuedTask>, 4> tasks; absl::InlinedVector<std::unique_ptr<QueuedTask>, 4> tasks;
{ {
rtc::CritScope lock(&me->pending_lock_); MutexLock lock(&me->pending_lock_);
tasks.swap(me->pending_); tasks.swap(me->pending_);
} }
RTC_DCHECK(!tasks.empty()); RTC_DCHECK(!tasks.empty());

View File

@ -22,10 +22,10 @@
#include "api/task_queue/queued_task.h" #include "api/task_queue/queued_task.h"
#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_base.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
@ -97,7 +97,7 @@ class TaskQueueStdlib final : public TaskQueueBase {
// tasks (including delayed tasks). // tasks (including delayed tasks).
rtc::PlatformThread thread_; rtc::PlatformThread thread_;
rtc::CriticalSection pending_lock_; Mutex pending_lock_;
// Indicates if the worker thread needs to shutdown now. // Indicates if the worker thread needs to shutdown now.
bool thread_should_quit_ RTC_GUARDED_BY(pending_lock_){false}; bool thread_should_quit_ RTC_GUARDED_BY(pending_lock_){false};
@ -135,7 +135,7 @@ void TaskQueueStdlib::Delete() {
RTC_DCHECK(!IsCurrent()); RTC_DCHECK(!IsCurrent());
{ {
rtc::CritScope lock(&pending_lock_); MutexLock lock(&pending_lock_);
thread_should_quit_ = true; thread_should_quit_ = true;
} }
@ -148,7 +148,7 @@ void TaskQueueStdlib::Delete() {
void TaskQueueStdlib::PostTask(std::unique_ptr<QueuedTask> task) { void TaskQueueStdlib::PostTask(std::unique_ptr<QueuedTask> task) {
{ {
rtc::CritScope lock(&pending_lock_); MutexLock lock(&pending_lock_);
OrderId order = thread_posting_order_++; OrderId order = thread_posting_order_++;
pending_queue_.push(std::pair<OrderId, std::unique_ptr<QueuedTask>>( pending_queue_.push(std::pair<OrderId, std::unique_ptr<QueuedTask>>(
@ -166,7 +166,7 @@ void TaskQueueStdlib::PostDelayedTask(std::unique_ptr<QueuedTask> task,
delay.next_fire_at_ms_ = fire_at; delay.next_fire_at_ms_ = fire_at;
{ {
rtc::CritScope lock(&pending_lock_); MutexLock lock(&pending_lock_);
delay.order_ = ++thread_posting_order_; delay.order_ = ++thread_posting_order_;
delayed_queue_[delay] = std::move(task); delayed_queue_[delay] = std::move(task);
} }
@ -179,7 +179,7 @@ TaskQueueStdlib::NextTask TaskQueueStdlib::GetNextTask() {
auto tick = rtc::TimeMillis(); auto tick = rtc::TimeMillis();
rtc::CritScope lock(&pending_lock_); MutexLock lock(&pending_lock_);
if (thread_should_quit_) { if (thread_should_quit_) {
result.final_task_ = true; result.final_task_ = true;

View File

@ -33,12 +33,12 @@
#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_base.h"
#include "rtc_base/arraysize.h" #include "rtc_base/arraysize.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc { namespace webrtc {
namespace { namespace {
@ -205,7 +205,7 @@ class TaskQueueWin : public TaskQueueBase {
timer_tasks_; timer_tasks_;
UINT_PTR timer_id_ = 0; UINT_PTR timer_id_ = 0;
WorkerThread thread_; WorkerThread thread_;
rtc::CriticalSection pending_lock_; Mutex pending_lock_;
std::queue<std::unique_ptr<QueuedTask>> pending_ std::queue<std::unique_ptr<QueuedTask>> pending_
RTC_GUARDED_BY(pending_lock_); RTC_GUARDED_BY(pending_lock_);
HANDLE in_queue_; HANDLE in_queue_;
@ -235,7 +235,7 @@ void TaskQueueWin::Delete() {
} }
void TaskQueueWin::PostTask(std::unique_ptr<QueuedTask> task) { void TaskQueueWin::PostTask(std::unique_ptr<QueuedTask> task) {
rtc::CritScope lock(&pending_lock_); MutexLock lock(&pending_lock_);
pending_.push(std::move(task)); pending_.push(std::move(task));
::SetEvent(in_queue_); ::SetEvent(in_queue_);
} }
@ -262,7 +262,7 @@ void TaskQueueWin::RunPendingTasks() {
while (true) { while (true) {
std::unique_ptr<QueuedTask> task; std::unique_ptr<QueuedTask> task;
{ {
rtc::CritScope lock(&pending_lock_); MutexLock lock(&pending_lock_);
if (pending_.empty()) if (pending_.empty())
break; break;
task = std::move(pending_.front()); task = std::move(pending_.front());

View File

@ -75,7 +75,7 @@ std::unique_ptr<TestClient::Packet> TestClient::NextPacket(int timeout_ms) {
int64_t end = TimeAfter(timeout_ms); int64_t end = TimeAfter(timeout_ms);
while (TimeUntil(end) > 0) { while (TimeUntil(end) > 0) {
{ {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (packets_.size() != 0) { if (packets_.size() != 0) {
break; break;
} }
@ -85,7 +85,7 @@ std::unique_ptr<TestClient::Packet> TestClient::NextPacket(int timeout_ms) {
// Return the first packet placed in the queue. // Return the first packet placed in the queue.
std::unique_ptr<Packet> packet; std::unique_ptr<Packet> packet;
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
if (packets_.size() > 0) { if (packets_.size() > 0) {
packet = std::move(packets_.front()); packet = std::move(packets_.front());
packets_.erase(packets_.begin()); packets_.erase(packets_.begin());
@ -149,7 +149,7 @@ void TestClient::OnPacket(AsyncPacketSocket* socket,
size_t size, size_t size,
const SocketAddress& remote_addr, const SocketAddress& remote_addr,
const int64_t& packet_time_us) { const int64_t& packet_time_us) {
CritScope cs(&crit_); webrtc::MutexLock lock(&mutex_);
packets_.push_back( packets_.push_back(
std::make_unique<Packet>(remote_addr, buf, size, packet_time_us)); std::make_unique<Packet>(remote_addr, buf, size, packet_time_us));
} }

View File

@ -16,8 +16,8 @@
#include "rtc_base/async_udp_socket.h" #include "rtc_base/async_udp_socket.h"
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/fake_clock.h" #include "rtc_base/fake_clock.h"
#include "rtc_base/synchronization/mutex.h"
namespace rtc { namespace rtc {
@ -105,7 +105,7 @@ class TestClient : public sigslot::has_slots<> {
void AdvanceTime(int ms); void AdvanceTime(int ms);
ThreadProcessingFakeClock* fake_clock_ = nullptr; ThreadProcessingFakeClock* fake_clock_ = nullptr;
CriticalSection crit_; webrtc::Mutex mutex_;
std::unique_ptr<AsyncPacketSocket> socket_; std::unique_ptr<AsyncPacketSocket> socket_;
std::vector<std::unique_ptr<Packet>> packets_; std::vector<std::unique_ptr<Packet>> packets_;
int ready_to_send_count_ = 0; int ready_to_send_count_ = 0;

View File

@ -19,6 +19,7 @@
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/fake_clock.h" #include "rtc_base/fake_clock.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/physical_socket_server.h" #include "rtc_base/physical_socket_server.h"

View File

@ -17,6 +17,7 @@
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/fake_clock.h" #include "rtc_base/fake_clock.h"
#include "rtc_base/message_handler.h" #include "rtc_base/message_handler.h"

View File

@ -733,7 +733,7 @@ bool Win32SocketServer::Wait(int cms, bool process_io) {
MSG msg; MSG msg;
b = GetMessage(&msg, nullptr, s_wm_wakeup_id, s_wm_wakeup_id); b = GetMessage(&msg, nullptr, s_wm_wakeup_id, s_wm_wakeup_id);
{ {
CritScope scope(&cs_); webrtc::MutexLock lock(&mutex_);
posted_ = false; posted_ = false;
} }
} else { } else {
@ -747,7 +747,7 @@ void Win32SocketServer::WakeUp() {
if (wnd_.handle()) { if (wnd_.handle()) {
// Set the "message pending" flag, if not already set. // Set the "message pending" flag, if not already set.
{ {
CritScope scope(&cs_); webrtc::MutexLock lock(&mutex_);
if (posted_) if (posted_)
return; return;
posted_ = true; posted_ = true;
@ -760,7 +760,7 @@ void Win32SocketServer::WakeUp() {
void Win32SocketServer::Pump() { void Win32SocketServer::Pump() {
// Clear the "message pending" flag. // Clear the "message pending" flag.
{ {
CritScope scope(&cs_); webrtc::MutexLock lock(&mutex_);
posted_ = false; posted_ = false;
} }

View File

@ -13,10 +13,10 @@
#if defined(WEBRTC_WIN) #if defined(WEBRTC_WIN)
#include "rtc_base/async_socket.h" #include "rtc_base/async_socket.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/socket.h" #include "rtc_base/socket.h"
#include "rtc_base/socket_factory.h" #include "rtc_base/socket_factory.h"
#include "rtc_base/socket_server.h" #include "rtc_base/socket_server.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
#include "rtc_base/win32_window.h" #include "rtc_base/win32_window.h"
@ -123,7 +123,7 @@ class Win32SocketServer : public SocketServer {
static const wchar_t kWindowName[]; static const wchar_t kWindowName[];
Thread* message_queue_; Thread* message_queue_;
MessageWindow wnd_; MessageWindow wnd_;
CriticalSection cs_; webrtc::Mutex mutex_;
bool posted_; bool posted_;
HWND hdlg_; HWND hdlg_;
}; };

View File

@ -10,6 +10,7 @@
#include "sdk/android/native_api/jni/java_types.h" #include "sdk/android/native_api/jni/java_types.h"
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
@ -51,14 +52,15 @@ Iterable::Iterator::Iterator(JNIEnv* jni, const JavaRef<jobject>& iterable)
Iterable::Iterator::Iterator(Iterator&& other) Iterable::Iterator::Iterator(Iterator&& other)
: jni_(std::move(other.jni_)), : jni_(std::move(other.jni_)),
iterator_(std::move(other.iterator_)), iterator_(std::move(other.iterator_)),
value_(std::move(other.value_)), value_(std::move(other.value_)) {
thread_checker_(std::move(other.thread_checker_)) {} RTC_DCHECK_RUN_ON(&thread_checker_);
}
Iterable::Iterator::~Iterator() = default; Iterable::Iterator::~Iterator() = default;
// Advances the iterator one step. // Advances the iterator one step.
Iterable::Iterator& Iterable::Iterator::operator++() { Iterable::Iterator& Iterable::Iterator::operator++() {
RTC_CHECK(thread_checker_.IsCurrent()); RTC_DCHECK_RUN_ON(&thread_checker_);
if (AtEnd()) { if (AtEnd()) {
// Can't move past the end. // Can't move past the end.
return *this; return *this;
@ -93,7 +95,7 @@ ScopedJavaLocalRef<jobject>& Iterable::Iterator::operator*() {
} }
bool Iterable::Iterator::AtEnd() const { bool Iterable::Iterator::AtEnd() const {
RTC_CHECK(thread_checker_.IsCurrent()); RTC_DCHECK_RUN_ON(&thread_checker_);
return jni_ == nullptr || IsNull(jni_, iterator_); return jni_ == nullptr || IsNull(jni_, iterator_);
} }

View File

@ -18,7 +18,9 @@
#define SDK_ANDROID_NATIVE_API_JNI_JAVA_TYPES_H_ #define SDK_ANDROID_NATIVE_API_JNI_JAVA_TYPES_H_
#include <jni.h> #include <jni.h>
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -12,11 +12,13 @@
#define SDK_ANDROID_SRC_JNI_VIDEO_DECODER_WRAPPER_H_ #define SDK_ANDROID_SRC_JNI_VIDEO_DECODER_WRAPPER_H_
#include <jni.h> #include <jni.h>
#include <atomic> #include <atomic>
#include <deque> #include <deque>
#include "api/video_codecs/video_decoder.h" #include "api/video_codecs/video_decoder.h"
#include "common_video/h264/h264_bitstream_parser.h" #include "common_video/h264/h264_bitstream_parser.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/race_checker.h" #include "rtc_base/race_checker.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
#include "sdk/android/src/jni/jni_helpers.h" #include "sdk/android/src/jni/jni_helpers.h"

View File

@ -19,6 +19,7 @@
#include "api/video/video_stream_decoder.h" #include "api/video/video_stream_decoder.h"
#include "modules/video_coding/frame_buffer2.h" #include "modules/video_coding/frame_buffer2.h"
#include "modules/video_coding/timing.h" #include "modules/video_coding/timing.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"