Replace some RecursiveCriticalSection with Mutex, in PhysicalSocketServer.
The one remaining RecursiveCriticalSection likely needs a bit more
care.
Bug: webrtc:11567
Change-Id: Ie81085969197bed03ac8e2d269b58653b86095e0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/206468
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Markus Handell <handellm@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33206}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 983488f..65572aa 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -809,6 +809,7 @@
"../api:function_view",
"../api:scoped_refptr",
"../api/task_queue",
+ "synchronization:mutex",
"synchronization:sequence_checker",
"system:no_unique_address",
"system:rtc_export",
diff --git a/rtc_base/physical_socket_server.cc b/rtc_base/physical_socket_server.cc
index adf3fab..ee611a1 100644
--- a/rtc_base/physical_socket_server.cc
+++ b/rtc_base/physical_socket_server.cc
@@ -48,6 +48,7 @@
#include "rtc_base/logging.h"
#include "rtc_base/network_monitor.h"
#include "rtc_base/null_socket_server.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h"
#if defined(WEBRTC_LINUX)
@@ -273,12 +274,12 @@
}
int PhysicalSocket::GetError() const {
- CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
return error_;
}
void PhysicalSocket::SetError(int error) {
- CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
error_ = error;
}
@@ -934,7 +935,7 @@
}
virtual void Signal() {
- CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
if (!fSignaled_) {
const uint8_t b[1] = {0};
const ssize_t res = write(afd_[1], b, sizeof(b));
@@ -949,7 +950,7 @@
// It is not possible to perfectly emulate an auto-resetting event with
// pipes. This simulates it by resetting before the event is handled.
- CritScope cs(&crit_);
+ webrtc::MutexLock lock(&mutex_);
if (fSignaled_) {
uint8_t b[4]; // Allow for reading more than 1 byte, but expect 1.
const ssize_t res = read(afd_[0], b, sizeof(b));
@@ -965,10 +966,10 @@
bool IsDescriptorClosed() override { return false; }
private:
- PhysicalSocketServer* ss_;
- int afd_[2];
- bool fSignaled_;
- RecursiveCriticalSection crit_;
+ PhysicalSocketServer* const ss_;
+ int afd_[2]; // Assigned in constructor only.
+ bool fSignaled_ RTC_GUARDED_BY(mutex_);
+ webrtc::Mutex mutex_;
};
#endif // WEBRTC_POSIX
diff --git a/rtc_base/physical_socket_server.h b/rtc_base/physical_socket_server.h
index 5a09aac..f83bf52 100644
--- a/rtc_base/physical_socket_server.h
+++ b/rtc_base/physical_socket_server.h
@@ -25,6 +25,7 @@
#include "rtc_base/async_resolver_interface.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/socket_server.h"
+#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/thread_annotations.h"
@@ -203,8 +204,8 @@
SOCKET s_;
bool udp_;
int family_ = 0;
- RecursiveCriticalSection crit_;
- int error_ RTC_GUARDED_BY(crit_);
+ mutable webrtc::Mutex mutex_;
+ int error_ RTC_GUARDED_BY(mutex_);
ConnState state_;
AsyncResolver* resolver_;