From 0fa4bf1e9d5492436de217aaa26127b58cf7e676 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 14 Jan 2018 05:14:14 +0100 Subject: [PATCH] Ref T207, workaround for Q_ASSERT issue described in T207 --- src/blackmisc/datacache.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/blackmisc/datacache.h b/src/blackmisc/datacache.h index 8c4fbdd66..bdb17c7ca 100644 --- a/src/blackmisc/datacache.h +++ b/src/blackmisc/datacache.h @@ -13,6 +13,7 @@ #define BLACKMISC_DATACACHE_H #include "blackmisc/blackmiscexport.h" +#include "blackmisc/threadutils.h" #include "blackmisc/identifier.h" #include "blackmisc/propertyindex.h" #include "blackmisc/statusmessage.h" @@ -71,7 +72,7 @@ namespace BlackMisc private: CValuePage *m_page = nullptr; - QList> m_queue; + QList> m_queue; QMutex m_mutex; }; } @@ -329,7 +330,7 @@ namespace BlackMisc if (Trait::isPinned()) { CDataCache::instance()->pinValue(this->getKey()); } if (Trait::isDeferred()) { CDataCache::instance()->deferValue(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. @@ -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. void synchronize() { + // does not compile on gcc without this -> this->m_page auto *queue = this->m_page->template findChild(); Q_ASSERT(queue); - admit(); - CDataCache::instance()->synchronize(this->getKey()); - CDataCache::instance()->synchronize(this->getKey()); // if load was in progress when admit() was called, synchronize with the next load - queue->setQueuedValueFromCache(this->getKey()); + this->admit(); + const QString key(this->getKey()); + CDataCache::instance()->synchronize(key); + 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).