logic: Fixed termination issues in task scheduling
* don't use thread::detach() in TaskGroupParallel::terminate to make it useful for tabs * properly terminate TaskFillIndexerCommandQueue * fixed wrong microsecond delays * moved some task delays to TaskDecoratorRepeat for better transparency
This commit is contained in:
@@ -4,12 +4,13 @@
|
||||
|
||||
TaskDecoratorDelay::TaskDecoratorDelay(size_t delayMS)
|
||||
: m_delayMS(delayMS)
|
||||
, m_delayComplete(delayMS == 0)
|
||||
, m_delayComplete(false)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskDecoratorDelay::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
m_delayComplete = (m_delayMS == 0);
|
||||
m_start = TimeStamp::now();
|
||||
}
|
||||
|
||||
@@ -20,8 +21,8 @@ Task::TaskState TaskDecoratorDelay::doUpdate(std::shared_ptr<Blackboard> blackbo
|
||||
return m_taskRunner->update(blackboard);
|
||||
}
|
||||
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_TIME_MS));
|
||||
const int SLEEP_TIME_MS = (m_delayMS / 3) + 1;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
|
||||
m_delayComplete = (TimeStamp::now().deltaMS(m_start) >= m_delayMS);
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include "TaskDecoratorRepeat.h"
|
||||
|
||||
TaskDecoratorRepeat::TaskDecoratorRepeat(ConditionType condition, TaskState exitState)
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
TaskDecoratorRepeat::TaskDecoratorRepeat(ConditionType condition, TaskState exitState, size_t delayMS)
|
||||
: m_condition(condition)
|
||||
, m_exitState(exitState)
|
||||
, m_delayMS(delayMS)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,6 +33,8 @@ Task::TaskState TaskDecoratorRepeat::doUpdate(std::shared_ptr<Blackboard> blackb
|
||||
break;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(m_delayMS));
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
CONDITION_WHILE_SUCCESS
|
||||
};
|
||||
|
||||
TaskDecoratorRepeat(ConditionType condition, TaskState exitState);
|
||||
TaskDecoratorRepeat(ConditionType condition, TaskState exitState, size_t delayMS);
|
||||
|
||||
private:
|
||||
void doEnter(std::shared_ptr<Blackboard> blackboard) override;
|
||||
@@ -25,6 +25,7 @@ private:
|
||||
|
||||
const ConditionType m_condition;
|
||||
const TaskState m_exitState;
|
||||
const size_t m_delayMS;
|
||||
};
|
||||
|
||||
#endif // TASK_DECORATOR_REPEAT_H
|
||||
|
||||
@@ -78,9 +78,13 @@ void TaskGroupParallel::doTerminate()
|
||||
for (size_t i = 0; i < m_tasks.size(); i++)
|
||||
{
|
||||
m_tasks[i]->taskRunner->terminate();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_tasks.size(); i++)
|
||||
{
|
||||
if (m_tasks[i]->thread)
|
||||
{
|
||||
m_tasks[i]->thread->detach();
|
||||
m_tasks[i]->thread->join();
|
||||
m_tasks[i]->thread.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,9 +44,6 @@ void TaskReturnSuccessIf<T>::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
template <typename T>
|
||||
Task::TaskState TaskReturnSuccessIf<T>::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_TIME_MS));
|
||||
|
||||
T lhsValue = 0;
|
||||
blackboard->get<T>(m_lhsValueName, lhsValue);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user