diff --git a/webrtc/base/race_checker.cc b/webrtc/base/race_checker.cc index 9f0946ca76..92bdd7bdfd 100644 --- a/webrtc/base/race_checker.cc +++ b/webrtc/base/race_checker.cc @@ -14,6 +14,14 @@ namespace rtc { RaceChecker::RaceChecker() {} +// Note that the implementation here is in itself racy, but we pretend it does +// not matter because we want this useful in release builds without having to +// pay the cost of using atomics. A race hitting the race checker is likely to +// cause access_count_ to diverge from zero and therefore cause the ThreadRef +// comparison to fail, signaling a race, although it may not be in the exact +// spot where a race *first* appeared in the code we're trying to protect. There +// is also a chance that an actual race is missed, however the probability of +// that has been considered small enough to be an acceptable trade off. bool RaceChecker::Acquire() const { const PlatformThreadRef current_thread = CurrentThreadRef(); // Set new accessing thread if this is a new use. diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index e066f309a7..358c142a1b 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -26,6 +26,7 @@ #include "webrtc/base/constructormagic.h" #include "webrtc/base/helpers.h" #include "webrtc/base/logging.h" +#include "webrtc/base/race_checker.h" #include "webrtc/base/stringencode.h" #include "webrtc/base/stringutils.h" #include "webrtc/base/trace_event.h" @@ -1155,7 +1156,6 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: // RTC_DCHECK(voe_audio_transport); RTC_DCHECK(call); - audio_capture_thread_checker_.DetachFromThread(); config_.rtp.ssrc = ssrc; config_.rtp.c_name = c_name; config_.voe_channel_id = ch; @@ -1270,7 +1270,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream int sample_rate, size_t number_of_channels, size_t number_of_frames) override { - RTC_DCHECK(audio_capture_thread_checker_.CalledOnValidThread()); + RTC_CHECK_RUNS_SERIALIZED(&audio_capture_race_checker_); RTC_DCHECK(voe_audio_transport_); voe_audio_transport_->PushCaptureData(config_.voe_channel_id, audio_data, bits_per_sample, sample_rate, @@ -1317,7 +1317,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream } rtc::ThreadChecker worker_thread_checker_; - rtc::ThreadChecker audio_capture_thread_checker_; + rtc::RaceChecker audio_capture_race_checker_; webrtc::AudioTransport* const voe_audio_transport_ = nullptr; webrtc::Call* call_ = nullptr; webrtc::AudioSendStream::Config config_;