diff --git a/src/camera.cpp b/src/camera.cpp index d768f53..481cbd1 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -248,8 +248,10 @@ bool Upkeep::exec() dumpLogs(QString("logs/") + REC_LOG_NAME, shared->recLog); dumpLogs(QString("logs/") + DET_LOG_NAME, shared->detLog); + shared->logMutex.lock(); shared->recLog.clear(); shared->detLog.clear(); + shared->logMutex.unlock(); initLogFrontPages(); enforceMaxEvents(shared); @@ -308,6 +310,8 @@ bool EventLoop::exec() while (!shared->recList.isEmpty()) { + shared->recMutex.lock(); + auto event = shared->recList[0]; auto maxFiles = shared->evMaxSecs / 2; // there's 2 secs in each hls segment @@ -324,6 +328,7 @@ bool EventLoop::exec() vidList.append(forwardFacingFiles("live", ".ts", event.timeStamp, maxFiles / 2)); shared->recList.removeFirst(); + shared->recMutex.unlock(); } } @@ -494,7 +499,9 @@ bool DetectLoop::exec() event.score = score; event.imgPath = images[pos]; + shared->recMutex.lock(); shared->recList.append(event); mod = true; + shared->recMutex.unlock(); } } } diff --git a/src/common.h b/src/common.h index 993ac88..e0b4868 100644 --- a/src/common.h +++ b/src/common.h @@ -25,10 +25,11 @@ #include #include #include +#include using namespace std; -#define APP_VER "3.0.t15" +#define APP_VER "3.0.t16" #define APP_NAME "Motion Watch" #define APP_BIN "mow" #define REC_LOG_NAME "rec_log_lines.html" @@ -49,6 +50,8 @@ struct evt_t struct shared_t { QList recList; + QMutex recMutex; + QMutex logMutex; QString conf; QString recLog; QString detLog; diff --git a/src/logger.cpp b/src/logger.cpp index 293b64b..dc6485c 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -14,12 +14,20 @@ void recLog(const QString &line, shared_t *share) { + share->logMutex.lock(); + share->recLog += QDateTime::currentDateTime().toString("[yyyy-MM-dd-hh-mm-ss] ") + line + "
\n"; + + share->logMutex.unlock(); } void detLog(const QString &line, shared_t *share) { + share->logMutex.lock(); + share->detLog += QDateTime::currentDateTime().toString("[yyyy-MM-dd-hh-mm-ss] ") + line + "
\n"; + + share->logMutex.unlock(); } void enforceMaxLogSize(const QString &filePath, shared_t *share)