logic: Fixed indexing tasks

* Added mutex to BlackBoard
* stop inject task from blocking CPU in endless loop
This commit is contained in:
Eberhard Graether
2016-09-15 00:02:50 +02:00
parent ae879ba0f7
commit b1b2262581
3 changed files with 14 additions and 0 deletions
+4
View File
@@ -1,5 +1,8 @@
#include "data/TaskInjectStorage.h"
#include <chrono>
#include <thread>
#include "data/Storage.h"
#include "data/StorageProvider.h"
#include "utility/scheduling/Blackboard.h"
@@ -34,6 +37,7 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboa
{
if (indexerCount > 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return STATE_SUCCESS;
}
}
@@ -15,12 +15,16 @@ Blackboard::~Blackboard()
bool Blackboard::exists(const std::string& key)
{
std::lock_guard<std::mutex> 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<std::mutex> lock(m_mutex);
ItemMap::const_iterator it = m_values.find(key);
if (it != m_values.end())
{
+6
View File
@@ -3,6 +3,7 @@
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include "utility/logging/logging.h"
@@ -47,6 +48,7 @@ public:
private:
typedef std::map<std::string, std::shared_ptr<BlackboardItemBase>> ItemMap;
std::mutex m_mutex;
std::shared_ptr<Blackboard> m_parent;
ItemMap m_values;
@@ -56,12 +58,16 @@ private:
template <typename T>
void Blackboard::set(const std::string& key, const T& value)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_values[key] = std::make_shared<BlackboardItem<T>>(value);
}
template <typename T>
bool Blackboard::get(const std::string& key, T& value)
{
std::lock_guard<std::mutex> lock(m_mutex);
ItemMap::const_iterator it = m_values.find(key);
if (it != m_values.end())
{