From 7707eaf0457317f289fd29a16b658596b41fa09a Mon Sep 17 00:00:00 2001 From: EndrII Date: Wed, 19 Feb 2025 13:28:56 +0100 Subject: [PATCH 1/2] added more logs and mutex --- src/qTbot/src/public/qTbot/ibot.cpp | 34 ++++++++++++++++++++++++----- src/qTbot/src/public/qTbot/ibot.h | 4 +++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/qTbot/src/public/qTbot/ibot.cpp b/src/qTbot/src/public/qTbot/ibot.cpp index 2dbd22a..c45e94d 100644 --- a/src/qTbot/src/public/qTbot/ibot.cpp +++ b/src/qTbot/src/public/qTbot/ibot.cpp @@ -115,7 +115,23 @@ void IBot::setParallelActiveNetworkThreads(int newParallelActiveNetworkThreads) } void IBot::setCurrentParallelActiveNetworkThreads(int newParallelActiveNetworkThreads) { + bool wasBusy = _currentParallelActiveNetworkThreads == _parallelActiveNetworkThreads; + static bool lastMessageWasFree = false; + _currentParallelActiveNetworkThreads = newParallelActiveNetworkThreads; + + if (_currentParallelActiveNetworkThreads == _parallelActiveNetworkThreads) { + qInfo() << "All network threads are busy!"; + lastMessageWasFree = false; + + } else if (wasBusy) { + qInfo() << "Network threads are free! available: " << _currentParallelActiveNetworkThreads << " from " << _parallelActiveNetworkThreads; + lastMessageWasFree = false; + + } else if (_currentParallelActiveNetworkThreads == 0 && !lastMessageWasFree) { + qInfo() << "All network threads are free!"; + lastMessageWasFree = true; + } } int IBot::reqestLimitPerSecond() const { @@ -131,9 +147,11 @@ IBot::sendRequest(const QSharedPointer &rquest) { auto&& responce = QSharedPointer>::create(); responce->start(); - - _requestQueue.insert(makeKey(rquest->priority()), - RequestData{rquest, "", responce}); + { + QMutexLocker lock(&_mutex); + _requestQueue.insert(makeKey(rquest->priority()), + RequestData{rquest, "", responce}); + } if (!_requestExecutor->isActive()) { handleEcxecuteRequest(); @@ -150,8 +168,12 @@ IBot::sendRequest(const QSharedPointer &rquest, auto&& responce = QSharedPointer>::create(); responce->start(); - _requestQueue.insert(makeKey(rquest->priority()), - RequestData{rquest, pathToResult, responce}); + { + QMutexLocker lock(&_mutex); + _requestQueue.insert(makeKey(rquest->priority()), + RequestData{rquest, pathToResult, responce}); + } + if (!_requestExecutor->isActive()) { handleEcxecuteRequest(); @@ -184,6 +206,8 @@ void IBot::handleIncomeNewUpdate(const QSharedPointer & message) { } void IBot::handleEcxecuteRequest() { + QMutexLocker lock(&_mutex); + if (!_requestQueue.size()) { _requestExecutor->stop(); return; diff --git a/src/qTbot/src/public/qTbot/ibot.h b/src/qTbot/src/public/qTbot/ibot.h index f9517e3..7f95228 100644 --- a/src/qTbot/src/public/qTbot/ibot.h +++ b/src/qTbot/src/public/qTbot/ibot.h @@ -305,7 +305,7 @@ signals: /** * @brief sigReceiveUpdate emit when but receive any updates from users. */ - void sigReceiveUpdate(const QSharedPointer& ); + void sigReceiveUpdate(const QSharedPointer& ); /** * @brief sigStopRequire just custm event for stop bot if tou use services. @@ -339,6 +339,8 @@ private: int _currentParallelActiveNetworkThreads = 0; int _parallelActiveNetworkThreads = 5; + QRecursiveMutex _mutex; + }; From b8bcf5324b021e7c443f06d6fe9d8e8aaedc9a03 Mon Sep 17 00:00:00 2001 From: EndrII Date: Wed, 19 Feb 2025 13:30:14 +0100 Subject: [PATCH 2/2] update cmake --- submodules/CMake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/CMake b/submodules/CMake index a96691e..f96d16e 160000 --- a/submodules/CMake +++ b/submodules/CMake @@ -1 +1 @@ -Subproject commit a96691e39974196e4739fbbb16e13eab5060c0ee +Subproject commit f96d16ec9be058fc35f3966e0a8dfe7d62ad3fb1