mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
Ref T292, Ref T285 avoid unnecessary calls of cache synchronize in model set/model caches
This commit is contained in:
@@ -59,6 +59,21 @@ namespace BlackMisc
|
||||
// void
|
||||
}
|
||||
|
||||
void IMultiSimulatorModelCaches::markCacheAsAlreadySynchronized(const CSimulatorInfo &simulator, bool synchronized)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: m_syncFS9 = synchronized; break;
|
||||
case CSimulatorInfo::FSX: m_syncFsx = synchronized; break;;
|
||||
case CSimulatorInfo::P3D: m_syncP3D = synchronized; break;;
|
||||
case CSimulatorInfo::XPLANE: m_syncXPlane = synchronized; break;;
|
||||
default:
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void IMultiSimulatorModelCaches::emitCacheChanged(const CSimulatorInfo &simulator)
|
||||
{
|
||||
emit this->cacheChanged(simulator);
|
||||
@@ -205,6 +220,22 @@ namespace BlackMisc
|
||||
return this->setCachedModels(models, simulator);
|
||||
}
|
||||
|
||||
bool IMultiSimulatorModelCaches::isCacheAlreadySynchronized(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return m_syncFS9;
|
||||
case CSimulatorInfo::FSX: return m_syncFsx;
|
||||
case CSimulatorInfo::P3D: return m_syncP3D;
|
||||
case CSimulatorInfo::XPLANE: return m_syncXPlane;
|
||||
default:
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IMultiSimulatorModelCaches::synchronizeMultiCaches(const CSimulatorInfo &simulator)
|
||||
{
|
||||
for (const CSimulatorInfo &singleSimulator : simulator.asSingleSimulatorSet())
|
||||
@@ -298,6 +329,8 @@ namespace BlackMisc
|
||||
void CModelCaches::synchronizeCacheImpl(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
|
||||
if (this->isCacheAlreadySynchronized(simulator)) { return; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: m_modelCacheFs9.synchronize(); break;
|
||||
@@ -308,12 +341,15 @@ namespace BlackMisc
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
break;
|
||||
}
|
||||
this->markCacheAsAlreadySynchronized(simulator, true);
|
||||
this->emitCacheChanged(simulator); // sync
|
||||
}
|
||||
|
||||
void CModelCaches::admitCacheImpl(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
|
||||
if (this->isCacheAlreadySynchronized(simulator)) { return; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: m_modelCacheFs9.admit(); break;
|
||||
@@ -328,7 +364,7 @@ namespace BlackMisc
|
||||
|
||||
CModelSetCaches::CModelSetCaches(bool synchronizeCache, QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{
|
||||
CSimulatorInfo simulator = BlackMisc::Simulation::CSimulatorInfo::guessDefaultSimulator();
|
||||
CSimulatorInfo simulator = CSimulatorInfo::guessDefaultSimulator();
|
||||
const QString simStr(simulator.toQString(true));
|
||||
|
||||
if (synchronizeCache)
|
||||
@@ -469,6 +505,8 @@ namespace BlackMisc
|
||||
void CModelSetCaches::synchronizeCacheImpl(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
|
||||
if (this->isCacheAlreadySynchronized(simulator)) { return; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: m_modelCacheFs9.synchronize(); break;
|
||||
@@ -479,12 +517,15 @@ namespace BlackMisc
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
this->markCacheAsAlreadySynchronized(simulator, true);
|
||||
this->emitCacheChanged(simulator); // sync
|
||||
}
|
||||
|
||||
void CModelSetCaches::admitCacheImpl(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
|
||||
if (this->isCacheAlreadySynchronized(simulator)) { return; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: m_modelCacheFs9.admit(); break;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <atomic>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -220,6 +221,10 @@ namespace BlackMisc
|
||||
//! \threadsafe
|
||||
virtual void synchronizeCache(const CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! Is the cache already synchronized?
|
||||
//! \threadsafe
|
||||
bool isCacheAlreadySynchronized(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Synchronize multiple simulators
|
||||
//! \threadsafe
|
||||
virtual void synchronizeMultiCaches(const CSimulatorInfo &simulator);
|
||||
@@ -233,12 +238,15 @@ namespace BlackMisc
|
||||
virtual void admitMultiCaches(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Info string about models in cache
|
||||
//! \threadsafe
|
||||
QString getInfoString() const;
|
||||
|
||||
//! Info string without XPlane (FSX,P3D, FS9)
|
||||
//! \threadsafe
|
||||
QString getInfoStringFsFamily() const;
|
||||
|
||||
//! Cache count and timestamp
|
||||
//! \threadsafe
|
||||
QString getCacheCountAndTimestamp(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Graceful shutdown
|
||||
@@ -257,16 +265,26 @@ namespace BlackMisc
|
||||
IMultiSimulatorModelCaches(QObject *parent = nullptr) : QObject(parent)
|
||||
{ }
|
||||
|
||||
//! \name Cache has been changed. This will only detect changes elsewhere, owned caches will not signal local changes
|
||||
//! @{
|
||||
//! \name Cache has been changed. This will only detect changes elsewhere, owned caches will not signal local changes @{
|
||||
void changedFsx() { this->emitCacheChanged(CSimulatorInfo::fsx()); }
|
||||
void changedFs9() { this->emitCacheChanged(CSimulatorInfo::fs9()); }
|
||||
void changedP3D() { this->emitCacheChanged(CSimulatorInfo::p3d()); }
|
||||
void changedXP() { this->emitCacheChanged(CSimulatorInfo::xplane()); }
|
||||
//! @}
|
||||
|
||||
//! Is the cache already synchronized?
|
||||
//! \threadsafe
|
||||
void markCacheAsAlreadySynchronized(const CSimulatorInfo &simulator, bool synchronized);
|
||||
|
||||
//! Emit cacheChanged() utility function (allows breakpoint)
|
||||
void emitCacheChanged(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Cache synchronized flag @{
|
||||
std::atomic_bool m_syncFsx { false };
|
||||
std::atomic_bool m_syncP3D { false };
|
||||
std::atomic_bool m_syncFS9 { false };
|
||||
std::atomic_bool m_syncXPlane { false };
|
||||
//! @}
|
||||
};
|
||||
|
||||
//! Bundle of caches for all simulators
|
||||
|
||||
Reference in New Issue
Block a user