Rename CriticalSection to RecursiveCriticalSection.

This name change communicates that the recursive critical section
should not be used for new code.
The relevant files are renamed rtc_base/critical_section* ->
rtc_base/deprecated/recursive_critical_section*

Bug: webrtc:11567
Change-Id: I73483a1c5e59c389407a981efbfc2cfe76ccdb43
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/179483
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31754}
This commit is contained in:
Markus Handell 2020-07-16 16:16:09 +02:00 committed by Commit Bot
parent 1a09faed62
commit 3cb525b378
18 changed files with 68 additions and 65 deletions

View file

@ -14,7 +14,7 @@
#include "call/rtp_demuxer.h"
#include "call/rtp_stream_receiver_controller_interface.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
namespace webrtc {
@ -63,7 +63,7 @@ class RtpStreamReceiverController
// to be called on the same thread, and OnRtpPacket to be called
// by a single, but possibly distinct, thread. But applications not
// using Call may have use threads differently.
rtc::CriticalSection lock_;
rtc::RecursiveCriticalSection lock_;
RtpDemuxer demuxer_ RTC_GUARDED_BY(&lock_);
};

View file

@ -25,7 +25,7 @@
#include "modules/desktop_capture/win/dxgi_adapter_duplicator.h"
#include "modules/desktop_capture/win/dxgi_context.h"
#include "modules/desktop_capture/win/dxgi_frame.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
namespace webrtc {
@ -219,7 +219,7 @@ class DxgiDuplicatorController {
std::atomic_int refcount_;
// This lock must be locked whenever accessing any of the following objects.
rtc::CriticalSection lock_;
rtc::RecursiveCriticalSection lock_;
// A self-incremented integer to compare with the one in Context. It ensures
// a Context instance is always initialized after DxgiDuplicatorController.

View file

@ -32,7 +32,7 @@
#include "modules/rtp_rtcp/include/rtp_packet_sender.h"
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
#include "modules/utility/include/process_thread.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
@ -157,7 +157,7 @@ class PacedSender : public Module,
PacedSender* const delegate_;
} module_proxy_{this};
rtc::CriticalSection critsect_;
rtc::RecursiveCriticalSection critsect_;
const PacingController::ProcessMode process_mode_;
PacingController pacing_controller_ RTC_GUARDED_BY(critsect_);

View file

@ -20,7 +20,7 @@
#include "api/task_queue/queued_task.h"
#include "modules/include/module.h"
#include "modules/utility/include/process_thread.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/location.h"
#include "rtc_base/platform_thread.h"
@ -92,7 +92,8 @@ class ProcessThreadImpl : public ProcessThread {
// issues, but I haven't figured out what they are, if there are alignment
// requirements for mutexes on Mac or if there's something else to it.
// So be careful with changing the layout.
rtc::CriticalSection lock_; // Used to guard modules_, tasks_ and stop_.
rtc::RecursiveCriticalSection
lock_; // Used to guard modules_, tasks_ and stop_.
rtc::ThreadChecker thread_checker_;
rtc::Event wake_up_;

View file

@ -316,7 +316,7 @@ class JsepTransport : public sigslot::has_slots<> {
const rtc::Thread* const network_thread_;
// Critical scope for fields accessed off-thread
// TODO(https://bugs.webrtc.org/10300): Stop doing this.
rtc::CriticalSection accessor_lock_;
rtc::RecursiveCriticalSection accessor_lock_;
const std::string mid_;
// needs-ice-restart bit as described in JSEP.
bool needs_ice_restart_ RTC_GUARDED_BY(accessor_lock_) = false;

View file

@ -170,8 +170,8 @@ rtc_source_set("refcount") {
rtc_library("criticalsection") {
sources = [
"critical_section.cc",
"critical_section.h",
"deprecated/recursive_critical_section.cc",
"deprecated/recursive_critical_section.h",
]
deps = [
":atomicops",
@ -179,7 +179,6 @@ rtc_library("criticalsection") {
":macromagic",
":platform_thread_types",
"synchronization:yield",
"system:rtc_export",
"system:unused",
]
}
@ -1181,7 +1180,7 @@ if (rtc_include_tests) {
"byte_order_unittest.cc",
"checks_unittest.cc",
"copy_on_write_buffer_unittest.cc",
"critical_section_unittest.cc",
"deprecated/recursive_critical_section_unittest.cc",
"event_tracer_unittest.cc",
"event_unittest.cc",
"logging_unittest.cc",

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include <time.h>
@ -18,8 +18,6 @@
#include "rtc_base/synchronization/yield.h"
#include "rtc_base/system/unused.h"
// TODO(tommi): Split this file up to per-platform implementation files.
#if RTC_DCHECK_IS_ON
#define RTC_CS_DEBUG_CODE(x) x
#else // !RTC_DCHECK_IS_ON
@ -28,7 +26,7 @@
namespace rtc {
CriticalSection::CriticalSection() {
RecursiveCriticalSection::RecursiveCriticalSection() {
#if defined(WEBRTC_WIN)
InitializeCriticalSection(&crit_);
#elif defined(WEBRTC_POSIX)
@ -57,7 +55,7 @@ CriticalSection::CriticalSection() {
#endif
}
CriticalSection::~CriticalSection() {
RecursiveCriticalSection::~RecursiveCriticalSection() {
#if defined(WEBRTC_WIN)
DeleteCriticalSection(&crit_);
#elif defined(WEBRTC_POSIX)
@ -71,7 +69,7 @@ CriticalSection::~CriticalSection() {
#endif
}
void CriticalSection::Enter() const RTC_EXCLUSIVE_LOCK_FUNCTION() {
void RecursiveCriticalSection::Enter() const RTC_EXCLUSIVE_LOCK_FUNCTION() {
#if defined(WEBRTC_WIN)
EnterCriticalSection(&crit_);
#elif defined(WEBRTC_POSIX)
@ -130,7 +128,8 @@ void CriticalSection::Enter() const RTC_EXCLUSIVE_LOCK_FUNCTION() {
#endif
}
bool CriticalSection::TryEnter() const RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
bool RecursiveCriticalSection::TryEnter() const
RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
#if defined(WEBRTC_WIN)
return TryEnterCriticalSection(&crit_) != FALSE;
#elif defined(WEBRTC_POSIX)
@ -163,7 +162,7 @@ bool CriticalSection::TryEnter() const RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
#endif
}
void CriticalSection::Leave() const RTC_UNLOCK_FUNCTION() {
void RecursiveCriticalSection::Leave() const RTC_UNLOCK_FUNCTION() {
RTC_DCHECK(CurrentThreadIsOwner());
#if defined(WEBRTC_WIN)
LeaveCriticalSection(&crit_);
@ -191,7 +190,7 @@ void CriticalSection::Leave() const RTC_UNLOCK_FUNCTION() {
#endif
}
bool CriticalSection::CurrentThreadIsOwner() const {
bool RecursiveCriticalSection::CurrentThreadIsOwner() const {
#if defined(WEBRTC_WIN)
// OwningThread has type HANDLE but actually contains the Thread ID:
// http://stackoverflow.com/questions/12675301/why-is-the-owningthread-member-of-critical-section-of-type-handle-when-it-is-de
@ -210,7 +209,7 @@ bool CriticalSection::CurrentThreadIsOwner() const {
#endif
}
CritScope::CritScope(const CriticalSection* cs) : cs_(cs) {
CritScope::CritScope(const RecursiveCriticalSection* cs) : cs_(cs) {
cs_->Enter();
}
CritScope::~CritScope() {

View file

@ -8,13 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_CRITICAL_SECTION_H_
#define RTC_BASE_CRITICAL_SECTION_H_
#ifndef RTC_BASE_DEPRECATED_RECURSIVE_CRITICAL_SECTION_H_
#define RTC_BASE_DEPRECATED_RECURSIVE_CRITICAL_SECTION_H_
#include "rtc_base/checks.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/platform_thread_types.h"
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/thread_annotations.h"
#if defined(WEBRTC_WIN)
@ -43,13 +41,18 @@
namespace rtc {
// NOTE: This class is deprecated. Please use webrtc::Mutex instead!
// Search using https://www.google.com/?q=recursive+lock+considered+harmful
// to find the reasons.
//
// Locking methods (Enter, TryEnter, Leave)are const to permit protecting
// members inside a const context without requiring mutable CriticalSections
// everywhere. CriticalSection is reentrant lock.
class RTC_LOCKABLE RTC_EXPORT CriticalSection {
// members inside a const context without requiring mutable
// RecursiveCriticalSections everywhere. RecursiveCriticalSection is
// reentrant lock.
class RTC_LOCKABLE RecursiveCriticalSection {
public:
CriticalSection();
~CriticalSection();
RecursiveCriticalSection();
~RecursiveCriticalSection();
void Enter() const RTC_EXCLUSIVE_LOCK_FUNCTION();
bool TryEnter() const RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true);
@ -87,14 +90,15 @@ class RTC_LOCKABLE RTC_EXPORT CriticalSection {
// CritScope, for serializing execution through a scope.
class RTC_SCOPED_LOCKABLE CritScope {
public:
explicit CritScope(const CriticalSection* cs) RTC_EXCLUSIVE_LOCK_FUNCTION(cs);
explicit CritScope(const RecursiveCriticalSection* cs)
RTC_EXCLUSIVE_LOCK_FUNCTION(cs);
~CritScope() RTC_UNLOCK_FUNCTION();
private:
const CriticalSection* const cs_;
const RecursiveCriticalSection* const cs_;
RTC_DISALLOW_COPY_AND_ASSIGN(CritScope);
};
} // namespace rtc
#endif // RTC_BASE_CRITICAL_SECTION_H_
#endif // RTC_BASE_DEPRECATED_RECURSIVE_CRITICAL_SECTION_H_

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include <stddef.h>
#include <stdint.h>
@ -124,7 +124,7 @@ class RTC_LOCKABLE CriticalSectionLock {
void Unlock() RTC_UNLOCK_FUNCTION() { cs_.Leave(); }
private:
CriticalSection cs_;
RecursiveCriticalSection cs_;
};
template <class Lock>
@ -183,7 +183,7 @@ class AtomicOpRunner : public RunnerBase {
}
private:
CriticalSection all_values_crit_;
RecursiveCriticalSection all_values_crit_;
Verifier verifier_;
};
@ -282,7 +282,7 @@ TEST(AtomicOpsTest, CompareAndSwap) {
EXPECT_EQ(1, runner.shared_value());
}
TEST(CriticalSectionTest, Basic) {
TEST(RecursiveCriticalSectionTest, Basic) {
// Create and start lots of threads.
LockRunner<CriticalSectionLock> runner;
std::vector<std::unique_ptr<Thread>> threads;
@ -320,7 +320,7 @@ class PerfTestData {
private:
uint8_t cache_line_barrier_1_[64];
CriticalSection lock_;
RecursiveCriticalSection lock_;
uint8_t cache_line_barrier_2_[64];
int64_t my_counter_ = 0;
const int expected_count_;
@ -372,7 +372,7 @@ class PerfTestThread {
// user 1m20.575s
// sys 3m48.872s
// Unit test output:
// [ OK ] CriticalSectionTest.Performance (294375 ms)
// [ OK ] RecursiveCriticalSectionTest.Performance (294375 ms)
//
// Native mutex implementation using first fit policy (current macOS default):
// Approximate CPU usage:
@ -380,7 +380,7 @@ class PerfTestThread {
// user 0m12.738s
// sys 0m31.207s
// Unit test output:
// [ OK ] CriticalSectionTest.Performance (11444 ms)
// [ OK ] RecursiveCriticalSectionTest.Performance (11444 ms)
//
// Special partially spin lock based implementation:
// Approximate CPU usage:
@ -388,10 +388,10 @@ class PerfTestThread {
// user 0m3.014s
// sys 0m4.495s
// Unit test output:
// [ OK ] CriticalSectionTest.Performance (1885 ms)
// [ OK ] RecursiveCriticalSectionTest.Performance (1885 ms)
//
// The test is disabled by default to avoid unecessarily loading the bots.
TEST(CriticalSectionTest, DISABLED_Performance) {
TEST(RecursiveCriticalSectionTest, DISABLED_Performance) {
PerfTestThread threads[8];
Event event;

View file

@ -15,7 +15,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/deprecation.h"
#include "rtc_base/message_handler.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
@ -149,7 +149,7 @@ class DEPRECATED_SignalThread : public sigslot::has_slots<>,
Thread* main_;
Worker worker_;
CriticalSection cs_;
RecursiveCriticalSection cs_;
State state_ RTC_GUARDED_BY(cs_);
int refcount_ RTC_GUARDED_BY(cs_);
bool destroy_called_ RTC_GUARDED_BY(cs_) = false;

View file

@ -955,7 +955,7 @@ class EventDispatcher : public Dispatcher {
PhysicalSocketServer* ss_;
int afd_[2];
bool fSignaled_;
CriticalSection crit_;
RecursiveCriticalSection crit_;
};
#endif // WEBRTC_POSIX

View file

@ -21,7 +21,7 @@
#include <set>
#include <vector>
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/net_helpers.h"
#include "rtc_base/socket_server.h"
#include "rtc_base/system/rtc_export.h"
@ -111,7 +111,7 @@ class RTC_EXPORT PhysicalSocketServer : public SocketServer {
DispatcherSet pending_remove_dispatchers_ RTC_GUARDED_BY(crit_);
bool processing_dispatchers_ RTC_GUARDED_BY(crit_) = false;
Signaler* signal_wakeup_; // Assigned in constructor only
CriticalSection crit_;
RecursiveCriticalSection crit_;
#if defined(WEBRTC_WIN)
const WSAEVENT socket_ev_;
#endif
@ -191,7 +191,7 @@ class PhysicalSocket : public AsyncSocket, public sigslot::has_slots<> {
SOCKET s_;
bool udp_;
int family_ = 0;
CriticalSection crit_;
RecursiveCriticalSection crit_;
int error_ RTC_GUARDED_BY(crit_);
ConnState state_;
AsyncResolver* resolver_;

View file

@ -31,7 +31,7 @@
#include "absl/algorithm/container.h"
#include "rtc_base/atomic_ops.h"
#include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/logging.h"
#include "rtc_base/null_socket_server.h"
#include "rtc_base/synchronization/sequence_checker.h"
@ -88,8 +88,8 @@ class MessageHandlerWithTask final : public MessageHandler {
class RTC_SCOPED_LOCKABLE MarkProcessingCritScope {
public:
MarkProcessingCritScope(const CriticalSection* cs, size_t* processing)
RTC_EXCLUSIVE_LOCK_FUNCTION(cs)
MarkProcessingCritScope(const RecursiveCriticalSection* cs,
size_t* processing) RTC_EXCLUSIVE_LOCK_FUNCTION(cs)
: cs_(cs), processing_(processing) {
cs_->Enter();
*processing_ += 1;
@ -101,7 +101,7 @@ class RTC_SCOPED_LOCKABLE MarkProcessingCritScope {
}
private:
const CriticalSection* const cs_;
const RecursiveCriticalSection* const cs_;
size_t* processing_;
RTC_DISALLOW_COPY_AND_ASSIGN(MarkProcessingCritScope);

View file

@ -29,7 +29,7 @@
#include "api/task_queue/queued_task.h"
#include "api/task_queue/task_queue_base.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/location.h"
#include "rtc_base/message_handler.h"
#include "rtc_base/platform_thread_types.h"
@ -140,7 +140,7 @@ class RTC_EXPORT ThreadManager {
// Methods that don't modify the list of message queues may be called in a
// re-entrant fashion. "processing_" keeps track of the depth of re-entrant
// calls.
CriticalSection crit_;
RecursiveCriticalSection crit_;
size_t processing_ RTC_GUARDED_BY(crit_) = 0;
#if RTC_DCHECK_IS_ON
// Represents all thread seand actions by storing all send targets per thread.
@ -531,7 +531,7 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
friend class ScopedDisallowBlockingCalls;
CriticalSection* CritForTest() { return &crit_; }
RecursiveCriticalSection* CritForTest() { return &crit_; }
private:
class QueuedTaskHandler final : public MessageHandler {
@ -582,7 +582,7 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
std::vector<Thread*> allowed_threads_ RTC_GUARDED_BY(this);
bool invoke_policy_enabled_ RTC_GUARDED_BY(this) = false;
#endif
CriticalSection crit_;
RecursiveCriticalSection crit_;
bool fInitialized_;
bool fDestroyed_;

View file

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

View file

@ -17,7 +17,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/message_handler.h"
@ -295,7 +295,7 @@ class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> {
std::map<rtc::IPAddress, rtc::IPAddress> alternative_address_mapping_;
std::unique_ptr<Function> delay_dist_;
CriticalSection delay_crit_;
RecursiveCriticalSection delay_crit_;
double drop_prob_;
bool sending_blocked_ = false;
@ -380,7 +380,7 @@ class VirtualSocket : public AsyncSocket,
bool ready_to_send_ = true;
// Critical section to protect the recv_buffer and queue_
CriticalSection crit_;
RecursiveCriticalSection crit_;
// Network model that enforces bandwidth and capacity constraints
NetworkQueue network_;

View file

@ -16,7 +16,7 @@
#include "rtc_base/atomic_ops.h"
#include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/deprecated/recursive_critical_section.h"
#import "RTCAudioSessionConfiguration.h"
#import "base/RTCLogging.h"
@ -35,7 +35,7 @@ NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume";
// TODO(tkchin): Consider more granular locking. We're not expecting a lot of
// lock contention so coarse locks should be fine for now.
@implementation RTC_OBJC_TYPE (RTCAudioSession) {
rtc::CriticalSection _crit;
rtc::RecursiveCriticalSection _crit;
AVAudioSession *_session;
volatile int _activationCount;
volatile int _lockRecursionCount;

View file

@ -168,7 +168,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint {
uint16_t NextPort() RTC_EXCLUSIVE_LOCKS_REQUIRED(receiver_lock_);
void UpdateReceiveStats(const EmulatedIpPacket& packet);
rtc::CriticalSection receiver_lock_;
rtc::RecursiveCriticalSection receiver_lock_;
rtc::ThreadChecker enabled_state_checker_;
uint64_t id_;