Ref T207, workaround for Q_ASSERT issue described in T207

This commit is contained in:
Klaus Basan
2018-01-14 05:14:14 +01:00
parent 8bb47a555c
commit 0fa4bf1e9d

View File

@@ -13,6 +13,7 @@
#define BLACKMISC_DATACACHE_H #define BLACKMISC_DATACACHE_H
#include "blackmisc/blackmiscexport.h" #include "blackmisc/blackmiscexport.h"
#include "blackmisc/threadutils.h"
#include "blackmisc/identifier.h" #include "blackmisc/identifier.h"
#include "blackmisc/propertyindex.h" #include "blackmisc/propertyindex.h"
#include "blackmisc/statusmessage.h" #include "blackmisc/statusmessage.h"
@@ -71,7 +72,7 @@ namespace BlackMisc
private: private:
CValuePage *m_page = nullptr; CValuePage *m_page = nullptr;
QList<std::pair<CValueCachePacket, QObject*>> m_queue; QList<std::pair<CValueCachePacket, QObject *>> m_queue;
QMutex m_mutex; QMutex m_mutex;
}; };
} }
@@ -329,7 +330,7 @@ namespace BlackMisc
if (Trait::isPinned()) { CDataCache::instance()->pinValue(this->getKey()); } if (Trait::isPinned()) { CDataCache::instance()->pinValue(this->getKey()); }
if (Trait::isDeferred()) { CDataCache::instance()->deferValue(this->getKey()); } if (Trait::isDeferred()) { CDataCache::instance()->deferValue(this->getKey()); }
if (Trait::isSession()) { CDataCache::instance()->sessionValue(this->getKey()); } if (Trait::isSession()) { CDataCache::instance()->sessionValue(this->getKey()); }
static_assert(! (Trait::isPinned() && Trait::isDeferred()), "trait can not be both pinned and deferred"); static_assert(!(Trait::isPinned() && Trait::isDeferred()), "trait can not be both pinned and deferred");
} }
//! Constructor. //! Constructor.
@@ -381,12 +382,18 @@ namespace BlackMisc
//! If the value is currently being loaded, wait for it to finish loading, and call the notification slot, if any. //! If the value is currently being loaded, wait for it to finish loading, and call the notification slot, if any.
void synchronize() void synchronize()
{ {
// does not compile on gcc without this -> this->m_page
auto *queue = this->m_page->template findChild<Private::CDataPageQueue *>(); auto *queue = this->m_page->template findChild<Private::CDataPageQueue *>();
Q_ASSERT(queue); Q_ASSERT(queue);
admit(); this->admit();
CDataCache::instance()->synchronize(this->getKey()); const QString key(this->getKey());
CDataCache::instance()->synchronize(this->getKey()); // if load was in progress when admit() was called, synchronize with the next load CDataCache::instance()->synchronize(key);
queue->setQueuedValueFromCache(this->getKey()); CDataCache::instance()->synchronize(key); // if load was in progress when admit() was called, synchronize with the next load
// run in page thread
//! \todo KB 2018-01 is this OK or should it go to CValuePage::setValuesFromCache?
if (CThreadUtils::isCurrentThreadObjectThread(this->m_page)) { queue->setQueuedValueFromCache(key); }
else { QTimer::singleShot(0, queue, [ = ] { queue->setQueuedValueFromCache(key); }); }
} }
//! Data cache doesn't support setAndSave (because set() already causes save anyway). //! Data cache doesn't support setAndSave (because set() already causes save anyway).