small improvement for the mutexes

This commit is contained in:
Volker Fischer 2014-02-16 20:04:22 +00:00
parent 9e4dbd861a
commit e004ed6964

View file

@ -154,8 +154,6 @@ void CChannel::SetAudioStreamProperties ( const EAudComprType eNewAudComprType,
CNetworkTransportProps NetworkTransportProps; CNetworkTransportProps NetworkTransportProps;
Mutex.lock(); Mutex.lock();
MutexSocketBuf.lock();
MutexConvBuf.lock();
{ {
// store new values // store new values
eAudioCompressionType = eNewAudComprType; eAudioCompressionType = eNewAudComprType;
@ -163,18 +161,24 @@ void CChannel::SetAudioStreamProperties ( const EAudComprType eNewAudComprType,
iNetwFrameSize = iNewNetwFrameSize; iNetwFrameSize = iNewNetwFrameSize;
iNetwFrameSizeFact = iNewNetwFrameSizeFact; iNetwFrameSizeFact = iNewNetwFrameSizeFact;
MutexSocketBuf.lock();
{
// init socket buffer // init socket buffer
SockBuf.Init ( iNetwFrameSize, iCurSockBufNumFrames ); SockBuf.Init ( iNetwFrameSize, iCurSockBufNumFrames );
}
MutexSocketBuf.unlock();
MutexConvBuf.lock();
{
// init conversion buffer // init conversion buffer
ConvBuf.Init ( iNetwFrameSize * iNetwFrameSizeFact ); ConvBuf.Init ( iNetwFrameSize * iNetwFrameSizeFact );
}
MutexConvBuf.unlock();
// fill network transport properties struct // fill network transport properties struct
NetworkTransportProps = NetworkTransportProps =
GetNetworkTransportPropsFromCurrentSettings(); GetNetworkTransportPropsFromCurrentSettings();
} }
MutexConvBuf.unlock();
MutexSocketBuf.unlock();
Mutex.unlock(); Mutex.unlock();
// tell the server about the new network settings // tell the server about the new network settings
@ -377,8 +381,6 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor
if ( bIsServer ) if ( bIsServer )
{ {
Mutex.lock(); Mutex.lock();
MutexSocketBuf.lock();
MutexConvBuf.lock();
{ {
// store received parameters // store received parameters
eAudioCompressionType = NetworkTransportProps.eAudioCodingType; eAudioCompressionType = NetworkTransportProps.eAudioCodingType;
@ -387,15 +389,21 @@ void CChannel::OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTranspor
iNetwFrameSize = iNetwFrameSize =
NetworkTransportProps.iBaseNetworkPacketSize; NetworkTransportProps.iBaseNetworkPacketSize;
MutexSocketBuf.lock();
{
// update socket buffer (the network block size is a multiple of the // update socket buffer (the network block size is a multiple of the
// minimum network frame size // minimum network frame size
SockBuf.Init ( iNetwFrameSize, iCurSockBufNumFrames ); SockBuf.Init ( iNetwFrameSize, iCurSockBufNumFrames );
}
MutexSocketBuf.unlock();
MutexConvBuf.lock();
{
// init conversion buffer // init conversion buffer
ConvBuf.Init ( iNetwFrameSize * iNetwFrameSizeFact ); ConvBuf.Init ( iNetwFrameSize * iNetwFrameSizeFact );
} }
MutexConvBuf.unlock(); MutexConvBuf.unlock();
MutexSocketBuf.unlock(); }
Mutex.unlock(); Mutex.unlock();
// if old CELT codec is used, inform the client that the new OPUS codec // if old CELT codec is used, inform the client that the new OPUS codec