UI: LogManager: Fix buffers handling.

This commit is contained in:
Nodir Temirkhodjaev 2018-02-23 15:33:28 +05:00
parent 7b03e56576
commit 19344e8d8c
4 changed files with 17 additions and 8 deletions

View File

@ -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()

View File

@ -23,7 +23,7 @@ signals:
const QString &errorMessage);
public slots:
void readLogAsync(LogBuffer *logBuffer);
bool readLogAsync(LogBuffer *logBuffer);
void cancelAsyncIo();
void abort();

View File

@ -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;
}
}

View File

@ -46,7 +46,7 @@ private:
void setupDriverWorker();
void readLogAsync(LogBuffer *logBuffer);
void readLogAsync();
void cancelAsyncIo();
LogBuffer *getFreeBuffer();