Remove ALL usage of CriticalSectionWrapper.

Finally we are able to remove this class entirely, along with the last
vestiges of it's use. I've also removed some legacy files that were only
used for windows XP support.

BUG=webrtc:7035

Review-Url: https://codereview.webrtc.org/2790533002
Cr-Original-Commit-Position: refs/heads/master@{#17480}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: ff046c74c50c98bcd79274c31c10a65327c31ef1
diff --git a/modules/audio_conference_mixer/source/memory_pool_posix.h b/modules/audio_conference_mixer/source/memory_pool_posix.h
index 12aae3f..8e726f9 100644
--- a/modules/audio_conference_mixer/source/memory_pool_posix.h
+++ b/modules/audio_conference_mixer/source/memory_pool_posix.h
@@ -14,7 +14,7 @@
 #include <assert.h>
 #include <list>
 
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -36,7 +36,7 @@
     // Non-atomic function.
     int32_t CreateMemory(uint32_t amountToCreate);
 
-    CriticalSectionWrapper* _crit;
+    rtc::CriticalSection _crit;
 
     bool _terminate;
 
@@ -49,8 +49,7 @@
 
 template<class MemoryType>
 MemoryPoolImpl<MemoryType>::MemoryPoolImpl(int32_t initialPoolSize)
-    : _crit(CriticalSectionWrapper::CreateCriticalSection()),
-      _terminate(false),
+    : _terminate(false),
       _initialPoolSize(initialPoolSize),
       _createdMemory(0),
       _outstandingMemory(0)
@@ -63,13 +62,12 @@
     // Trigger assert if there is outstanding memory.
     assert(_createdMemory == 0);
     assert(_outstandingMemory == 0);
-    delete _crit;
 }
 
 template<class MemoryType>
 int32_t MemoryPoolImpl<MemoryType>::PopMemory(MemoryType*& memory)
 {
-    CriticalSectionScoped cs(_crit);
+    rtc::CritScope cs(&_crit);
     if(_terminate)
     {
         memory = NULL;
@@ -97,7 +95,7 @@
     {
         return -1;
     }
-    CriticalSectionScoped cs(_crit);
+    rtc::CritScope cs(&_crit);
     _outstandingMemory--;
     if(_memoryPool.size() > (_initialPoolSize << 1))
     {
@@ -115,14 +113,14 @@
 template<class MemoryType>
 bool MemoryPoolImpl<MemoryType>::Initialize()
 {
-    CriticalSectionScoped cs(_crit);
+    rtc::CritScope cs(&_crit);
     return CreateMemory(_initialPoolSize) == 0;
 }
 
 template<class MemoryType>
 int32_t MemoryPoolImpl<MemoryType>::Terminate()
 {
-    CriticalSectionScoped cs(_crit);
+    rtc::CritScope cs(&_crit);
     assert(_createdMemory == _outstandingMemory + _memoryPool.size());
 
     _terminate = true;
diff --git a/modules/audio_conference_mixer/source/time_scheduler.h b/modules/audio_conference_mixer/source/time_scheduler.h
index b155429..5240342 100644
--- a/modules/audio_conference_mixer/source/time_scheduler.h
+++ b/modules/audio_conference_mixer/source/time_scheduler.h
@@ -17,7 +17,6 @@
 #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_TIME_SCHEDULER_H_
 
 namespace webrtc {
-class CriticalSectionWrapper;
 
 class TimeScheduler {
 public:
diff --git a/modules/audio_device/mac/audio_device_mac.cc b/modules/audio_device/mac/audio_device_mac.cc
index 77897a2..0ea052f 100644
--- a/modules/audio_device/mac/audio_device_mac.cc
+++ b/modules/audio_device/mac/audio_device_mac.cc
@@ -93,7 +93,6 @@
 
 AudioDeviceMac::AudioDeviceMac(const int32_t id)
     : _ptrAudioBuffer(NULL),
-      _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
       _stopEventRec(*EventWrapper::Create()),
       _stopEvent(*EventWrapper::Create()),
       _id(id),
@@ -197,7 +196,6 @@
 
   delete &_stopEvent;
   delete &_stopEventRec;
-  delete &_critSect;
 }
 
 // ============================================================================
@@ -205,7 +203,7 @@
 // ============================================================================
 
 void AudioDeviceMac::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   _ptrAudioBuffer = audioBuffer;
 
@@ -223,7 +221,7 @@
 }
 
 AudioDeviceGeneric::InitStatus AudioDeviceMac::Init() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_initialized) {
     return InitStatus::OK;
@@ -423,7 +421,7 @@
 }
 
 int32_t AudioDeviceMac::InitSpeaker() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_playing) {
     return -1;
@@ -471,7 +469,7 @@
 }
 
 int32_t AudioDeviceMac::InitMicrophone() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_recording) {
     return -1;
@@ -901,7 +899,7 @@
 }
 
 int32_t AudioDeviceMac::SetPlayoutDevice(uint16_t index) {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_playIsInitialized) {
     return -1;
@@ -1053,7 +1051,7 @@
 }
 
 int32_t AudioDeviceMac::InitPlayout() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_playing) {
     return -1;
@@ -1200,7 +1198,7 @@
 }
 
 int32_t AudioDeviceMac::InitRecording() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_recording) {
     return -1;
@@ -1402,7 +1400,7 @@
 }
 
 int32_t AudioDeviceMac::StartRecording() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (!_recIsInitialized) {
     return -1;
@@ -1439,7 +1437,7 @@
 }
 
 int32_t AudioDeviceMac::StopRecording() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (!_recIsInitialized) {
     return 0;
@@ -1455,7 +1453,7 @@
       _doStopRec = true;  // Signal to io proc to stop audio device
       _critSect.Leave();  // Cannot be under lock, risk of deadlock
       if (kEventTimeout == _stopEventRec.Wait(2000)) {
-        CriticalSectionScoped critScoped(&_critSect);
+        rtc::CritScope critScoped(&_critSect);
         WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
                      " Timed out stopping the capture IOProc. "
                      "We may have failed to detect a device removal.");
@@ -1481,7 +1479,7 @@
       _doStop = true;     // Signal to io proc to stop audio device
       _critSect.Leave();  // Cannot be under lock, risk of deadlock
       if (kEventTimeout == _stopEvent.Wait(2000)) {
-        CriticalSectionScoped critScoped(&_critSect);
+        rtc::CritScope critScoped(&_critSect);
         WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
                      " Timed out stopping the shared IOProc. "
                      "We may have failed to detect a device removal.");
@@ -1540,7 +1538,7 @@
 }
 
 int32_t AudioDeviceMac::StartPlayout() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (!_playIsInitialized) {
     return -1;
@@ -1566,7 +1564,7 @@
 }
 
 int32_t AudioDeviceMac::StopPlayout() {
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (!_playIsInitialized) {
     return 0;
@@ -1587,7 +1585,7 @@
     _doStop = true;     // Signal to io proc to stop audio device
     _critSect.Leave();  // Cannot be under lock, risk of deadlock
     if (kEventTimeout == _stopEvent.Wait(2000)) {
-      CriticalSectionScoped critScoped(&_critSect);
+      rtc::CritScope critScoped(&_critSect);
       WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
                    " Timed out stopping the render IOProc. "
                    "We may have failed to detect a device removal.");
diff --git a/modules/audio_device/mac/audio_device_mac.h b/modules/audio_device/mac/audio_device_mac.h
index ccde6f0..52b44eb 100644
--- a/modules/audio_device/mac/audio_device_mac.h
+++ b/modules/audio_device/mac/audio_device_mac.h
@@ -13,10 +13,11 @@
 
 #include <memory>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/modules/audio_device/audio_device_generic.h"
 #include "webrtc/modules/audio_device/mac/audio_mixer_manager_mac.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
+#include "webrtc/system_wrappers/include/event_wrapper.h"
 
 #include <AudioToolbox/AudioConverter.h>
 #include <CoreAudio/CoreAudio.h>
@@ -283,7 +284,7 @@
 
   AudioDeviceBuffer* _ptrAudioBuffer;
 
-  CriticalSectionWrapper& _critSect;
+  rtc::CriticalSection _critSect;
 
   EventWrapper& _stopEventRec;
   EventWrapper& _stopEvent;
diff --git a/modules/audio_device/mac/audio_mixer_manager_mac.cc b/modules/audio_device/mac/audio_mixer_manager_mac.cc
index e7e0754..3347a02 100644
--- a/modules/audio_device/mac/audio_mixer_manager_mac.cc
+++ b/modules/audio_device/mac/audio_mixer_manager_mac.cc
@@ -9,7 +9,6 @@
  */
 
 #include "webrtc/modules/audio_device/mac/audio_mixer_manager_mac.h"
-#include "webrtc/system_wrappers/include/trace.h"
 
 #include <unistd.h>  // getpid()
 
@@ -44,8 +43,7 @@
   } while (0)
 
 AudioMixerManagerMac::AudioMixerManagerMac(const int32_t id)
-    : _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
-      _id(id),
+    : _id(id),
       _inputDeviceID(kAudioObjectUnknown),
       _outputDeviceID(kAudioObjectUnknown),
       _noInputChannels(0),
@@ -57,10 +55,7 @@
 AudioMixerManagerMac::~AudioMixerManagerMac() {
   WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destructed",
                __FUNCTION__);
-
   Close();
-
-  delete &_critSect;
 }
 
 // ============================================================================
@@ -70,7 +65,7 @@
 int32_t AudioMixerManagerMac::Close() {
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   CloseSpeaker();
   CloseMicrophone();
@@ -81,7 +76,7 @@
 int32_t AudioMixerManagerMac::CloseSpeaker() {
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   _outputDeviceID = kAudioObjectUnknown;
   _noOutputChannels = 0;
@@ -92,7 +87,7 @@
 int32_t AudioMixerManagerMac::CloseMicrophone() {
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   _inputDeviceID = kAudioObjectUnknown;
   _noInputChannels = 0;
@@ -104,7 +99,7 @@
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                "AudioMixerManagerMac::OpenSpeaker(id=%d)", deviceID);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   OSStatus err = noErr;
   UInt32 size = 0;
@@ -155,7 +150,7 @@
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                "AudioMixerManagerMac::OpenMicrophone(id=%d)", deviceID);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   OSStatus err = noErr;
   UInt32 size = 0;
@@ -216,7 +211,7 @@
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                "AudioMixerManagerMac::SetSpeakerVolume(volume=%u)", volume);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_outputDeviceID == kAudioObjectUnknown) {
     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
@@ -456,7 +451,7 @@
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                "AudioMixerManagerMac::SetSpeakerMute(enable=%u)", enable);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_outputDeviceID == kAudioObjectUnknown) {
     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
@@ -632,7 +627,7 @@
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                "AudioMixerManagerMac::SetMicrophoneMute(enable=%u)", enable);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_inputDeviceID == kAudioObjectUnknown) {
     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
@@ -759,7 +754,7 @@
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                "AudioMixerManagerMac::SetMicrophoneBoost(enable=%u)", enable);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_inputDeviceID == kAudioObjectUnknown) {
     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
@@ -837,7 +832,7 @@
   WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                "AudioMixerManagerMac::SetMicrophoneVolume(volume=%u)", volume);
 
-  CriticalSectionScoped lock(&_critSect);
+  rtc::CritScope lock(&_critSect);
 
   if (_inputDeviceID == kAudioObjectUnknown) {
     WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
diff --git a/modules/audio_device/mac/audio_mixer_manager_mac.h b/modules/audio_device/mac/audio_mixer_manager_mac.h
index 9cbfe2d..17515a6 100644
--- a/modules/audio_device/mac/audio_mixer_manager_mac.h
+++ b/modules/audio_device/mac/audio_mixer_manager_mac.h
@@ -11,8 +11,9 @@
 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_MAC_H
 #define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_MAC_H
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/audio_device/include/audio_device.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
+#include "webrtc/system_wrappers/include/trace.h"
 #include "webrtc/typedefs.h"
 
 #include <CoreAudio/CoreAudio.h>
@@ -64,7 +65,7 @@
                        const char* err);
 
  private:
-  CriticalSectionWrapper& _critSect;
+  rtc::CriticalSection _critSect;
   int32_t _id;
 
   AudioDeviceID _inputDeviceID;
diff --git a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
index 56ac85a..b8e5142 100644
--- a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
+++ b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc
@@ -20,7 +20,6 @@
 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h"
 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h"
 #include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/metrics.h"
 #include "webrtc/typedefs.h"
 
@@ -53,7 +52,6 @@
       last_valid_incoming_bitrate_(0),
       remote_rate_(new AimdRateControl()),
       observer_(observer),
-      crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
       last_process_time_(-1),
       process_interval_ms_(kProcessIntervalMs),
       uma_recorded_(false) {
@@ -83,7 +81,7 @@
   uint32_t rtp_timestamp = header.timestamp +
       header.extension.transmissionTimeOffset;
   int64_t now_ms = clock_->TimeInMilliseconds();
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.find(ssrc);
   if (it == overuse_detectors_.end()) {
     // This is a new SSRC. Adding to map.
@@ -143,7 +141,7 @@
 
 void RemoteBitrateEstimatorSingleStream::Process() {
   {
-    CriticalSectionScoped cs(crit_sect_.get());
+    rtc::CritScope cs(&crit_sect_);
     UpdateEstimate(clock_->TimeInMilliseconds());
   }
   last_process_time_ = clock_->TimeInMilliseconds();
@@ -153,7 +151,7 @@
   if (last_process_time_ < 0) {
     return 0;
   }
-  CriticalSectionScoped cs_(crit_sect_.get());
+  rtc::CritScope cs_(&crit_sect_);
   RTC_DCHECK_GT(process_interval_ms_, 0);
   return last_process_time_ + process_interval_ms_ -
       clock_->TimeInMilliseconds();
@@ -207,12 +205,12 @@
 
 void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avg_rtt_ms,
                                                      int64_t max_rtt_ms) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   GetRemoteRate()->SetRtt(avg_rtt_ms);
 }
 
 void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.find(ssrc);
   if (it != overuse_detectors_.end()) {
     delete it->second;
@@ -223,7 +221,7 @@
 bool RemoteBitrateEstimatorSingleStream::LatestEstimate(
     std::vector<uint32_t>* ssrcs,
     uint32_t* bitrate_bps) const {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   assert(bitrate_bps);
   if (!remote_rate_->ValidEstimate()) {
     return false;
@@ -254,7 +252,7 @@
 }
 
 void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int min_bitrate_bps) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   remote_rate_->SetMinBitrate(min_bitrate_bps);
 }
 
diff --git a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h
index 610d961..0b78bfc 100644
--- a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h
+++ b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h
@@ -16,10 +16,10 @@
 #include <vector>
 
 #include "webrtc/base/constructormagic.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/rate_statistics.h"
 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h"
 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 
@@ -47,24 +47,24 @@
 
   // Triggers a new estimate calculation.
   void UpdateEstimate(int64_t time_now)
-      EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get());
+      EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
 
   void GetSsrcs(std::vector<uint32_t>* ssrcs) const
-      SHARED_LOCKS_REQUIRED(crit_sect_.get());
+      SHARED_LOCKS_REQUIRED(crit_sect_);
 
   // Returns |remote_rate_| if the pointed to object exists,
   // otherwise creates it.
-  AimdRateControl* GetRemoteRate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get());
+  AimdRateControl* GetRemoteRate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
 
   const Clock* const clock_;
-  SsrcOveruseEstimatorMap overuse_detectors_ GUARDED_BY(crit_sect_.get());
-  RateStatistics incoming_bitrate_ GUARDED_BY(crit_sect_.get());
-  uint32_t last_valid_incoming_bitrate_ GUARDED_BY(crit_sect_.get());
-  std::unique_ptr<AimdRateControl> remote_rate_ GUARDED_BY(crit_sect_.get());
-  RemoteBitrateObserver* const observer_ GUARDED_BY(crit_sect_.get());
-  std::unique_ptr<CriticalSectionWrapper> crit_sect_;
+  SsrcOveruseEstimatorMap overuse_detectors_ GUARDED_BY(crit_sect_);
+  RateStatistics incoming_bitrate_ GUARDED_BY(crit_sect_);
+  uint32_t last_valid_incoming_bitrate_ GUARDED_BY(crit_sect_);
+  std::unique_ptr<AimdRateControl> remote_rate_ GUARDED_BY(crit_sect_);
+  RemoteBitrateObserver* const observer_ GUARDED_BY(crit_sect_);
+  rtc::CriticalSection crit_sect_;
   int64_t last_process_time_;
-  int64_t process_interval_ms_ GUARDED_BY(crit_sect_.get());
+  int64_t process_interval_ms_ GUARDED_BY(crit_sect_);
   bool uma_recorded_;
 
   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RemoteBitrateEstimatorSingleStream);
diff --git a/modules/remote_bitrate_estimator/test/bwe_test_logging.cc b/modules/remote_bitrate_estimator/test/bwe_test_logging.cc
index ab6be5a..a8cd84d 100644
--- a/modules/remote_bitrate_estimator/test/bwe_test_logging.cc
+++ b/modules/remote_bitrate_estimator/test/bwe_test_logging.cc
@@ -21,7 +21,6 @@
 #include "webrtc/base/checks.h"
 #include "webrtc/base/format_macros.h"
 #include "webrtc/base/platform_thread.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 
 namespace webrtc {
 namespace testing {
@@ -58,27 +57,27 @@
 }
 
 void Logging::SetGlobalContext(uint32_t name) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   thread_map_[rtc::CurrentThreadId()].global_state.tag = ToString(name);
 }
 
 void Logging::SetGlobalContext(const std::string& name) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   thread_map_[rtc::CurrentThreadId()].global_state.tag = name;
 }
 
 void Logging::SetGlobalContext(const char* name) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   thread_map_[rtc::CurrentThreadId()].global_state.tag = name;
 }
 
 void Logging::SetGlobalEnable(bool enabled) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   thread_map_[rtc::CurrentThreadId()].global_state.enabled = enabled;
 }
 
 void Logging::Log(const char format[], ...) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   const State& state = it->second.stack.top();
@@ -115,7 +114,7 @@
                    double value,
                    uint32_t ssrc,
                    const std::string& alg_name) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   const State& state = it->second.stack.top();
@@ -129,7 +128,7 @@
                       const std::string& name,
                       double value,
                       int flow_id) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   const State& state = it->second.stack.top();
@@ -142,7 +141,7 @@
                               const std::string& name,
                               double value,
                               int flow_id) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   const State& state = it->second.stack.top();
@@ -158,7 +157,7 @@
                            double yhigh,
                            const std::string& error_title,
                            int flow_id) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   const State& state = it->second.stack.top();
@@ -177,7 +176,7 @@
                                 double ymax,
                                 const std::string& limit_title,
                                 int flow_id) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   const State& state = it->second.stack.top();
@@ -192,7 +191,7 @@
                         const std::string& title,
                         const std::string& y_label,
                         int num_flows) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   const State& state = it->second.stack.top();
@@ -203,8 +202,7 @@
 }
 
 Logging::Logging()
-    : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
-      thread_map_() {
+    : thread_map_() {
 }
 
 Logging::State::State() : tag(""), timestamp_ms(0), enabled(true) {}
@@ -228,7 +226,7 @@
 
 void Logging::PushState(const std::string& append_to_tag, int64_t timestamp_ms,
                         bool enabled) {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   State new_state(append_to_tag, timestamp_ms, enabled);
   ThreadState* thread_state = &thread_map_[rtc::CurrentThreadId()];
   std::stack<State>* stack = &thread_state->stack;
@@ -241,7 +239,7 @@
 }
 
 void Logging::PopState() {
-  CriticalSectionScoped cs(crit_sect_.get());
+  rtc::CritScope cs(&crit_sect_);
   ThreadMap::iterator it = thread_map_.find(rtc::CurrentThreadId());
   RTC_DCHECK(it != thread_map_.end());
   std::stack<State>* stack = &it->second.stack;
diff --git a/modules/remote_bitrate_estimator/test/bwe_test_logging.h b/modules/remote_bitrate_estimator/test/bwe_test_logging.h
index 9262164..be9ecdb 100644
--- a/modules/remote_bitrate_estimator/test/bwe_test_logging.h
+++ b/modules/remote_bitrate_estimator/test/bwe_test_logging.h
@@ -129,6 +129,7 @@
 #include <string>
 
 #include "webrtc/base/constructormagic.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/common_types.h"
 
 #define BWE_TEST_LOGGING_GLOBAL_CONTEXT(name) \
@@ -254,9 +255,6 @@
   } while (0)
 
 namespace webrtc {
-
-class CriticalSectionWrapper;
-
 namespace testing {
 namespace bwe {
 
@@ -340,7 +338,7 @@
   void PopState();
 
   static Logging g_Logging;
-  std::unique_ptr<CriticalSectionWrapper> crit_sect_;
+  rtc::CriticalSection crit_sect_;
   ThreadMap thread_map_;
 
   RTC_DISALLOW_COPY_AND_ASSIGN(Logging);
diff --git a/modules/video_capture/linux/video_capture_linux.cc b/modules/video_capture/linux/video_capture_linux.cc
index d09c42a..c7c9f3e 100644
--- a/modules/video_capture/linux/video_capture_linux.cc
+++ b/modules/video_capture/linux/video_capture_linux.cc
@@ -24,7 +24,6 @@
 #include "webrtc/base/refcount.h"
 #include "webrtc/base/scoped_ref_ptr.h"
 #include "webrtc/modules/video_capture/linux/video_capture_linux.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
 namespace webrtc {
@@ -42,7 +41,6 @@
 
 VideoCaptureModuleV4L2::VideoCaptureModuleV4L2()
     : VideoCaptureImpl(),
-      _captureCritSect(CriticalSectionWrapper::CreateCriticalSection()),
       _deviceId(-1),
       _deviceFd(-1),
       _buffersAllocatedByDevice(-1),
@@ -107,10 +105,6 @@
 VideoCaptureModuleV4L2::~VideoCaptureModuleV4L2()
 {
     StopCapture();
-    if (_captureCritSect)
-    {
-        delete _captureCritSect;
-    }
     if (_deviceFd != -1)
       close(_deviceFd);
 }
@@ -132,7 +126,7 @@
         }
     }
 
-    CriticalSectionScoped cs(_captureCritSect);
+    rtc::CritScope cs(&_captureCritSect);
     //first open /dev/video device
     char device[20];
     sprintf(device, "/dev/video%d", (int) _deviceId);
@@ -303,7 +297,7 @@
         _captureThread.reset();
     }
 
-    CriticalSectionScoped cs(_captureCritSect);
+    rtc::CritScope cs(&_captureCritSect);
     if (_captureStarted)
     {
         _captureStarted = false;
@@ -410,7 +404,7 @@
     fd_set rSet;
     struct timeval timeout;
 
-    _captureCritSect->Enter();
+    rtc::CritScope cs(&_captureCritSect);
 
     FD_ZERO(&rSet);
     FD_SET(_deviceFd, &rSet);
@@ -421,19 +415,16 @@
     if (retVal < 0 && errno != EINTR) // continue if interrupted
     {
         // select failed
-        _captureCritSect->Leave();
         return false;
     }
     else if (retVal == 0)
     {
         // select timed out
-        _captureCritSect->Leave();
         return true;
     }
     else if (!FD_ISSET(_deviceFd, &rSet))
     {
         // not event on camera handle
-        _captureCritSect->Leave();
         return true;
     }
 
@@ -450,7 +441,6 @@
             {
                 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
                            "could not sync on a buffer on device %s", strerror(errno));
-                _captureCritSect->Leave();
                 return true;
             }
         }
@@ -469,7 +459,6 @@
                        "Failed to enqueue capture buffer");
         }
     }
-    _captureCritSect->Leave();
     usleep(0);
     return true;
 }
diff --git a/modules/video_capture/linux/video_capture_linux.h b/modules/video_capture/linux/video_capture_linux.h
index e048e88..fdfcdb5 100644
--- a/modules/video_capture/linux/video_capture_linux.h
+++ b/modules/video_capture/linux/video_capture_linux.h
@@ -13,13 +13,13 @@
 
 #include <memory>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/platform_thread.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/video_capture/video_capture_impl.h"
 
 namespace webrtc
 {
-class CriticalSectionWrapper;
 namespace videocapturemodule
 {
 class VideoCaptureModuleV4L2: public VideoCaptureImpl
@@ -43,7 +43,7 @@
 
     // TODO(pbos): Stop using unique_ptr and resetting the thread.
     std::unique_ptr<rtc::PlatformThread> _captureThread;
-    CriticalSectionWrapper* _captureCritSect;
+    rtc::CriticalSection _captureCritSect;
 
     int32_t _deviceId;
     int32_t _deviceFd;
diff --git a/modules/video_capture/test/video_capture_unittest.cc b/modules/video_capture/test/video_capture_unittest.cc
index d0c3ec9..a4a7a72 100644
--- a/modules/video_capture/test/video_capture_unittest.cc
+++ b/modules/video_capture/test/video_capture_unittest.cc
@@ -16,19 +16,17 @@
 
 #include "webrtc/api/video/i420_buffer.h"
 #include "webrtc/api/video/video_frame.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/scoped_ref_ptr.h"
 #include "webrtc/base/timeutils.h"
 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
 #include "webrtc/modules/utility/include/process_thread.h"
 #include "webrtc/modules/video_capture/video_capture.h"
 #include "webrtc/modules/video_capture/video_capture_factory.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/sleep.h"
 #include "webrtc/test/frame_utils.h"
 #include "webrtc/test/gtest.h"
 
-using webrtc::CriticalSectionWrapper;
-using webrtc::CriticalSectionScoped;
 using webrtc::SleepMs;
 using webrtc::VideoCaptureCapability;
 using webrtc::VideoCaptureFactory;
@@ -61,8 +59,7 @@
 class TestVideoCaptureCallback
     : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
  public:
-  TestVideoCaptureCallback()
-      : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()),
+  TestVideoCaptureCallback() :
         last_render_time_ms_(0),
         incoming_frames_(0),
         timing_warnings_(0),
@@ -74,7 +71,7 @@
   }
 
   void OnFrame(const webrtc::VideoFrame& videoFrame) override {
-    CriticalSectionScoped cs(capture_cs_.get());
+    rtc::CritScope cs(&capture_cs_);
     int height = videoFrame.height();
     int width = videoFrame.width();
 #if defined(ANDROID) && ANDROID
@@ -107,38 +104,38 @@
   }
 
   void SetExpectedCapability(VideoCaptureCapability capability) {
-    CriticalSectionScoped cs(capture_cs_.get());
+    rtc::CritScope cs(&capture_cs_);
     capability_= capability;
     incoming_frames_ = 0;
     last_render_time_ms_ = 0;
   }
   int incoming_frames() {
-    CriticalSectionScoped cs(capture_cs_.get());
+    rtc::CritScope cs(&capture_cs_);
     return incoming_frames_;
   }
 
   int timing_warnings() {
-    CriticalSectionScoped cs(capture_cs_.get());
+    rtc::CritScope cs(&capture_cs_);
     return timing_warnings_;
   }
   VideoCaptureCapability capability() {
-    CriticalSectionScoped cs(capture_cs_.get());
+    rtc::CritScope cs(&capture_cs_);
     return capability_;
   }
 
   bool CompareLastFrame(const webrtc::VideoFrame& frame) {
-    CriticalSectionScoped cs(capture_cs_.get());
+    rtc::CritScope cs(&capture_cs_);
     return webrtc::test::FrameBufsEqual(last_frame_,
                                         frame.video_frame_buffer());
   }
 
   void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) {
-    CriticalSectionScoped cs(capture_cs_.get());
+    rtc::CritScope cs(&capture_cs_);
     rotate_frame_ = rotation;
   }
 
  private:
-  std::unique_ptr<CriticalSectionWrapper> capture_cs_;
+  rtc::CriticalSection capture_cs_;
   VideoCaptureCapability capability_;
   int64_t last_render_time_ms_;
   int incoming_frames_;
diff --git a/modules/video_capture/video_capture_impl.cc b/modules/video_capture/video_capture_impl.cc
index ead2b15..cc4c797 100644
--- a/modules/video_capture/video_capture_impl.cc
+++ b/modules/video_capture/video_capture_impl.cc
@@ -20,7 +20,6 @@
 #include "webrtc/modules/include/module_common_types.h"
 #include "webrtc/modules/video_capture/video_capture_config.h"
 #include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/logging.h"
 
 namespace webrtc {
@@ -81,7 +80,6 @@
 
 VideoCaptureImpl::VideoCaptureImpl()
     : _deviceUniqueId(NULL),
-      _apiCs(*CriticalSectionWrapper::CreateCriticalSection()),
       _requestedCapability(),
       _lastProcessTimeNanos(rtc::TimeNanos()),
       _lastFrameRateCallbackTimeNanos(rtc::TimeNanos()),
@@ -99,20 +97,18 @@
 VideoCaptureImpl::~VideoCaptureImpl()
 {
     DeRegisterCaptureDataCallback();
-    delete &_apiCs;
-
     if (_deviceUniqueId)
         delete[] _deviceUniqueId;
 }
 
 void VideoCaptureImpl::RegisterCaptureDataCallback(
     rtc::VideoSinkInterface<VideoFrame>* dataCallBack) {
-    CriticalSectionScoped cs(&_apiCs);
+    rtc::CritScope cs(&_apiCs);
     _dataCallBack = dataCallBack;
 }
 
 void VideoCaptureImpl::DeRegisterCaptureDataCallback() {
-    CriticalSectionScoped cs(&_apiCs);
+    rtc::CritScope cs(&_apiCs);
     _dataCallBack = NULL;
 }
 int32_t VideoCaptureImpl::DeliverCapturedFrame(VideoFrame& captureFrame) {
@@ -131,7 +127,7 @@
     const VideoCaptureCapability& frameInfo,
     int64_t captureTime/*=0*/)
 {
-    CriticalSectionScoped cs(&_apiCs);
+    rtc::CritScope cs(&_apiCs);
 
     const int32_t width = frameInfo.width;
     const int32_t height = frameInfo.height;
@@ -196,7 +192,7 @@
 }
 
 int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) {
-  CriticalSectionScoped cs(&_apiCs);
+  rtc::CritScope cs(&_apiCs);
   _rotateFrame = rotation;
   return 0;
 }
diff --git a/modules/video_capture/video_capture_impl.h b/modules/video_capture/video_capture_impl.h
index 559e14e..2cdb93e 100644
--- a/modules/video_capture/video_capture_impl.h
+++ b/modules/video_capture/video_capture_impl.h
@@ -16,6 +16,7 @@
  */
 
 #include "webrtc/api/video/video_frame.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/scoped_ref_ptr.h"
 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
 #include "webrtc/modules/video_capture/video_capture.h"
@@ -23,7 +24,6 @@
 
 namespace webrtc
 {
-class CriticalSectionWrapper;
 
 namespace videocapturemodule {
 // Class definitions
@@ -93,7 +93,7 @@
     int32_t DeliverCapturedFrame(VideoFrame& captureFrame);
 
     char* _deviceUniqueId; // current Device unique name;
-    CriticalSectionWrapper& _apiCs;
+    rtc::CriticalSection _apiCs;
     VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture.
 private:
     void UpdateFrameCount();
diff --git a/modules/video_capture/windows/video_capture_ds.cc b/modules/video_capture/windows/video_capture_ds.cc
index a98b1b8..9bb928d 100644
--- a/modules/video_capture/windows/video_capture_ds.cc
+++ b/modules/video_capture/windows/video_capture_ds.cc
@@ -13,7 +13,6 @@
 #include "webrtc/modules/video_capture/video_capture_config.h"
 #include "webrtc/modules/video_capture/windows/help_functions_ds.h"
 #include "webrtc/modules/video_capture/windows/sink_filter_ds.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
 #include <Dvdmedia.h> // VIDEOINFOHEADER2
@@ -153,7 +152,7 @@
 int32_t VideoCaptureDS::StartCapture(
                                       const VideoCaptureCapability& capability)
 {
-    CriticalSectionScoped cs(&_apiCs);
+    rtc::CritScope cs(&_apiCs);
 
     if (capability != _requestedCapability)
     {
@@ -176,7 +175,7 @@
 
 int32_t VideoCaptureDS::StopCapture()
 {
-    CriticalSectionScoped cs(&_apiCs);
+    rtc::CritScope cs(&_apiCs);
 
     HRESULT hr = _mediaControl->Pause();
     if (FAILED(hr))
diff --git a/modules/video_coding/codecs/test/packet_manipulator.cc b/modules/video_coding/codecs/test/packet_manipulator.cc
index b554b4e..9bde45e 100644
--- a/modules/video_coding/codecs/test/packet_manipulator.cc
+++ b/modules/video_coding/codecs/test/packet_manipulator.cc
@@ -24,16 +24,11 @@
     : packet_reader_(packet_reader),
       config_(config),
       active_burst_packets_(0),
-      critsect_(CriticalSectionWrapper::CreateCriticalSection()),
       random_seed_(1),
       verbose_(verbose) {
   assert(packet_reader);
 }
 
-PacketManipulatorImpl::~PacketManipulatorImpl() {
-  delete critsect_;
-}
-
 int PacketManipulatorImpl::ManipulatePackets(
     webrtc::EncodedImage* encoded_image) {
   int nbr_packets_dropped = 0;
@@ -89,10 +84,10 @@
   // Use the previous result as new seed before each rand() call. Doing this
   // it doesn't matter if other threads are calling rand() since we'll always
   // get the same behavior as long as we're using a fixed initial seed.
-  critsect_->Enter();
+  critsect_.Enter();
   srand(random_seed_);
   random_seed_ = rand();  // NOLINT (rand_r instead of rand)
-  critsect_->Leave();
+  critsect_.Leave();
   return (random_seed_ + 1.0) / (RAND_MAX + 1.0);
 }
 
diff --git a/modules/video_coding/codecs/test/packet_manipulator.h b/modules/video_coding/codecs/test/packet_manipulator.h
index 3334be0..9b8585c 100644
--- a/modules/video_coding/codecs/test/packet_manipulator.h
+++ b/modules/video_coding/codecs/test/packet_manipulator.h
@@ -13,8 +13,8 @@
 
 #include <stdlib.h>
 
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/test/testsupport/packet_reader.h"
 
 namespace webrtc {
@@ -91,7 +91,7 @@
   PacketManipulatorImpl(PacketReader* packet_reader,
                         const NetworkingConfig& config,
                         bool verbose);
-  virtual ~PacketManipulatorImpl();
+  ~PacketManipulatorImpl() = default;
   int ManipulatePackets(webrtc::EncodedImage* encoded_image) override;
   virtual void InitializeRandomSeed(unsigned int seed);
 
@@ -104,7 +104,7 @@
   const NetworkingConfig& config_;
   // Used to simulate a burst over several frames.
   int active_burst_packets_;
-  CriticalSectionWrapper* critsect_;
+  rtc::CriticalSection critsect_;
   unsigned int random_seed_;
   bool verbose_;
 };
diff --git a/modules/video_coding/generic_encoder.h b/modules/video_coding/generic_encoder.h
index 4d2ea2f..939d8b0 100644
--- a/modules/video_coding/generic_encoder.h
+++ b/modules/video_coding/generic_encoder.h
@@ -21,7 +21,6 @@
 #include "webrtc/base/race_checker.h"
 
 namespace webrtc {
-class CriticalSectionWrapper;
 
 namespace media_optimization {
 class MediaOptimization;
diff --git a/modules/video_coding/jitter_buffer.cc b/modules/video_coding/jitter_buffer.cc
index 345bdf7..c74ebe5 100644
--- a/modules/video_coding/jitter_buffer.cc
+++ b/modules/video_coding/jitter_buffer.cc
@@ -27,7 +27,6 @@
 #include "webrtc/modules/video_coding/jitter_estimator.h"
 #include "webrtc/modules/video_coding/packet.h"
 #include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/field_trial.h"
 #include "webrtc/system_wrappers/include/metrics.h"
@@ -221,7 +220,6 @@
                                  KeyFrameRequestSender* keyframe_request_sender)
     : clock_(clock),
       running_(false),
-      crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
       frame_event_(std::move(event)),
       max_number_of_frames_(kStartNumberOfFrames),
       free_frames_(),
@@ -272,7 +270,6 @@
        it != decodable_frames_.end(); ++it) {
     delete it->second;
   }
-  delete crit_sect_;
 }
 
 void VCMJitterBuffer::UpdateHistograms() {
@@ -304,7 +301,7 @@
 }
 
 void VCMJitterBuffer::Start() {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   running_ = true;
   incoming_frame_count_ = 0;
   incoming_frame_rate_ = 0;
@@ -332,7 +329,7 @@
 }
 
 void VCMJitterBuffer::Stop() {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   UpdateHistograms();
   running_ = false;
   last_decoded_state_.Reset();
@@ -342,12 +339,12 @@
 }
 
 bool VCMJitterBuffer::Running() const {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   return running_;
 }
 
 void VCMJitterBuffer::Flush() {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   decodable_frames_.Reset(&free_frames_);
   incomplete_frames_.Reset(&free_frames_);
   last_decoded_state_.Reset();  // TODO(mikhal): sync reset.
@@ -364,22 +361,22 @@
 
 // Get received key and delta frames
 FrameCounts VCMJitterBuffer::FrameStatistics() const {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   return receive_statistics_;
 }
 
 int VCMJitterBuffer::num_packets() const {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   return num_packets_;
 }
 
 int VCMJitterBuffer::num_duplicated_packets() const {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   return num_duplicated_packets_;
 }
 
 int VCMJitterBuffer::num_discarded_packets() const {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   return num_discarded_packets_;
 }
 
@@ -388,7 +385,7 @@
                                              unsigned int* bitrate) {
   assert(framerate);
   assert(bitrate);
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   const int64_t now = clock_->TimeInMilliseconds();
   int64_t diff = now - time_last_incoming_frame_count_;
   if (diff < 1000 && incoming_frame_rate_ > 0 && incoming_bit_rate_ > 0) {
@@ -445,9 +442,9 @@
 // Returns immediately or a |max_wait_time_ms| ms event hang waiting for a
 // complete frame, |max_wait_time_ms| decided by caller.
 VCMEncodedFrame* VCMJitterBuffer::NextCompleteFrame(uint32_t max_wait_time_ms) {
-  crit_sect_->Enter();
+  crit_sect_.Enter();
   if (!running_) {
-    crit_sect_->Leave();
+    crit_sect_.Leave();
     return nullptr;
   }
   CleanUpOldOrEmptyFrames();
@@ -458,14 +455,14 @@
         clock_->TimeInMilliseconds() + max_wait_time_ms;
     int64_t wait_time_ms = max_wait_time_ms;
     while (wait_time_ms > 0) {
-      crit_sect_->Leave();
+      crit_sect_.Leave();
       const EventTypeWrapper ret =
           frame_event_->Wait(static_cast<uint32_t>(wait_time_ms));
-      crit_sect_->Enter();
+      crit_sect_.Enter();
       if (ret == kEventSignaled) {
         // Are we shutting down the jitter buffer?
         if (!running_) {
-          crit_sect_->Leave();
+          crit_sect_.Leave();
           return nullptr;
         }
         // Finding oldest frame ready for decoder.
@@ -483,16 +480,16 @@
   }
   if (decodable_frames_.empty() ||
       decodable_frames_.Front()->GetState() != kStateComplete) {
-    crit_sect_->Leave();
+    crit_sect_.Leave();
     return nullptr;
   }
   VCMEncodedFrame* encoded_frame = decodable_frames_.Front();
-  crit_sect_->Leave();
+  crit_sect_.Leave();
   return encoded_frame;
 }
 
 bool VCMJitterBuffer::NextMaybeIncompleteTimestamp(uint32_t* timestamp) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   if (!running_) {
     return false;
   }
@@ -529,7 +526,7 @@
 }
 
 VCMEncodedFrame* VCMJitterBuffer::ExtractAndSetDecode(uint32_t timestamp) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   if (!running_) {
     return NULL;
   }
@@ -583,7 +580,7 @@
 // frames from within the jitter buffer.
 void VCMJitterBuffer::ReleaseFrame(VCMEncodedFrame* frame) {
   RTC_CHECK(frame != nullptr);
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   VCMFrameBuffer* frame_buffer = static_cast<VCMFrameBuffer*>(frame);
   RecycleFrameBuffer(frame_buffer);
 }
@@ -624,7 +621,7 @@
 int64_t VCMJitterBuffer::LastPacketTime(const VCMEncodedFrame* frame,
                                         bool* retransmitted) const {
   assert(retransmitted);
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   const VCMFrameBuffer* frame_buffer =
       static_cast<const VCMFrameBuffer*>(frame);
   *retransmitted = (frame_buffer->GetNackCount() > 0);
@@ -633,7 +630,7 @@
 
 VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(const VCMPacket& packet,
                                                  bool* retransmitted) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
 
   ++num_packets_;
   if (num_packets_ == 1) {
@@ -880,7 +877,7 @@
 }
 
 uint32_t VCMJitterBuffer::EstimatedJitterMs() {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   // Compute RTT multiplier for estimation.
   // low_rtt_nackThresholdMs_ == -1 means no FEC.
   double rtt_mult = 1.0f;
@@ -894,7 +891,7 @@
 }
 
 void VCMJitterBuffer::UpdateRtt(int64_t rtt_ms) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   rtt_ms_ = rtt_ms;
   jitter_estimate_.UpdateRtt(rtt_ms);
   if (!WaitForRetransmissions())
@@ -904,7 +901,7 @@
 void VCMJitterBuffer::SetNackMode(VCMNackMode mode,
                                   int64_t low_rtt_nack_threshold_ms,
                                   int64_t high_rtt_nack_threshold_ms) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   nack_mode_ = mode;
   if (mode == kNoNack) {
     missing_sequence_numbers_.clear();
@@ -928,7 +925,7 @@
 void VCMJitterBuffer::SetNackSettings(size_t max_nack_list_size,
                                       int max_packet_age_to_nack,
                                       int max_incomplete_time_ms) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   assert(max_packet_age_to_nack >= 0);
   assert(max_incomplete_time_ms_ >= 0);
   max_nack_list_size_ = max_nack_list_size;
@@ -937,7 +934,7 @@
 }
 
 VCMNackMode VCMJitterBuffer::nack_mode() const {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   return nack_mode_;
 }
 
@@ -964,7 +961,7 @@
 }
 
 std::vector<uint16_t> VCMJitterBuffer::GetNackList(bool* request_key_frame) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   *request_key_frame = false;
   if (nack_mode_ == kNoNack) {
     return std::vector<uint16_t>();
@@ -1024,7 +1021,7 @@
 }
 
 void VCMJitterBuffer::SetDecodeErrorMode(VCMDecodeErrorMode error_mode) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   decode_error_mode_ = error_mode;
 }
 
@@ -1124,7 +1121,7 @@
 
 void VCMJitterBuffer::RegisterStatsCallback(
     VCMReceiveStatisticsCallback* callback) {
-  CriticalSectionScoped cs(crit_sect_);
+  rtc::CritScope cs(&crit_sect_);
   stats_callback_ = callback;
 }
 
diff --git a/modules/video_coding/jitter_buffer.h b/modules/video_coding/jitter_buffer.h
index 62017da..460b8ae 100644
--- a/modules/video_coding/jitter_buffer.h
+++ b/modules/video_coding/jitter_buffer.h
@@ -18,6 +18,7 @@
 #include <vector>
 
 #include "webrtc/base/constructormagic.h"
+#include "webrtc/base/criticalsection.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/modules/include/module_common_types.h"
 #include "webrtc/modules/utility/include/process_thread.h"
@@ -28,7 +29,6 @@
 #include "webrtc/modules/video_coding/jitter_buffer_common.h"
 #include "webrtc/modules/video_coding/jitter_estimator.h"
 #include "webrtc/modules/video_coding/nack_module.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -315,7 +315,7 @@
   Clock* clock_;
   // If we are running (have started) or not.
   bool running_;
-  CriticalSectionWrapper* crit_sect_;
+  rtc::CriticalSection crit_sect_;
   // Event to signal when we have a frame ready for decoder.
   std::unique_ptr<EventWrapper> frame_event_;
   // Number of allocated frames.
diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn
index 83f5f23..708fd31 100644
--- a/system_wrappers/BUILD.gn
+++ b/system_wrappers/BUILD.gn
@@ -20,7 +20,6 @@
     "include/clock.h",
     "include/cpu_features_wrapper.h",
     "include/cpu_info.h",
-    "include/critical_section_wrapper.h",
     "include/event_wrapper.h",
     "include/field_trial.h",
     "include/file_wrapper.h",
@@ -38,8 +37,6 @@
     "source/aligned_malloc.cc",
     "source/atomic32_win.cc",
     "source/clock.cc",
-    "source/condition_variable_event_win.cc",
-    "source/condition_variable_event_win.h",
     "source/cpu_features.cc",
     "source/cpu_info.cc",
     "source/event.cc",
@@ -55,8 +52,6 @@
     "source/rw_lock_posix.h",
     "source/rw_lock_win.cc",
     "source/rw_lock_win.h",
-    "source/rw_lock_winxp_win.cc",
-    "source/rw_lock_winxp_win.h",
     "source/sleep.cc",
     "source/timestamp_extrapolator.cc",
     "source/trace_impl.cc",
@@ -171,8 +166,6 @@
       "source/aligned_array_unittest.cc",
       "source/aligned_malloc_unittest.cc",
       "source/clock_unittest.cc",
-      "source/condition_variable_unittest.cc",
-      "source/critical_section_unittest.cc",
       "source/event_timer_posix_unittest.cc",
       "source/logging_unittest.cc",
       "source/metrics_default_unittest.cc",
diff --git a/system_wrappers/include/critical_section_wrapper.h b/system_wrappers/include/critical_section_wrapper.h
deleted file mode 100644
index 0858b4f..0000000
--- a/system_wrappers/include/critical_section_wrapper.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_
-#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_
-
-#include "webrtc/base/criticalsection.h"
-#include "webrtc/base/thread_annotations.h"
-#include "webrtc/common_types.h"
-
-namespace webrtc {
-
-class LOCKABLE CriticalSectionWrapper {
- public:
-  // Legacy factory method, being deprecated. Please use the constructor.
-  // TODO(tommi): Remove the CriticalSectionWrapper class and move users over
-  // to using rtc::CriticalSection.
-  static CriticalSectionWrapper* CreateCriticalSection() {
-    return new CriticalSectionWrapper();
-  }
-
-  CriticalSectionWrapper() {}
-  ~CriticalSectionWrapper() {}
-
-  // Tries to grab lock, beginning of a critical section. Will wait for the
-  // lock to become available if the grab failed.
-  void Enter() EXCLUSIVE_LOCK_FUNCTION() { lock_.Enter(); }
-
-  // Returns a grabbed lock, end of critical section.
-  void Leave() UNLOCK_FUNCTION() { lock_.Leave(); }
-
- private:
-  rtc::CriticalSection lock_;
-};
-
-// RAII extension of the critical section. Prevents Enter/Leave mismatches and
-// provides more compact critical section syntax.
-class SCOPED_LOCKABLE CriticalSectionScoped {
- public:
-  explicit CriticalSectionScoped(CriticalSectionWrapper* critsec)
-      EXCLUSIVE_LOCK_FUNCTION(critsec)
-      : ptr_crit_sec_(critsec) {
-    ptr_crit_sec_->Enter();
-  }
-
-  ~CriticalSectionScoped() UNLOCK_FUNCTION() { ptr_crit_sec_->Leave(); }
-
- private:
-  CriticalSectionWrapper* ptr_crit_sec_;
-};
-
-}  // namespace webrtc
-
-#endif  // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_
diff --git a/system_wrappers/source/condition_variable_event_win.cc b/system_wrappers/source/condition_variable_event_win.cc
deleted file mode 100644
index 535cbc5..0000000
--- a/system_wrappers/source/condition_variable_event_win.cc
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
-Source:
-http://www1.cse.wustl.edu/~schmidt/ACE-copying.html
-
-License:
-Copyright and Licensing Information for ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM),
-and CoSMIC(TM)
-
-ACE(TM), TAO(TM), CIAO(TM), DAnCE>(TM), and CoSMIC(TM) (henceforth referred to
-as "DOC software") are copyrighted by Douglas C. Schmidt and his research
-group at Washington University, University of California, Irvine, and
-Vanderbilt University, Copyright (c) 1993-2009, all rights reserved. Since DOC
-software is open-source, freely available software, you are free to use,
-modify, copy, and distribute--perpetually and irrevocably--the DOC software
-source code and object code produced from the source, as well as copy and
-distribute modified versions of this software. You must, however, include this
-copyright statement along with any code built using DOC software that you
-release. No copyright statement needs to be provided if you just ship binary
-executables of your software products.
-You can use DOC software in commercial and/or binary software releases and are
-under no obligation to redistribute any of your source code that is built
-using DOC software. Note, however, that you may not misappropriate the DOC
-software code, such as copyrighting it yourself or claiming authorship of the
-DOC software code, in a way that will prevent DOC software from being
-distributed freely using an open-source development model. You needn't inform
-anyone that you're using DOC software in your software, though we encourage
-you to let us know so we can promote your project in the DOC software success
-stories.
-
-The ACE, TAO, CIAO, DAnCE, and CoSMIC web sites are maintained by the DOC
-Group at the Institute for Software Integrated Systems (ISIS) and the Center
-for Distributed Object Computing of Washington University, St. Louis for the
-development of open-source software as part of the open-source software
-community. Submissions are provided by the submitter ``as is'' with no
-warranties whatsoever, including any warranty of merchantability,
-noninfringement of third party intellectual property, or fitness for any
-particular purpose. In no event shall the submitter be liable for any direct,
-indirect, special, exemplary, punitive, or consequential damages, including
-without limitation, lost profits, even if advised of the possibility of such
-damages. Likewise, DOC software is provided as is with no warranties of any
-kind, including the warranties of design, merchantability, and fitness for a
-particular purpose, noninfringement, or arising from a course of dealing,
-usage or trade practice. Washington University, UC Irvine, Vanderbilt
-University, their employees, and students shall have no liability with respect
-to the infringement of copyrights, trade secrets or any patents by DOC
-software or any part thereof. Moreover, in no event will Washington
-University, UC Irvine, or Vanderbilt University, their employees, or students
-be liable for any lost revenue or profits or other special, indirect and
-consequential damages.
-
-DOC software is provided with no support and without any obligation on the
-part of Washington University, UC Irvine, Vanderbilt University, their
-employees, or students to assist in its use, correction, modification, or
-enhancement. A number of companies around the world provide commercial support
-for DOC software, however. DOC software is Y2K-compliant, as long as the
-underlying OS platform is Y2K-compliant. Likewise, DOC software is compliant
-with the new US daylight savings rule passed by Congress as "The Energy Policy
-Act of 2005," which established new daylight savings times (DST) rules for the
-United States that expand DST as of March 2007. Since DOC software obtains
-time/date and calendaring information from operating systems users will not be
-affected by the new DST rules as long as they upgrade their operating systems
-accordingly.
-
-The names ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM), CoSMIC(TM), Washington
-University, UC Irvine, and Vanderbilt University, may not be used to endorse
-or promote products or services derived from this source without express
-written permission from Washington University, UC Irvine, or Vanderbilt
-University. This license grants no permission to call products or services
-derived from this source ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM), or CoSMIC(TM),
-nor does it grant permission for the name Washington University, UC Irvine, or
-Vanderbilt University to appear in their names.
-*/
-
-/*
- *  This source code contain modifications to the original source code
- *  which can be found here:
- *  http://www.cs.wustl.edu/~schmidt/win32-cv-1.html (section 3.2).
- *  Modifications:
- *  1) Dynamic detection of native support for condition variables.
- *  2) Use of WebRTC defined types and classes. Renaming of some functions.
- *  3) Introduction of a second event for wake all functionality. This prevents
- *     a thread from spinning on the same condition variable, preventing other
- *     threads from waking up.
- */
-
-#include "webrtc/system_wrappers/source/condition_variable_event_win.h"
-
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-
-namespace webrtc {
-
-ConditionVariableEventWin::ConditionVariableEventWin() : eventID_(WAKEALL_0) {
-  memset(&num_waiters_[0], 0, sizeof(num_waiters_));
-
-  InitializeCriticalSection(&num_waiters_crit_sect_);
-
-  events_[WAKEALL_0] = CreateEvent(NULL,  // no security attributes
-                                   TRUE,  // manual-reset, sticky event
-                                   FALSE,  // initial state non-signaled
-                                   NULL);  // no name for event
-
-  events_[WAKEALL_1] = CreateEvent(NULL,  // no security attributes
-                                   TRUE,  // manual-reset, sticky event
-                                   FALSE,  // initial state non-signaled
-                                   NULL);  // no name for event
-
-  events_[WAKE] = CreateEvent(NULL,  // no security attributes
-                              FALSE,  // auto-reset, sticky event
-                              FALSE,  // initial state non-signaled
-                              NULL);  // no name for event
-}
-
-ConditionVariableEventWin::~ConditionVariableEventWin() {
-  CloseHandle(events_[WAKE]);
-  CloseHandle(events_[WAKEALL_1]);
-  CloseHandle(events_[WAKEALL_0]);
-
-  DeleteCriticalSection(&num_waiters_crit_sect_);
-}
-
-void ConditionVariableEventWin::SleepCS(CRITICAL_SECTION* crit_sect) {
-  SleepCS(crit_sect, INFINITE);
-}
-
-bool ConditionVariableEventWin::SleepCS(CRITICAL_SECTION* crit_sect,
-                                        unsigned long max_time_in_ms) {
-  EnterCriticalSection(&num_waiters_crit_sect_);
-
-  // Get the eventID for the event that will be triggered by next
-  // WakeAll() call and start waiting for it.
-  const EventWakeUpType eventID =
-      (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0;
-
-  ++(num_waiters_[eventID]);
-  LeaveCriticalSection(&num_waiters_crit_sect_);
-
-  LeaveCriticalSection(crit_sect);
-  HANDLE events[2];
-  events[0] = events_[WAKE];
-  events[1] = events_[eventID];
-  const DWORD result = WaitForMultipleObjects(2,  // Wait on 2 events.
-                                              events,
-                                              FALSE,  // Wait for either.
-                                              max_time_in_ms);
-
-  const bool ret_val = (result != WAIT_TIMEOUT);
-
-  EnterCriticalSection(&num_waiters_crit_sect_);
-  --(num_waiters_[eventID]);
-
-  // Last waiter should only be true for WakeAll(). WakeAll() correspond
-  // to position 1 in events[] -> (result == WAIT_OBJECT_0 + 1)
-  const bool last_waiter = (result == WAIT_OBJECT_0 + 1) &&
-      (num_waiters_[eventID] == 0);
-  LeaveCriticalSection(&num_waiters_crit_sect_);
-
-  if (last_waiter) {
-    // Reset/unset the WakeAll() event since all threads have been
-    // released.
-    ResetEvent(events_[eventID]);
-  }
-
-  EnterCriticalSection(crit_sect);
-  return ret_val;
-}
-
-void ConditionVariableEventWin::Wake() {
-  EnterCriticalSection(&num_waiters_crit_sect_);
-  const bool have_waiters = (num_waiters_[WAKEALL_0] > 0) ||
-      (num_waiters_[WAKEALL_1] > 0);
-  LeaveCriticalSection(&num_waiters_crit_sect_);
-
-  if (have_waiters) {
-    SetEvent(events_[WAKE]);
-  }
-}
-
-void ConditionVariableEventWin::WakeAll() {
-  EnterCriticalSection(&num_waiters_crit_sect_);
-
-  // Update current WakeAll() event
-  eventID_ = (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0;
-
-  // Trigger current event
-  const EventWakeUpType eventID = eventID_;
-  const bool have_waiters = num_waiters_[eventID] > 0;
-  LeaveCriticalSection(&num_waiters_crit_sect_);
-
-  if (have_waiters) {
-    SetEvent(events_[eventID]);
-  }
-}
-
-}  // namespace webrtc
diff --git a/system_wrappers/source/condition_variable_event_win.h b/system_wrappers/source/condition_variable_event_win.h
deleted file mode 100644
index 8099ad5..0000000
--- a/system_wrappers/source/condition_variable_event_win.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_EVENT_WIN_H_
-#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_EVENT_WIN_H_
-
-#include <windows.h>
-
-namespace webrtc {
-
-class ConditionVariableEventWin {
- public:
-  ConditionVariableEventWin();
-  ~ConditionVariableEventWin();
-
-  void SleepCS(CRITICAL_SECTION* crit_sect);
-  bool SleepCS(CRITICAL_SECTION* crit_sect, unsigned long max_time_inMS);
-  void Wake();
-  void WakeAll();
-
- private:
-  enum EventWakeUpType {
-    WAKEALL_0   = 0,
-    WAKEALL_1   = 1,
-    WAKE        = 2,
-    EVENT_COUNT = 3
-  };
-
-  unsigned int     num_waiters_[2];
-  EventWakeUpType  eventID_;
-  CRITICAL_SECTION num_waiters_crit_sect_;
-  HANDLE           events_[EVENT_COUNT];
-};
-
-}  // namespace webrtc
-
-#endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_EVENT_WIN_H_
diff --git a/system_wrappers/source/condition_variable_unittest.cc b/system_wrappers/source/condition_variable_unittest.cc
deleted file mode 100644
index 90779ff..0000000
--- a/system_wrappers/source/condition_variable_unittest.cc
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-// TODO(tommi): Remove completely.  As is there is still some code for Windows
-// that relies on ConditionVariableEventWin, but code has been removed on other
-// platforms.
-#if defined(WEBRTC_WIN)
-
-#include "webrtc/base/platform_thread.h"
-#include "webrtc/base/timeutils.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/source/condition_variable_event_win.h"
-#include "webrtc/test/gtest.h"
-
-namespace webrtc {
-
-namespace {
-
-const int kLongWaitMs = 100 * 1000; // A long time in testing terms
-const int kShortWaitMs = 2 * 1000; // Long enough for process switches to happen
-const int kVeryShortWaitMs = 20; // Used when we want a timeout
-
-// A Baton is one possible control structure one can build using
-// conditional variables.
-// A Baton is always held by one and only one active thread - unlike
-// a lock, it can never be free.
-// One can pass it or grab it - both calls have timeouts.
-// Note - a production tool would guard against passing it without
-// grabbing it first. This one is for testing, so it doesn't.
-class Baton {
- public:
-  Baton()
-    : being_passed_(false),
-      pass_count_(0) {
-    InitializeCriticalSection(&crit_sect_);
-  }
-
-  ~Baton() {
-    DeleteCriticalSection(&crit_sect_);
-  }
-
-  // Pass the baton. Returns false if baton is not picked up in |max_msecs|.
-  // Only one process can pass at the same time; this property is
-  // ensured by the |giver_sect_| lock.
-  bool Pass(uint32_t max_msecs) {
-    CriticalSectionScoped cs_giver(&giver_sect_);
-    EnterCriticalSection(&crit_sect_);
-    SignalBatonAvailable();
-    const bool result = TakeBatonIfStillFree(max_msecs);
-    if (result) {
-      ++pass_count_;
-    }
-    LeaveCriticalSection(&crit_sect_);
-    return result;
-  }
-
-  // Grab the baton. Returns false if baton is not passed.
-  bool Grab(uint32_t max_msecs) {
-    EnterCriticalSection(&crit_sect_);
-    bool ret = WaitUntilBatonOffered(max_msecs);
-    LeaveCriticalSection(&crit_sect_);
-    return ret;
-  }
-
-  int PassCount() {
-    // We don't allow polling PassCount() during a Pass()-call since there is
-    // no guarantee that |pass_count_| is incremented until the Pass()-call
-    // finishes. I.e. the Grab()-call may finish before |pass_count_| has been
-    // incremented.
-    // Thus, this function waits on giver_sect_.
-    CriticalSectionScoped cs(&giver_sect_);
-    return pass_count_;
-  }
-
- private:
-  // Wait/Signal forms a classical semaphore on |being_passed_|.
-  // These functions must be called with crit_sect_ held.
-  bool WaitUntilBatonOffered(int timeout_ms) {
-    while (!being_passed_) {
-      if (!cond_var_.SleepCS(&crit_sect_, timeout_ms)) {
-        return false;
-      }
-    }
-    being_passed_ = false;
-    cond_var_.Wake();
-    return true;
-  }
-
-  void SignalBatonAvailable() {
-    assert(!being_passed_);
-    being_passed_ = true;
-    cond_var_.Wake();
-  }
-
-  // Timeout extension: Wait for a limited time for someone else to
-  // take it, and take it if it's not taken.
-  // Returns true if resource is taken by someone else, false
-  // if it is taken back by the caller.
-  // This function must be called with both |giver_sect_| and
-  // |crit_sect_| held.
-  bool TakeBatonIfStillFree(int timeout_ms) {
-    bool not_timeout = true;
-    while (being_passed_ && not_timeout) {
-      not_timeout = cond_var_.SleepCS(&crit_sect_, timeout_ms);
-      // If we're woken up while variable is still held, we may have
-      // gotten a wakeup destined for a grabber thread.
-      // This situation is not treated specially here.
-    }
-    if (!being_passed_)
-      return true;
-    assert(!not_timeout);
-    being_passed_ = false;
-    return false;
-  }
-
-  // Lock that ensures that there is only one thread in the active
-  // part of Pass() at a time.
-  // |giver_sect_| must always be acquired before |cond_var_|.
-  CriticalSectionWrapper giver_sect_;
-  // Lock that protects |being_passed_|.
-  CRITICAL_SECTION crit_sect_;
-  ConditionVariableEventWin cond_var_;
-  bool being_passed_;
-  // Statistics information: Number of successfull passes.
-  int pass_count_;
-};
-
-// Function that waits on a Baton, and passes it right back.
-// We expect these calls never to time out.
-bool WaitingRunFunction(void* obj) {
-  Baton* the_baton = static_cast<Baton*> (obj);
-  EXPECT_TRUE(the_baton->Grab(kLongWaitMs));
-  EXPECT_TRUE(the_baton->Pass(kLongWaitMs));
-  return true;
-}
-
-class CondVarTest : public ::testing::Test {
- public:
-  CondVarTest() : thread_(&WaitingRunFunction, &baton_, "CondVarTest") {}
-
-  virtual void SetUp() {
-    thread_.Start();
-  }
-
-  virtual void TearDown() {
-    // We have to wake the thread in order to make it obey the stop order.
-    // But we don't know if the thread has completed the run function, so
-    // we don't know if it will exit before or after the Pass.
-    // Thus, we need to pin it down inside its Run function (between Grab
-    // and Pass).
-    ASSERT_TRUE(baton_.Pass(kShortWaitMs));
-    ASSERT_TRUE(baton_.Grab(kShortWaitMs));
-    thread_.Stop();
-  }
-
- protected:
-  Baton baton_;
-
- private:
-  rtc::PlatformThread thread_;
-};
-
-// The SetUp and TearDown functions use condition variables.
-// This test verifies those pieces in isolation.
-// Disabled due to flakiness.  See bug 4262 for details.
-TEST_F(CondVarTest, DISABLED_InitFunctionsWork) {
-  // All relevant asserts are in the SetUp and TearDown functions.
-}
-
-// This test verifies that one can use the baton multiple times.
-TEST_F(CondVarTest, DISABLED_PassBatonMultipleTimes) {
-  const int kNumberOfRounds = 2;
-  for (int i = 0; i < kNumberOfRounds; ++i) {
-    ASSERT_TRUE(baton_.Pass(kShortWaitMs));
-    ASSERT_TRUE(baton_.Grab(kShortWaitMs));
-  }
-  EXPECT_EQ(2 * kNumberOfRounds, baton_.PassCount());
-}
-
-TEST(CondVarWaitTest, WaitingWaits) {
-  CRITICAL_SECTION crit_sect;
-  InitializeCriticalSection(&crit_sect);
-  ConditionVariableEventWin cond_var;
-  EnterCriticalSection(&crit_sect);
-  int64_t start_ms = rtc::TimeMillis();
-  EXPECT_FALSE(cond_var.SleepCS(&crit_sect, kVeryShortWaitMs));
-  int64_t end_ms = rtc::TimeMillis();
-  EXPECT_LE(start_ms + kVeryShortWaitMs, end_ms)
-      << "actual elapsed:" << end_ms - start_ms;
-  LeaveCriticalSection(&crit_sect);
-  DeleteCriticalSection(&crit_sect);
-}
-
-}  // anonymous namespace
-
-}  // namespace webrtc
-
-#endif  // defined(WEBRTC_WIN)
diff --git a/system_wrappers/source/critical_section_unittest.cc b/system_wrappers/source/critical_section_unittest.cc
deleted file mode 100644
index 623f2fc..0000000
--- a/system_wrappers/source/critical_section_unittest.cc
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-
-#include "webrtc/base/platform_thread.h"
-#include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/test/gtest.h"
-
-namespace webrtc {
-
-namespace {
-
-// Cause a process switch. Needed to avoid depending on
-// busy-wait in tests.
-static void SwitchProcess() {
-  // Note - sched_yield has been tried as process switch. This does
-  // not cause a process switch enough of the time for reliability.
-  SleepMs(1);
-}
-
-class ProtectedCount {
-public:
-  explicit ProtectedCount(CriticalSectionWrapper* crit_sect)
-    : crit_sect_(crit_sect),
-      count_(0) {
-  }
-
-  void Increment() {
-    CriticalSectionScoped cs(crit_sect_);
-    ++count_;
-  }
-
-  int Count() const {
-    CriticalSectionScoped cs(crit_sect_);
-    return count_;
-  }
-
-private:
-  CriticalSectionWrapper* crit_sect_;
-  int count_;
-};
-
-class CritSectTest : public ::testing::Test {
-public:
-  CritSectTest() {}
-
-  // Waits a number of cycles for the count to reach a given value.
-  // Returns true if the target is reached or passed.
-  bool WaitForCount(int target, ProtectedCount* count) {
-    int loop_counter = 0;
-    // On Posix, this SwitchProcess() needs to be in a loop to make the
-    // test both fast and non-flaky.
-    // With 1 us wait as the switch, up to 7 rounds have been observed.
-    while (count->Count() < target && loop_counter < 100 * target) {
-      ++loop_counter;
-      SwitchProcess();
-    }
-    return (count->Count() >= target);
-  }
-};
-
-void LockUnlockThenStopRunFunction(void* obj) {
-  ProtectedCount* the_count = static_cast<ProtectedCount*>(obj);
-  the_count->Increment();
-}
-
-TEST_F(CritSectTest, ThreadWakesOnce) NO_THREAD_SAFETY_ANALYSIS {
-  CriticalSectionWrapper* crit_sect =
-      CriticalSectionWrapper::CreateCriticalSection();
-  ProtectedCount count(crit_sect);
-  rtc::PlatformThread thread(
-      &LockUnlockThenStopRunFunction, &count, "ThreadWakesOnce");
-  crit_sect->Enter();
-  thread.Start();
-  SwitchProcess();
-  // The critical section is of reentrant mode, so this should not release
-  // the lock, even though count.Count() locks and unlocks the critical section
-  // again.
-  // Thus, the thread should not be able to increment the count
-  ASSERT_EQ(0, count.Count());
-  crit_sect->Leave();  // This frees the thread to act.
-  EXPECT_TRUE(WaitForCount(1, &count));
-  thread.Stop();
-  delete crit_sect;
-}
-
-bool LockUnlockRunFunction(void* obj) {
-  ProtectedCount* the_count = static_cast<ProtectedCount*>(obj);
-  the_count->Increment();
-  SwitchProcess();
-  return true;
-}
-
-TEST_F(CritSectTest, ThreadWakesTwice) NO_THREAD_SAFETY_ANALYSIS {
-  CriticalSectionWrapper* crit_sect =
-      CriticalSectionWrapper::CreateCriticalSection();
-  ProtectedCount count(crit_sect);
-  rtc::PlatformThread thread(
-      &LockUnlockRunFunction, &count, "ThreadWakesTwice");
-  crit_sect->Enter();  // Make sure counter stays 0 until we wait for it.
-  thread.Start();
-  crit_sect->Leave();
-
-  // The thread is capable of grabbing the lock multiple times,
-  // incrementing counter once each time.
-  // It's possible for the count to be incremented by more than 2.
-  EXPECT_TRUE(WaitForCount(2, &count));
-  EXPECT_LE(2, count.Count());
-
-  // The thread does not increment while lock is held.
-  crit_sect->Enter();
-  int count_before = count.Count();
-  for (int i = 0; i < 10; i++) {
-    SwitchProcess();
-  }
-  EXPECT_EQ(count_before, count.Count());
-  crit_sect->Leave();
-
-  SwitchProcess();
-  EXPECT_TRUE(WaitForCount(count_before + 1, &count));
-  thread.Stop();
-  delete crit_sect;
-}
-
-}  // anonymous namespace
-
-}  // namespace webrtc
diff --git a/system_wrappers/source/rw_lock.cc b/system_wrappers/source/rw_lock.cc
index 7c77123..ff53e8d 100644
--- a/system_wrappers/source/rw_lock.cc
+++ b/system_wrappers/source/rw_lock.cc
@@ -14,7 +14,6 @@
 
 #if defined(_WIN32)
 #include "webrtc/system_wrappers/source/rw_lock_win.h"
-#include "webrtc/system_wrappers/source/rw_lock_winxp_win.h"
 #else
 #include "webrtc/system_wrappers/source/rw_lock_posix.h"
 #endif
@@ -23,12 +22,7 @@
 
 RWLockWrapper* RWLockWrapper::CreateRWLock() {
 #ifdef _WIN32
-  // Native implementation is faster, so use that if available.
-  RWLockWrapper* lock = RWLockWin::Create();
-  if (lock) {
-    return lock;
-  }
-  return new RWLockWinXP();
+  return RWLockWin::Create();
 #else
   return RWLockPosix::Create();
 #endif
diff --git a/system_wrappers/source/rw_lock_winxp_win.cc b/system_wrappers/source/rw_lock_winxp_win.cc
deleted file mode 100644
index 9393c9f..0000000
--- a/system_wrappers/source/rw_lock_winxp_win.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/system_wrappers/source/rw_lock_winxp_win.h"
-
-namespace webrtc {
-namespace {
-class ScopedLock {
- public:
-  ScopedLock(CRITICAL_SECTION* lock) : lock_(lock) {
-    EnterCriticalSection(lock_);
-  }
-  ~ScopedLock() {
-    LeaveCriticalSection(lock_);
-  }
- private:
-  CRITICAL_SECTION* const lock_;
-};
-}
-
-RWLockWinXP::RWLockWinXP() {
-  InitializeCriticalSection(&critical_section_);
-}
-
-RWLockWinXP::~RWLockWinXP() {
-  DeleteCriticalSection(&critical_section_);
-}
-
-void RWLockWinXP::AcquireLockExclusive() {
-  ScopedLock cs(&critical_section_);
-  if (writer_active_ || readers_active_ > 0) {
-    ++writers_waiting_;
-    while (writer_active_ || readers_active_ > 0) {
-      write_condition_.SleepCS(&critical_section_);
-    }
-    --writers_waiting_;
-  }
-  writer_active_ = true;
-}
-
-void RWLockWinXP::ReleaseLockExclusive() {
-  ScopedLock cs(&critical_section_);
-  writer_active_ = false;
-  if (writers_waiting_ > 0) {
-    write_condition_.Wake();
-  } else if (readers_waiting_ > 0) {
-    read_condition_.WakeAll();
-  }
-}
-
-void RWLockWinXP::AcquireLockShared() {
-  ScopedLock cs(&critical_section_);
-  if (writer_active_ || writers_waiting_ > 0) {
-    ++readers_waiting_;
-
-    while (writer_active_ || writers_waiting_ > 0) {
-      read_condition_.SleepCS(&critical_section_);
-    }
-    --readers_waiting_;
-  }
-  ++readers_active_;
-}
-
-void RWLockWinXP::ReleaseLockShared() {
-  ScopedLock cs(&critical_section_);
-  --readers_active_;
-  if (readers_active_ == 0 && writers_waiting_ > 0) {
-    write_condition_.Wake();
-  }
-}
-
-}  // namespace webrtc
diff --git a/system_wrappers/source/rw_lock_winxp_win.h b/system_wrappers/source/rw_lock_winxp_win.h
deleted file mode 100644
index 5c88448..0000000
--- a/system_wrappers/source/rw_lock_winxp_win.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WINXP_WIN_H_
-#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WINXP_WIN_H_
-
-#include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
-#include "webrtc/system_wrappers/source/condition_variable_event_win.h"
-#include "webrtc/typedefs.h"
-
-namespace webrtc {
-
-class RWLockWinXP : public RWLockWrapper {
- public:
-  RWLockWinXP();
-  ~RWLockWinXP() override;
-
-  void AcquireLockExclusive() override;
-  void ReleaseLockExclusive() override;
-
-  void AcquireLockShared() override;
-  void ReleaseLockShared() override;
-
- private:
-  CRITICAL_SECTION critical_section_;
-  ConditionVariableEventWin read_condition_;
-  ConditionVariableEventWin write_condition_;
-
-  int readers_active_ = 0;
-  bool writer_active_ = false;
-  int readers_waiting_ = 0;
-  int writers_waiting_ = 0;
-};
-
-}  // namespace webrtc
-
-#endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_RW_LOCK_WINXP_WIN_H_