From 6eb0ca2e757814ec1b5328a77c9114fbddc2e834 Mon Sep 17 00:00:00 2001 From: "xians@webrtc.org" Date: Thu, 23 Feb 2012 10:39:53 +0000 Subject: [PATCH] Two problems are fixed: #1, avoid leaving the lock without entering the lock. #2, race problems in variables like _playError, _recError, _recWarning, _playWarning. Review URL: https://webrtc-codereview.appspot.com/400006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1751 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../source/linux/audio_device_pulse_linux.cc | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/modules/audio_device/main/source/linux/audio_device_pulse_linux.cc b/src/modules/audio_device/main/source/linux/audio_device_pulse_linux.cc index 811280f2f8..337410a13a 100644 --- a/src/modules/audio_device/main/source/linux/audio_device_pulse_linux.cc +++ b/src/modules/audio_device/main/source/linux/audio_device_pulse_linux.cc @@ -288,7 +288,7 @@ WebRtc_Word32 AudioDeviceLinuxPulse::Terminate() return 0; } - _critSect.Enter(); + Lock(); _mixerManager.Close(); @@ -297,11 +297,10 @@ WebRtc_Word32 AudioDeviceLinuxPulse::Terminate() { ThreadWrapper* tmpThread = _ptrThreadRec; _ptrThreadRec = NULL; - _critSect.Leave(); + UnLock(); tmpThread->SetNotAlive(); _timeEventRec.Set(); - if (tmpThread->Stop()) { delete tmpThread; @@ -310,6 +309,8 @@ WebRtc_Word32 AudioDeviceLinuxPulse::Terminate() WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, " failed to close down the rec audio thread"); } + // Lock again since we need to protect _ptrThreadPlay. + Lock(); } // PLAYOUT @@ -321,7 +322,6 @@ WebRtc_Word32 AudioDeviceLinuxPulse::Terminate() tmpThread->SetNotAlive(); _timeEventPlay.Set(); - if (tmpThread->Stop()) { delete tmpThread; @@ -330,6 +330,8 @@ WebRtc_Word32 AudioDeviceLinuxPulse::Terminate() WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, " failed to close down the play audio thread"); } + } else { + UnLock(); } // Terminate PulseAudio @@ -1750,42 +1752,50 @@ WebRtc_Word32 AudioDeviceLinuxPulse::CPULoad(WebRtc_UWord16& /*load*/) const bool AudioDeviceLinuxPulse::PlayoutWarning() const { - return (_playWarning > 0); + CriticalSectionScoped lock(_critSect); + return (_playWarning > 0); } bool AudioDeviceLinuxPulse::PlayoutError() const { - return (_playError > 0); + CriticalSectionScoped lock(_critSect); + return (_playError > 0); } bool AudioDeviceLinuxPulse::RecordingWarning() const { - return (_recWarning > 0); + CriticalSectionScoped lock(_critSect); + return (_recWarning > 0); } bool AudioDeviceLinuxPulse::RecordingError() const { - return (_recError > 0); + CriticalSectionScoped lock(_critSect); + return (_recError > 0); } void AudioDeviceLinuxPulse::ClearPlayoutWarning() { - _playWarning = 0; + CriticalSectionScoped lock(_critSect); + _playWarning = 0; } void AudioDeviceLinuxPulse::ClearPlayoutError() { - _playError = 0; + CriticalSectionScoped lock(_critSect); + _playError = 0; } void AudioDeviceLinuxPulse::ClearRecordingWarning() { - _recWarning = 0; + CriticalSectionScoped lock(_critSect); + _recWarning = 0; } void AudioDeviceLinuxPulse::ClearRecordingError() { - _recError = 0; + CriticalSectionScoped lock(_critSect); + _recError = 0; } // ============================================================================