From 19344e8d8c77a6f5429e4fd496ddb109a8983e0b Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 23 Feb 2018 15:33:28 +0500 Subject: [PATCH] UI: LogManager: Fix buffers handling. --- src/ui/driver/driverworker.cpp | 7 ++++++- src/ui/driver/driverworker.h | 2 +- src/ui/log/logmanager.cpp | 14 +++++++++----- src/ui/log/logmanager.h | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ui/driver/driverworker.cpp b/src/ui/driver/driverworker.cpp index a8c71123..5e3bcc66 100644 --- a/src/ui/driver/driverworker.cpp +++ b/src/ui/driver/driverworker.cpp @@ -22,15 +22,20 @@ void DriverWorker::run() } while (!m_aborted); } -void DriverWorker::readLogAsync(LogBuffer *logBuffer) +bool DriverWorker::readLogAsync(LogBuffer *logBuffer) { QMutexLocker locker(&m_mutex); + if (m_logBuffer) + return false; + m_cancelled = false; m_logBuffer = logBuffer; m_waitCondition.wakeOne(); + + return true; } void DriverWorker::cancelAsyncIo() diff --git a/src/ui/driver/driverworker.h b/src/ui/driver/driverworker.h index 47fd559b..75728ac3 100644 --- a/src/ui/driver/driverworker.h +++ b/src/ui/driver/driverworker.h @@ -23,7 +23,7 @@ signals: const QString &errorMessage); public slots: - void readLogAsync(LogBuffer *logBuffer); + bool readLogAsync(LogBuffer *logBuffer); void cancelAsyncIo(); void abort(); diff --git a/src/ui/log/logmanager.cpp b/src/ui/log/logmanager.cpp index 003ef33a..46f10327 100644 --- a/src/ui/log/logmanager.cpp +++ b/src/ui/log/logmanager.cpp @@ -27,10 +27,9 @@ void LogManager::setActive(bool active) m_active = active; if (m_active) { - readLogAsync(getFreeBuffer()); + readLogAsync(); } else { cancelAsyncIo(); - readLogAsync(nullptr); } emit activeChanged(); @@ -56,9 +55,13 @@ void LogManager::setupDriverWorker() this, &LogManager::processLogBuffer, Qt::QueuedConnection); } -void LogManager::readLogAsync(LogBuffer *logBuffer) +void LogManager::readLogAsync() { - m_driverWorker->readLogAsync(logBuffer); + LogBuffer *logBuffer = getFreeBuffer(); + + if (!m_driverWorker->readLogAsync(logBuffer)) { + addFreeBuffer(logBuffer); + } } void LogManager::cancelAsyncIo() @@ -84,7 +87,7 @@ void LogManager::processLogBuffer(LogBuffer *logBuffer, bool success, const QString &errorMessage) { if (m_active) { - readLogAsync(getFreeBuffer()); + readLogAsync(); } if (success) { @@ -124,6 +127,7 @@ void LogManager::readLogEntries(LogBuffer *logBuffer) break; } default: + Q_ASSERT(logBuffer->offset() != 0); return; } } diff --git a/src/ui/log/logmanager.h b/src/ui/log/logmanager.h index 18d65f49..d0125742 100644 --- a/src/ui/log/logmanager.h +++ b/src/ui/log/logmanager.h @@ -46,7 +46,7 @@ private: void setupDriverWorker(); - void readLogAsync(LogBuffer *logBuffer); + void readLogAsync(); void cancelAsyncIo(); LogBuffer *getFreeBuffer();