diff --git a/src/lib/data/TaskInjectStorage.cpp b/src/lib/data/TaskInjectStorage.cpp index f508d3de..601b29ae 100644 --- a/src/lib/data/TaskInjectStorage.cpp +++ b/src/lib/data/TaskInjectStorage.cpp @@ -1,5 +1,8 @@ #include "data/TaskInjectStorage.h" +#include +#include + #include "data/Storage.h" #include "data/StorageProvider.h" #include "utility/scheduling/Blackboard.h" @@ -34,6 +37,7 @@ 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 5920d701..bf83d937 100644 --- a/src/lib/utility/scheduling/Blackboard.cpp +++ b/src/lib/utility/scheduling/Blackboard.cpp @@ -15,12 +15,16 @@ Blackboard::~Blackboard() bool Blackboard::exists(const std::string& key) { + std::lock_guard lock(m_mutex); + ItemMap::const_iterator it = m_values.find(key); return (it != m_values.end()); } bool Blackboard::clear(const std::string& key) { + std::lock_guard lock(m_mutex); + ItemMap::const_iterator it = m_values.find(key); if (it != m_values.end()) { diff --git a/src/lib/utility/scheduling/Blackboard.h b/src/lib/utility/scheduling/Blackboard.h index e1eebfa6..86ba47ae 100644 --- a/src/lib/utility/scheduling/Blackboard.h +++ b/src/lib/utility/scheduling/Blackboard.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "utility/logging/logging.h" @@ -47,6 +48,7 @@ public: private: typedef std::map> ItemMap; + std::mutex m_mutex; std::shared_ptr m_parent; ItemMap m_values; @@ -56,12 +58,16 @@ private: template void Blackboard::set(const std::string& key, const T& value) { + std::lock_guard lock(m_mutex); + m_values[key] = std::make_shared>(value); } template bool Blackboard::get(const std::string& key, T& value) { + std::lock_guard lock(m_mutex); + ItemMap::const_iterator it = m_values.find(key); if (it != m_values.end()) {