use mutexlocker class for nicer code
This commit is contained in:
parent
7445505c12
commit
d2dc9f6834
1 changed files with 75 additions and 100 deletions
|
@ -611,6 +611,8 @@ CChannel::CChannel() : sName ( "" ),
|
|||
|
||||
void CChannel::SetEnable ( const bool bNEnStat )
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
// set internal parameter
|
||||
bIsEnabled = bNEnStat;
|
||||
|
||||
|
@ -624,8 +626,8 @@ void CChannel::SetEnable ( const bool bNEnStat )
|
|||
void CChannel::SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
|
||||
const CAudioCompression::EAudComprType eNewAudComprType )
|
||||
{
|
||||
Mutex.lock();
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
// store new value
|
||||
iCurNetwInBlSiFact = iNewBlockSizeFactor;
|
||||
|
||||
|
@ -640,13 +642,11 @@ void CChannel::SetNetwInBlSiFactAndCompr ( const int iNewBlockSizeFactor,
|
|||
// socket buffer must be adjusted
|
||||
SetSockBufSizeIntern ( GetSockBufSize() );
|
||||
}
|
||||
Mutex.unlock();
|
||||
}
|
||||
|
||||
void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
|
||||
{
|
||||
Mutex.lock();
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
// store new value
|
||||
iCurNetwOutBlSiFact = iNewNetwBlSiFactOut;
|
||||
|
||||
|
@ -657,8 +657,6 @@ void CChannel::SetNetwBufSizeFactOut ( const int iNewNetwBlSiFactOut )
|
|||
// init conversion buffer
|
||||
ConvBuf.Init ( iNewNetwBlSiFactOut * MIN_BLOCK_SIZE_SAMPLES );
|
||||
}
|
||||
Mutex.unlock();
|
||||
}
|
||||
|
||||
void CChannel::SetAudioCompressionOut ( const CAudioCompression::EAudComprType eNewAudComprTypeOut )
|
||||
{
|
||||
|
@ -673,13 +671,10 @@ void CChannel::SetAudioCompressionOut ( const CAudioCompression::EAudComprType e
|
|||
|
||||
void CChannel::SetSockBufSize ( const int iNumBlocks )
|
||||
{
|
||||
// this opperation must be done with mutex
|
||||
Mutex.lock();
|
||||
{
|
||||
QMutexLocker locker ( &Mutex ); // this opperation must be done with mutex
|
||||
|
||||
SetSockBufSizeIntern ( iNumBlocks );
|
||||
}
|
||||
Mutex.unlock();
|
||||
}
|
||||
|
||||
void CChannel::SetSockBufSizeIntern ( const int iNumBlocks )
|
||||
{
|
||||
|
@ -697,32 +692,28 @@ void CChannel::SetSockBufSizeIntern ( const int iNumBlocks )
|
|||
|
||||
void CChannel::SetGain ( const int iChanID, const double dNewGain )
|
||||
{
|
||||
Mutex.lock();
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
// set value (make sure channel ID is in range)
|
||||
if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) )
|
||||
{
|
||||
vecdGains[iChanID] = dNewGain;
|
||||
}
|
||||
}
|
||||
Mutex.unlock();
|
||||
}
|
||||
|
||||
double CChannel::GetGain ( const int iChanID )
|
||||
{
|
||||
double dReturnVal = 0;
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
Mutex.lock();
|
||||
{
|
||||
// get value (make sure channel ID is in range)
|
||||
if ( ( iChanID >= 0 ) && ( iChanID < MAX_NUM_CHANNELS ) )
|
||||
{
|
||||
dReturnVal = vecdGains[iChanID];
|
||||
return vecdGains[iChanID];
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Mutex.unlock();
|
||||
|
||||
return dReturnVal;
|
||||
}
|
||||
|
||||
void CChannel::SetName ( const QString strNewName )
|
||||
|
@ -751,15 +742,9 @@ QString CChannel::GetName()
|
|||
{
|
||||
// make sure the string is not written at the same time when it is
|
||||
// read here -> use mutex to secure access
|
||||
QString strReturn;
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
Mutex.lock();
|
||||
{
|
||||
strReturn = sName;
|
||||
}
|
||||
Mutex.unlock();
|
||||
|
||||
return strReturn;
|
||||
return sName;
|
||||
}
|
||||
|
||||
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
||||
|
@ -799,25 +784,19 @@ void CChannel::OnChangeChanName ( QString strName )
|
|||
|
||||
bool CChannel::GetAddress(CHostAddress& RetAddr)
|
||||
{
|
||||
bool bReturnFlag;
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
Mutex.lock();
|
||||
{
|
||||
if ( IsConnected() )
|
||||
{
|
||||
RetAddr = InetAddr;
|
||||
bReturnFlag = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RetAddr = CHostAddress();
|
||||
bReturnFlag = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Mutex.unlock();
|
||||
|
||||
return bReturnFlag;
|
||||
}
|
||||
|
||||
EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
||||
int iNumBytes )
|
||||
|
@ -946,11 +925,11 @@ EPutDataStat CChannel::PutData ( const CVector<unsigned char>& vecbyData,
|
|||
|
||||
EGetDataStat CChannel::GetData ( CVector<double>& vecdData )
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
// init with ok flag
|
||||
EGetDataStat eGetStatus = GS_BUFFER_OK;
|
||||
|
||||
Mutex.lock(); // get mutex lock
|
||||
{
|
||||
if ( !SockBuf.Get ( vecdData ) )
|
||||
{
|
||||
// decrease time-out counter
|
||||
|
@ -975,20 +954,18 @@ EGetDataStat CChannel::GetData ( CVector<double>& vecdData )
|
|||
eGetStatus = GS_CHAN_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
Mutex.unlock(); // get mutex unlock
|
||||
|
||||
return eGetStatus;
|
||||
}
|
||||
|
||||
CVector<unsigned char> CChannel::PrepSendPacket ( const CVector<short>& vecsNPacket )
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
// if the block is not ready we have to initialize with zero length to
|
||||
// tell the following network send routine that nothing should be sent
|
||||
CVector<unsigned char> vecbySendBuf ( 0 );
|
||||
|
||||
Mutex.lock(); // get mutex lock
|
||||
{
|
||||
// use conversion buffer to convert sound card block size in network
|
||||
// block size
|
||||
if ( ConvBuf.Put ( vecsNPacket ) )
|
||||
|
@ -997,8 +974,6 @@ CVector<unsigned char> CChannel::PrepSendPacket ( const CVector<short>& vecsNPac
|
|||
vecbySendBuf.Init ( iAudComprSizeOut );
|
||||
vecbySendBuf = AudioCompressionOut.Encode ( ConvBuf.Get() );
|
||||
}
|
||||
}
|
||||
Mutex.unlock(); // get mutex unlock
|
||||
|
||||
return vecbySendBuf;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue