mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
refs #522, consolidate mutable / make mutable thread safe
* removed mutable wherever possible in GUI classes * in vPilotReader also renamed some functions and some minor improvements
This commit is contained in:
@@ -34,7 +34,7 @@ namespace BlackMisc
|
||||
bool success = this->m_vPilotReader->read(false);
|
||||
if (success)
|
||||
{
|
||||
this->m_datastoreModels = this->m_vPilotReader->getRules().toAircraftModels();
|
||||
this->m_datastoreModels = this->m_vPilotReader->getAsModels();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace BlackMisc
|
||||
int keepModels(const QStringList &modelsToBeKept);
|
||||
|
||||
//! To aircraft models
|
||||
//! \note slow operation, can take a while
|
||||
BlackMisc::Simulation::CAircraftModelList toAircraftModels() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -82,12 +82,12 @@ namespace BlackMisc
|
||||
// already cached?
|
||||
{
|
||||
QReadLocker l(&m_lockData);
|
||||
if (!m_models.isEmpty() || m_rules.isEmpty()) return m_models;
|
||||
if (!m_models.isEmpty() || m_rules.isEmpty()) { return m_models; }
|
||||
if (m_shutdown) { return CAircraftModelList(); }
|
||||
}
|
||||
|
||||
// important: that can take a while and should normally
|
||||
// run in background
|
||||
if (m_shutdown) { return CAircraftModelList(); }
|
||||
CVPilotModelRuleSet rules(getRules()); // thread safe copy
|
||||
CAircraftModelList models(rules.toAircraftModels()); // long lasting operation
|
||||
QWriteLocker l(&m_lockData);
|
||||
@@ -103,6 +103,7 @@ namespace BlackMisc
|
||||
|
||||
void CVPilotRulesReader::gracefulShutdown()
|
||||
{
|
||||
QWriteLocker l(&m_lockData);
|
||||
m_shutdown = true;
|
||||
}
|
||||
|
||||
@@ -151,23 +152,23 @@ namespace BlackMisc
|
||||
return success;
|
||||
}
|
||||
|
||||
CWorker *CVPilotRulesReader::readASync(bool convertToModels)
|
||||
CWorker *CVPilotRulesReader::readInBackground(bool convertToModels)
|
||||
{
|
||||
// set a thread safe flag
|
||||
{
|
||||
QWriteLocker l(&m_lockData);
|
||||
if (m_asyncLoadInProgress) { return nullptr; }
|
||||
if (m_asyncLoadInProgress || m_shutdown) { return nullptr; }
|
||||
m_asyncLoadInProgress = true;
|
||||
}
|
||||
BlackMisc::CWorker *worker = BlackMisc::CWorker::fromTask(this, "CVPilotRulesReader", [this, convertToModels]()
|
||||
{
|
||||
this->read(convertToModels);
|
||||
});
|
||||
worker->then(this, &CVPilotRulesReader::ps_readASyncFinished);
|
||||
worker->then(this, &CVPilotRulesReader::ps_readInBackgroundFinished);
|
||||
return worker;
|
||||
}
|
||||
|
||||
void CVPilotRulesReader::ps_readASyncFinished()
|
||||
void CVPilotRulesReader::ps_readInBackgroundFinished()
|
||||
{
|
||||
QWriteLocker l(&m_lockData);
|
||||
m_asyncLoadInProgress = false;
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace BlackMisc
|
||||
int countRulesLoaded() const;
|
||||
|
||||
//! Graceful shutdown
|
||||
//! \threadsafe
|
||||
void gracefulShutdown();
|
||||
|
||||
//! The standard directory for vPilot mappings
|
||||
@@ -87,11 +88,12 @@ namespace BlackMisc
|
||||
|
||||
//! Load data in background thread
|
||||
//! \threadsafe
|
||||
BlackMisc::CWorker *readASync(bool convertToModels);
|
||||
BlackMisc::CWorker *readInBackground(bool convertToModels);
|
||||
|
||||
private slots:
|
||||
//! Asyncronous read finished
|
||||
void ps_readASyncFinished();
|
||||
//! \threadsafe
|
||||
void ps_readInBackgroundFinished();
|
||||
|
||||
private:
|
||||
QStringList m_fileList; //!< list of file names
|
||||
|
||||
Reference in New Issue
Block a user