mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #255 Use QMutex and std::atomic instead of QReadWriteLock
This commit is contained in:
@@ -26,16 +26,9 @@ namespace BlackCore
|
||||
m_micTestResult(Cvatlib_Voice_Simple::agc_Ok),
|
||||
m_isAudioLoopbackEnabled(false),
|
||||
m_temporaryUserRoomIndex(CVoiceVatlib::InvalidRoomIndex),
|
||||
m_lockVoiceRooms(QReadWriteLock::Recursive),
|
||||
m_lockCallsigns(QReadWriteLock::Recursive),
|
||||
m_lockCurrentOutputDevice(QReadWriteLock::Recursive),
|
||||
m_lockCurrentInputDevice(QReadWriteLock::Recursive),
|
||||
m_lockDeviceList(QReadWriteLock::Recursive),
|
||||
m_lockOutputEnabled(QReadWriteLock::Recursive),
|
||||
m_lockSquelch(QReadWriteLock::Recursive),
|
||||
m_lockTestResult(QReadWriteLock::Recursive),
|
||||
m_lockMyCallsign(QReadWriteLock::Recursive),
|
||||
m_lockConnectionStatus(QReadWriteLock::Recursive),
|
||||
m_lockCurrentOutputDevice(QMutex::Recursive),
|
||||
m_lockCurrentInputDevice(QMutex::Recursive),
|
||||
m_lockDeviceList(QMutex::Recursive)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -75,7 +68,7 @@ namespace BlackCore
|
||||
*/
|
||||
const BlackMisc::Audio::CAudioDeviceList &CVoiceVatlib::audioDevices() const
|
||||
{
|
||||
QReadLocker lockForReading(&m_lockDeviceList);
|
||||
QMutexLocker lockForReading(&m_lockDeviceList);
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
@@ -102,7 +95,7 @@ namespace BlackCore
|
||||
*/
|
||||
CAudioDevice CVoiceVatlib::getCurrentOutputDevice() const
|
||||
{
|
||||
QReadLocker lockForReading(&m_lockCurrentOutputDevice);
|
||||
QMutexLocker locker(&m_lockCurrentOutputDevice);
|
||||
return m_currentOutputDevice;
|
||||
}
|
||||
|
||||
@@ -111,7 +104,7 @@ namespace BlackCore
|
||||
*/
|
||||
CAudioDevice CVoiceVatlib::getCurrentInputDevice() const
|
||||
{
|
||||
QReadLocker lockForReading(&m_lockCurrentInputDevice);
|
||||
QMutexLocker locker(&m_lockCurrentInputDevice);
|
||||
return m_currentInputDevice;
|
||||
}
|
||||
|
||||
@@ -138,7 +131,7 @@ namespace BlackCore
|
||||
{
|
||||
qWarning() << "Input device hit a fatal error";
|
||||
}
|
||||
QWriteLocker lockForWriting(&m_lockCurrentInputDevice);
|
||||
QMutexLocker writeLocker(&m_lockCurrentInputDevice);
|
||||
this->m_currentInputDevice = device;
|
||||
}
|
||||
catch (...)
|
||||
@@ -168,7 +161,7 @@ namespace BlackCore
|
||||
{
|
||||
qWarning() << "Output device hit a fatal error";
|
||||
}
|
||||
QWriteLocker lockForWriting(&m_lockCurrentOutputDevice);
|
||||
QMutexLocker writeLocker(&m_lockCurrentOutputDevice);
|
||||
this->m_currentOutputDevice = device;
|
||||
}
|
||||
catch (...)
|
||||
@@ -298,7 +291,6 @@ namespace BlackCore
|
||||
*/
|
||||
float CVoiceVatlib::inputSquelch() const
|
||||
{
|
||||
QReadLocker lockForReading(&m_lockSquelch);
|
||||
return m_inputSquelch;
|
||||
}
|
||||
|
||||
@@ -307,7 +299,6 @@ namespace BlackCore
|
||||
*/
|
||||
qint32 CVoiceVatlib::micTestResult() const
|
||||
{
|
||||
QReadLocker lockForReading(&m_lockTestResult);
|
||||
return m_micTestResult;
|
||||
}
|
||||
|
||||
@@ -318,7 +309,6 @@ namespace BlackCore
|
||||
{
|
||||
QString result;
|
||||
|
||||
QReadLocker lockForReading(&m_lockTestResult);
|
||||
switch (m_micTestResult)
|
||||
{
|
||||
case Cvatlib_Voice_Simple::agc_Ok:
|
||||
@@ -573,7 +563,6 @@ namespace BlackCore
|
||||
try
|
||||
{
|
||||
m_vatlib->EndFindSquelch();
|
||||
QWriteLocker lockForWriting(&m_lockSquelch);
|
||||
m_inputSquelch = m_vatlib->GetInputSquelch();
|
||||
emit squelchTestFinished();
|
||||
}
|
||||
@@ -590,7 +579,6 @@ namespace BlackCore
|
||||
|
||||
try
|
||||
{
|
||||
QWriteLocker lockForWriting(&m_lockTestResult);
|
||||
m_micTestResult = m_vatlib->EndMicTest();
|
||||
emit micTestFinished();
|
||||
}
|
||||
@@ -715,7 +703,7 @@ namespace BlackCore
|
||||
{
|
||||
Q_UNUSED(obj)
|
||||
BlackMisc::Audio::CAudioDevice inputDevice(BlackMisc::Audio::CAudioDevice::InputDevice, cbvar_cast_voice(cbVar)->m_devices.count(BlackMisc::Audio::CAudioDevice::InputDevice), QString(name));
|
||||
QWriteLocker lockForWriting(&(cbvar_cast_voice(cbVar)->m_lockDeviceList));
|
||||
QMutexLocker lockForWriting(&(cbvar_cast_voice(cbVar)->m_lockDeviceList));
|
||||
cbvar_cast_voice(cbVar)->m_devices.push_back(inputDevice);
|
||||
}
|
||||
|
||||
@@ -726,7 +714,7 @@ namespace BlackCore
|
||||
{
|
||||
Q_UNUSED(obj)
|
||||
BlackMisc::Audio::CAudioDevice outputDevice(BlackMisc::Audio::CAudioDevice::OutputDevice, cbvar_cast_voice(cbVar)->m_devices.count(BlackMisc::Audio::CAudioDevice::OutputDevice), QString(name));
|
||||
QWriteLocker lockForWriting(&(cbvar_cast_voice(cbVar)->m_lockDeviceList));
|
||||
QMutexLocker lockForWriting(&(cbvar_cast_voice(cbVar)->m_lockDeviceList));
|
||||
cbvar_cast_voice(cbVar)->m_devices.push_back(outputDevice);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <QString>
|
||||
#include <QMutex>
|
||||
#include <QReadWriteLock>
|
||||
#include <atomic>
|
||||
#include <utility>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -57,6 +58,7 @@ namespace BlackCore
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param parent
|
||||
@@ -238,8 +240,8 @@ namespace BlackCore
|
||||
BlackMisc::Audio::CAudioDeviceList m_devices; /*!< in and output devices */
|
||||
BlackMisc::Audio::CAudioDevice m_currentOutputDevice;
|
||||
BlackMisc::Audio::CAudioDevice m_currentInputDevice;
|
||||
float m_inputSquelch;
|
||||
Cvatlib_Voice_Simple::agc m_micTestResult;
|
||||
std::atomic<float> m_inputSquelch;
|
||||
std::atomic<Cvatlib_Voice_Simple::agc> m_micTestResult;
|
||||
QMap <ComUnit, BlackMisc::Aviation::CCallsignList> m_voiceRoomCallsigns; /*!< voice room callsigns */
|
||||
BlackMisc::Aviation::CCallsignList m_temporaryVoiceRoomCallsigns; /*!< temp. storage of voice rooms during update */
|
||||
QMap<ComUnit, bool> m_outputEnabled; /*!< output enabled, basically a mute flag */
|
||||
@@ -253,17 +255,9 @@ namespace BlackCore
|
||||
const static qint32 InvalidRoomIndex = -1; /*! marks invalid room */
|
||||
|
||||
// Thread serialization
|
||||
mutable QReadWriteLock m_lockVoiceRooms;
|
||||
mutable QReadWriteLock m_lockCallsigns;
|
||||
mutable QReadWriteLock m_lockCurrentOutputDevice;
|
||||
mutable QReadWriteLock m_lockCurrentInputDevice;
|
||||
mutable QReadWriteLock m_lockDeviceList;
|
||||
mutable QReadWriteLock m_lockOutputEnabled;
|
||||
mutable QReadWriteLock m_lockSquelch;
|
||||
mutable QReadWriteLock m_lockTestResult;
|
||||
mutable QReadWriteLock m_lockMyCallsign;
|
||||
mutable QReadWriteLock m_lockConnectionStatus;
|
||||
|
||||
mutable QMutex m_lockCurrentOutputDevice;
|
||||
mutable QMutex m_lockCurrentInputDevice;
|
||||
mutable QMutex m_lockDeviceList;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user