mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-02 06:04:39 -04:00
Replace mutex lock/unlock pairs with guards, cleanups
This commit is contained in:
@@ -27,9 +27,12 @@ SDRPostThread::~SDRPostThread() {
|
||||
}
|
||||
|
||||
void SDRPostThread::bindDemodulator(DemodulatorInstance *demod) {
|
||||
|
||||
std::lock_guard < std::mutex > lock(busy_demod);
|
||||
|
||||
demodulators.push_back(demod);
|
||||
doRefresh.store(true);
|
||||
|
||||
}
|
||||
|
||||
void SDRPostThread::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
|
||||
@@ -37,10 +40,12 @@ void SDRPostThread::bindDemodulators(std::vector<DemodulatorInstance *> *demods)
|
||||
return;
|
||||
}
|
||||
std::lock_guard < std::mutex > lock(busy_demod);
|
||||
|
||||
for (std::vector<DemodulatorInstance *>::iterator di = demods->begin(); di != demods->end(); di++) {
|
||||
demodulators.push_back(*di);
|
||||
doRefresh.store(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
||||
@@ -49,12 +54,14 @@ void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
||||
}
|
||||
|
||||
std::lock_guard < std::mutex > lock(busy_demod);
|
||||
|
||||
std::vector<DemodulatorInstance *>::iterator i = std::find(demodulators.begin(), demodulators.end(), demod);
|
||||
|
||||
if (i != demodulators.end()) {
|
||||
demodulators.erase(i);
|
||||
doRefresh.store(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SDRPostThread::initPFBChannelizer() {
|
||||
@@ -79,7 +86,7 @@ void SDRPostThread::updateActiveDemodulators() {
|
||||
nRunDemods = 0;
|
||||
|
||||
long long centerFreq = wxGetApp().getFrequency();
|
||||
|
||||
|
||||
for (demod_i = demodulators.begin(); demod_i != demodulators.end(); demod_i++) {
|
||||
DemodulatorInstance *demod = *demod_i;
|
||||
DemodulatorThreadInputQueue *demodQueue = demod->getIQInputDataPipe();
|
||||
|
||||
@@ -29,10 +29,14 @@ protected:
|
||||
DemodulatorThreadInputQueue *iqVisualQueue;
|
||||
DemodulatorThreadInputQueue *iqActiveDemodVisualQueue;
|
||||
|
||||
//protects access to demodulators lists and such
|
||||
std::mutex busy_demod;
|
||||
std::vector<DemodulatorInstance *> demodulators;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void initPFBChannelizer();
|
||||
void updateActiveDemodulators();
|
||||
void updateChannels();
|
||||
|
||||
+28
-25
@@ -126,20 +126,22 @@ void SDRThread::init() {
|
||||
settingChanged.erase(settingChanged.begin(), settingChanged.end());
|
||||
}
|
||||
|
||||
setting_busy.lock();
|
||||
for (settings_i = settingsInfo.begin(); settings_i != settingsInfo.end(); settings_i++) {
|
||||
SoapySDR::ArgInfo setting = (*settings_i);
|
||||
if ((settingChanged.find(setting.key) != settingChanged.end()) && (settings.find(setting.key) != settings.end())) {
|
||||
device->writeSetting(setting.key, settings[setting.key]);
|
||||
settingChanged[setting.key] = false;
|
||||
} else {
|
||||
settings[setting.key] = device->readSetting(setting.key);
|
||||
settingChanged[setting.key] = false;
|
||||
}
|
||||
}
|
||||
setting_value_changed.store(false);
|
||||
{ //enter scoped-lock
|
||||
std::lock_guard < std::mutex > lock(setting_busy);
|
||||
|
||||
setting_busy.unlock();
|
||||
for (settings_i = settingsInfo.begin(); settings_i != settingsInfo.end(); settings_i++) {
|
||||
SoapySDR::ArgInfo setting = (*settings_i);
|
||||
if ((settingChanged.find(setting.key) != settingChanged.end()) && (settings.find(setting.key) != settings.end())) {
|
||||
device->writeSetting(setting.key, settings[setting.key]);
|
||||
settingChanged[setting.key] = false;
|
||||
} else {
|
||||
settings[setting.key] = device->readSetting(setting.key);
|
||||
settingChanged[setting.key] = false;
|
||||
}
|
||||
}
|
||||
setting_value_changed.store(false);
|
||||
|
||||
} //leave lock guard scope
|
||||
|
||||
updateSettings();
|
||||
|
||||
@@ -316,21 +318,22 @@ void SDRThread::updateSettings() {
|
||||
}
|
||||
|
||||
if (gain_value_changed.load() && !agc_mode.load()) {
|
||||
gain_busy.lock();
|
||||
std::lock_guard < std::mutex > lock(gain_busy);
|
||||
|
||||
for (std::map<std::string,bool>::iterator gci = gainChanged.begin(); gci != gainChanged.end(); gci++) {
|
||||
if (gci->second) {
|
||||
device->setGain(SOAPY_SDR_RX, 0, gci->first, gainValues[gci->first]);
|
||||
gainChanged[gci->first] = false;
|
||||
}
|
||||
}
|
||||
gain_busy.unlock();
|
||||
|
||||
gain_value_changed.store(false);
|
||||
}
|
||||
|
||||
|
||||
if (setting_value_changed.load()) {
|
||||
setting_busy.lock();
|
||||
|
||||
std::lock_guard < std::mutex > lock(setting_busy);
|
||||
|
||||
for (std::map<std::string, bool>::iterator sci = settingChanged.begin(); sci != settingChanged.end(); sci++) {
|
||||
if (sci->second) {
|
||||
@@ -340,7 +343,6 @@ void SDRThread::updateSettings() {
|
||||
}
|
||||
|
||||
setting_value_changed.store(false);
|
||||
setting_busy.unlock();
|
||||
|
||||
doUpdate = true;
|
||||
}
|
||||
@@ -511,11 +513,10 @@ bool SDRThread::getIQSwap() {
|
||||
}
|
||||
|
||||
void SDRThread::setGain(std::string name, float value) {
|
||||
gain_busy.lock();
|
||||
std::lock_guard < std::mutex > lock(gain_busy);
|
||||
gainValues[name] = value;
|
||||
gainChanged[name] = true;
|
||||
gain_value_changed.store(true);
|
||||
gain_busy.unlock();
|
||||
|
||||
DeviceConfig *devConfig = deviceConfig.load();
|
||||
if (devConfig) {
|
||||
@@ -524,28 +525,30 @@ void SDRThread::setGain(std::string name, float value) {
|
||||
}
|
||||
|
||||
float SDRThread::getGain(std::string name) {
|
||||
gain_busy.lock();
|
||||
std::lock_guard < std::mutex > lock(gain_busy);
|
||||
float val = gainValues[name];
|
||||
gain_busy.unlock();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void SDRThread::writeSetting(std::string name, std::string value) {
|
||||
setting_busy.lock();
|
||||
|
||||
std::lock_guard < std::mutex > lock(setting_busy);
|
||||
|
||||
settings[name] = value;
|
||||
settingChanged[name] = true;
|
||||
setting_value_changed.store(true);
|
||||
if (deviceConfig.load() != nullptr) {
|
||||
deviceConfig.load()->setSetting(name, value);
|
||||
}
|
||||
setting_busy.unlock();
|
||||
}
|
||||
|
||||
std::string SDRThread::readSetting(std::string name) {
|
||||
std::string val;
|
||||
setting_busy.lock();
|
||||
std::lock_guard < std::mutex > lock(setting_busy);
|
||||
|
||||
val = device->readSetting(name);
|
||||
setting_busy.unlock();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user