mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
refs #601 CDataCache overrides connectPage to provide a queue that is more flexible than the usual Qt::QueuedConnection.
This commit is contained in:
@@ -14,11 +14,15 @@
|
||||
#include "blackmisc/identifier.h"
|
||||
#include "blackmisc/atomicfile.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QTimer>
|
||||
#include <utility>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
using Private::CValuePage;
|
||||
using Private::CDataPageQueue;
|
||||
|
||||
class CDataCacheRevision::LockGuard
|
||||
{
|
||||
public:
|
||||
@@ -149,6 +153,39 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
void CDataCache::connectPage(CValuePage *page)
|
||||
{
|
||||
auto *queue = new CDataPageQueue(page);
|
||||
connect(page, &CValuePage::valuesWantToCache, this, &CDataCache::changeValues);
|
||||
connect(this, &CDataCache::valuesChanged, queue, &CDataPageQueue::queueValuesFromCache, Qt::DirectConnection);
|
||||
|
||||
auto *timer = new QTimer(page);
|
||||
connect(timer, &QTimer::timeout, queue, &CDataPageQueue::trySetQueuedValuesFromCache);
|
||||
timer->start(0);
|
||||
}
|
||||
|
||||
void CDataPageQueue::queueValuesFromCache(const CValueCachePacket &values, QObject *changedBy)
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
m_queue.push_back(std::make_pair(values, changedBy));
|
||||
}
|
||||
|
||||
void CDataPageQueue::trySetQueuedValuesFromCache()
|
||||
{
|
||||
bool locked = m_mutex.tryLock(0);
|
||||
if (locked)
|
||||
{
|
||||
decltype(m_queue) queue;
|
||||
qSwap(m_queue, queue);
|
||||
m_mutex.unlock();
|
||||
|
||||
for (const auto &pair : queue)
|
||||
{
|
||||
m_page->setValuesFromCache(pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CDataCacheSerializer::CDataCacheSerializer(CDataCache *owner, const QString &revisionFileName) :
|
||||
CContinuousWorker(owner),
|
||||
m_cache(owner),
|
||||
|
||||
Reference in New Issue
Block a user