From 83661f534e56dfaf3542963b54b1e208f223a377 Mon Sep 17 00:00:00 2001 From: "xians@webrtc.org" Date: Fri, 25 Nov 2011 10:58:15 +0000 Subject: [PATCH] fixing the racing conditions git-svn-id: http://webrtc.googlecode.com/svn/trunk@1025 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/voice_engine/main/source/channel.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/voice_engine/main/source/channel.cc b/src/voice_engine/main/source/channel.cc index 3b9e63637..5b1a0df2f 100644 --- a/src/voice_engine/main/source/channel.cc +++ b/src/voice_engine/main/source/channel.cc @@ -250,13 +250,16 @@ Channel::SendRTCPPacket(int channel, const void *data, int len) WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::SendRTCPPacket(channel=%d, len=%d)", channel, len); - if (_transportPtr == NULL) { - WEBRTC_TRACE(kTraceError, kTraceVoice, - VoEId(_instanceId,_channelId), - "Channel::SendRTCPPacket() failed to send RTCP packet" - " due to invalid transport object"); - return -1; + CriticalSectionScoped cs(_callbackCritSect); + if (_transportPtr == NULL) + { + WEBRTC_TRACE(kTraceError, kTraceVoice, + VoEId(_instanceId,_channelId), + "Channel::SendRTCPPacket() failed to send RTCP packet" + " due to invalid transport object"); + return -1; + } } WebRtc_UWord8* bufferToSendPtr = (WebRtc_UWord8*)data; @@ -1532,7 +1535,12 @@ Channel::Init() #ifndef WEBRTC_EXTERNAL_TRANSPORT // Ensure that the WebRtcSocketTransport implementation is used as // Transport on the sending side - _transportPtr = &_socketTransportModule; + { + // A lock is needed here since users can call + // RegisterExternalTransport() at the same time. + CriticalSectionScoped cs(_callbackCritSect); + _transportPtr = &_socketTransportModule; + } #endif // Initialize the far end AP module @@ -2803,6 +2811,8 @@ Channel::DeRegisterExternalTransport() WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::DeRegisterExternalTransport()"); + CriticalSectionScoped cs(_callbackCritSect); + if (!_transportPtr) { _engineStatisticsPtr->SetLastError(