logic: moved task waiting
* moved waiting from TaskInjectStorage to TaskGroupParallel so that the tasks that run here have the same conditions as tasks running in the TaskScheduler
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
#include "data/TaskInjectStorage.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "data/Storage.h"
|
||||
#include "data/StorageProvider.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
@@ -37,7 +34,6 @@ 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,20 +15,20 @@ Blackboard::~Blackboard()
|
||||
|
||||
bool Blackboard::exists(const std::string& key)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<std::mutex> 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<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<std::mutex> 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;
|
||||
|
||||
@@ -48,28 +48,29 @@ 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;
|
||||
|
||||
ItemMap m_items;
|
||||
std::mutex m_itemMutex;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
void Blackboard::set(const std::string& key, const T& value)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_itemMutex);
|
||||
|
||||
m_values[key] = std::make_shared<BlackboardItem<T>>(value);
|
||||
m_items[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);
|
||||
std::lock_guard<std::mutex> 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<BlackboardItem<T>> item = std::dynamic_pointer_cast<BlackboardItem<T>>(it->second);
|
||||
if (item)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "utility/scheduling/TaskGroupParallel.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "utility/ScopedFunctor.h"
|
||||
|
||||
TaskGroupParallel::TaskGroupParallel()
|
||||
@@ -69,6 +72,8 @@ void TaskGroupParallel::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
void TaskGroupParallel::processTaskThreaded(std::shared_ptr<TaskInfo> taskInfo, std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
|
||||
ScopedFunctor functor([&](){
|
||||
std::lock_guard<std::mutex> lock(m_activeTaskCountMutex);
|
||||
m_activeTaskCount--;
|
||||
@@ -88,6 +93,8 @@ void TaskGroupParallel::processTaskThreaded(std::shared_ptr<TaskInfo> taskInfo,
|
||||
taskInfo->active = false;
|
||||
break;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ void TaskScheduler::startSchedulerLoopThreaded()
|
||||
|
||||
void TaskScheduler::startSchedulerLoop()
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> 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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user