diff --git a/src/lib/data/TaskInjectStorage.cpp b/src/lib/data/TaskInjectStorage.cpp index 601b29ae..f508d3de 100644 --- a/src/lib/data/TaskInjectStorage.cpp +++ b/src/lib/data/TaskInjectStorage.cpp @@ -1,8 +1,5 @@ #include "data/TaskInjectStorage.h" -#include -#include - #include "data/Storage.h" #include "data/StorageProvider.h" #include "utility/scheduling/Blackboard.h" @@ -37,7 +34,6 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr blackboa { if (indexerCount > 0) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); return STATE_SUCCESS; } } diff --git a/src/lib/utility/scheduling/Blackboard.cpp b/src/lib/utility/scheduling/Blackboard.cpp index bf83d937..319965de 100644 --- a/src/lib/utility/scheduling/Blackboard.cpp +++ b/src/lib/utility/scheduling/Blackboard.cpp @@ -15,20 +15,20 @@ Blackboard::~Blackboard() bool Blackboard::exists(const std::string& key) { - std::lock_guard lock(m_mutex); + std::lock_guard lock(m_itemMutex); - ItemMap::const_iterator it = m_values.find(key); - return (it != m_values.end()); + ItemMap::const_iterator it = m_items.find(key); + return (it != m_items.end()); } bool Blackboard::clear(const std::string& key) { - std::lock_guard lock(m_mutex); + std::lock_guard lock(m_itemMutex); - ItemMap::const_iterator it = m_values.find(key); - if (it != m_values.end()) + ItemMap::const_iterator it = m_items.find(key); + if (it != m_items.end()) { - m_values.erase(it); + m_items.erase(it); return true; } return false; diff --git a/src/lib/utility/scheduling/Blackboard.h b/src/lib/utility/scheduling/Blackboard.h index 86ba47ae..029f4aec 100644 --- a/src/lib/utility/scheduling/Blackboard.h +++ b/src/lib/utility/scheduling/Blackboard.h @@ -48,28 +48,29 @@ public: private: typedef std::map> ItemMap; - std::mutex m_mutex; std::shared_ptr m_parent; - ItemMap m_values; + + ItemMap m_items; + std::mutex m_itemMutex; }; template void Blackboard::set(const std::string& key, const T& value) { - std::lock_guard lock(m_mutex); + std::lock_guard lock(m_itemMutex); - m_values[key] = std::make_shared>(value); + m_items[key] = std::make_shared>(value); } template bool Blackboard::get(const std::string& key, T& value) { - std::lock_guard lock(m_mutex); + std::lock_guard lock(m_itemMutex); - ItemMap::const_iterator it = m_values.find(key); - if (it != m_values.end()) + ItemMap::const_iterator it = m_items.find(key); + if (it != m_items.end()) { std::shared_ptr> item = std::dynamic_pointer_cast>(it->second); if (item) diff --git a/src/lib/utility/scheduling/TaskGroupParallel.cpp b/src/lib/utility/scheduling/TaskGroupParallel.cpp index 14468db4..fea40557 100644 --- a/src/lib/utility/scheduling/TaskGroupParallel.cpp +++ b/src/lib/utility/scheduling/TaskGroupParallel.cpp @@ -1,5 +1,8 @@ #include "utility/scheduling/TaskGroupParallel.h" +#include +#include + #include "utility/ScopedFunctor.h" TaskGroupParallel::TaskGroupParallel() @@ -69,6 +72,8 @@ void TaskGroupParallel::doReset(std::shared_ptr blackboard) void TaskGroupParallel::processTaskThreaded(std::shared_ptr taskInfo, std::shared_ptr blackboard) { + const int SLEEP_TIME_MS = 25; + ScopedFunctor functor([&](){ std::lock_guard lock(m_activeTaskCountMutex); m_activeTaskCount--; @@ -88,6 +93,8 @@ void TaskGroupParallel::processTaskThreaded(std::shared_ptr taskInfo, taskInfo->active = false; break; } + + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); } } diff --git a/src/lib/utility/scheduling/TaskScheduler.cpp b/src/lib/utility/scheduling/TaskScheduler.cpp index b19cd212..470132e8 100644 --- a/src/lib/utility/scheduling/TaskScheduler.cpp +++ b/src/lib/utility/scheduling/TaskScheduler.cpp @@ -48,6 +48,8 @@ void TaskScheduler::startSchedulerLoopThreaded() void TaskScheduler::startSchedulerLoop() { + const int SLEEP_TIME_MS = 25; + { std::lock_guard lock(m_loopMutex); @@ -73,7 +75,6 @@ void TaskScheduler::startSchedulerLoop() } } - const int SLEEP_TIME_MS = 25; std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); }