Migrate to webrtc::GlobalMutex.

Bug: webrtc:11567
Change-Id: I853434745c427e54474739e9c573e0f6f4fcedef
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/179283
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31732}
This commit is contained in:
Markus Handell
2020-07-15 11:53:44 +02:00
committed by Commit Bot
parent a13e7a1d46
commit 0dd35d3732
6 changed files with 18 additions and 13 deletions

View File

@ -58,7 +58,7 @@ static constexpr size_t kSctpMtu = 1200;
// Set the initial value of the static SCTP Data Engines reference count.
ABSL_CONST_INIT int g_usrsctp_usage_count = 0;
ABSL_CONST_INIT rtc::GlobalLock g_usrsctp_lock_;
ABSL_CONST_INIT webrtc::GlobalMutex g_usrsctp_lock_(absl::kConstInit);
// DataMessageType is used for the SCTP "Payload Protocol Identifier", as
// defined in http://tools.ietf.org/html/rfc4960#section-14.4
@ -330,7 +330,7 @@ class SctpTransport::UsrSctpWrapper {
}
static void IncrementUsrSctpUsageCount() {
rtc::GlobalLockScope lock(&g_usrsctp_lock_);
webrtc::GlobalMutexLock lock(&g_usrsctp_lock_);
if (!g_usrsctp_usage_count) {
InitializeUsrSctp();
}
@ -338,7 +338,7 @@ class SctpTransport::UsrSctpWrapper {
}
static void DecrementUsrSctpUsageCount() {
rtc::GlobalLockScope lock(&g_usrsctp_lock_);
webrtc::GlobalMutexLock lock(&g_usrsctp_lock_);
--g_usrsctp_usage_count;
if (!g_usrsctp_usage_count) {
UninitializeUsrSctp();

View File

@ -132,7 +132,8 @@ class RTC_SCOPED_LOCKABLE GlobalMutexLock final {
GlobalMutexLock(const GlobalMutexLock&) = delete;
GlobalMutexLock& operator=(const GlobalMutexLock&) = delete;
explicit GlobalMutexLock(GlobalMutex* mutex) RTC_EXCLUSIVE_LOCK_FUNCTION();
explicit GlobalMutexLock(GlobalMutex* mutex)
RTC_EXCLUSIVE_LOCK_FUNCTION(mutex_);
~GlobalMutexLock() RTC_UNLOCK_FUNCTION();
private:

View File

@ -72,7 +72,10 @@ if (is_mac || is_ios) {
rtc_source_set("thread_registry") {
sources = [ "thread_registry.h" ]
deps = [ "..:rtc_base_approved" ]
deps = [
"..:rtc_base_approved",
"../synchronization:mutex",
]
if (is_android && !build_with_chromium) {
sources += [ "thread_registry.cc" ]
deps += [ "../../sdk/android:native_api_stacktrace" ]

View File

@ -14,9 +14,9 @@
#include <utility>
#include "absl/base/attributes.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h"
#include "rtc_base/platform_thread_types.h"
#include "rtc_base/synchronization/mutex.h"
#include "sdk/android/native_api/stacktrace/stacktrace.h"
namespace webrtc {
@ -30,7 +30,7 @@ struct ThreadData {
// The map of registered threads, and the lock that protects it. We create the
// map on first use, and never destroy it.
ABSL_CONST_INIT rtc::GlobalLock g_thread_registry_lock;
ABSL_CONST_INIT GlobalMutex g_thread_registry_lock(absl::kConstInit);
ABSL_CONST_INIT std::map<const ScopedRegisterThreadForDebugging*, ThreadData>*
g_registered_threads = nullptr;
@ -38,7 +38,7 @@ ABSL_CONST_INIT std::map<const ScopedRegisterThreadForDebugging*, ThreadData>*
ScopedRegisterThreadForDebugging::ScopedRegisterThreadForDebugging(
rtc::Location location) {
rtc::GlobalLockScope gls(&g_thread_registry_lock);
GlobalMutexLock gls(&g_thread_registry_lock);
if (g_registered_threads == nullptr) {
g_registered_threads =
new std::map<const ScopedRegisterThreadForDebugging*, ThreadData>();
@ -49,14 +49,14 @@ ScopedRegisterThreadForDebugging::ScopedRegisterThreadForDebugging(
}
ScopedRegisterThreadForDebugging::~ScopedRegisterThreadForDebugging() {
rtc::GlobalLockScope gls(&g_thread_registry_lock);
GlobalMutexLock gls(&g_thread_registry_lock);
RTC_DCHECK(g_registered_threads != nullptr);
const int num_erased = g_registered_threads->erase(this);
RTC_DCHECK_EQ(num_erased, 1);
}
void PrintStackTracesOfRegisteredThreads() {
rtc::GlobalLockScope gls(&g_thread_registry_lock);
GlobalMutexLock gls(&g_thread_registry_lock);
if (g_registered_threads == nullptr) {
return;
}

View File

@ -935,6 +935,7 @@ if (current_os == "linux" || is_android) {
"../../rtc_base:criticalsection",
"../../rtc_base:logging",
"../../rtc_base:stringutils",
"../../rtc_base/synchronization:mutex",
]
absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ]
}

View File

@ -27,9 +27,9 @@
#endif
#include "absl/base/attributes.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@ -92,7 +92,7 @@ struct SignalHandlerOutputState {
};
// Global lock to ensure only one thread gets interrupted at a time.
ABSL_CONST_INIT rtc::GlobalLock g_signal_handler_lock;
ABSL_CONST_INIT GlobalMutex g_signal_handler_lock(absl::kConstInit);
// Argument passed to the ThreadSignalHandler() from the sampling thread to the
// sampled (stopped) thread. This value is set just before sending signal to the
// thread and reset when handler is done.
@ -153,7 +153,7 @@ const char* CaptureRawStacktrace(int pid,
act.sa_flags = SA_RESTART | SA_SIGINFO;
sigemptyset(&act.sa_mask);
rtc::GlobalLockScope ls(&g_signal_handler_lock);
GlobalMutexLock ls(&g_signal_handler_lock);
g_signal_handler_output_state = params;
if (sigaction(kSignal, &act, &old_act) != 0)