Commit 0512b30f by Tobias Langer

Minor fixes with timing and task termination.

parent 0c8665f9
...@@ -127,11 +127,19 @@ static void TaskStarter() ...@@ -127,11 +127,19 @@ static void TaskStarter()
auto& node = embb::mtapi::Node::GetInstance(); auto& node = embb::mtapi::Node::GetInstance();
/* Storage for any task which is started. */ /* Storage for any task which is started. */
std::vector<embb::mtapi::Task> running; std::vector<embb::mtapi::Task> running;
/* Storage for task parameters. */
std::vector<std::pair<int,int>> running_num;
auto hyperperiod = calculate_hyperperiod(); auto hyperperiod = calculate_hyperperiod();
/* Storage for task parameters. */
int task_cnt = 0;
for(int i = 0; i < taskset_length; i++) {
node.CreateAction(ACTION_ID + i + 1, IdleTask);
task_cnt += hyperperiod / taskset[i].period;
std::cout << "Task " << i << " wcet: " << taskset[i].wcet << " period: " << taskset[i].period << " deadline: " << taskset[i].deadline << std::endl;
}
std::vector<std::pair<int,int>> running_num(task_cnt);
int task_ptr = 0;
using namespace std::chrono; using namespace std::chrono;
start = base_clock::now(); start = base_clock::now();
...@@ -169,11 +177,10 @@ static void TaskStarter() ...@@ -169,11 +177,10 @@ static void TaskStarter()
* to make sure that all possible running tasks can access their * to make sure that all possible running tasks can access their
* parameters. * parameters.
*/ */
running_num.push_back(std::make_pair(i,count)); running_num[task_ptr++] = std::make_pair(i,count);
node.CreateAction(ACTION_ID + i + 1, IdleTask);
auto job = node.GetJob(ACTION_ID + i + 1, DOMAIN_ID); auto job = node.GetJob(ACTION_ID + i + 1, DOMAIN_ID);
int tmp; auto t = node.Start(job, &running_num.back(), &tmp); int tmp; auto t = node.Start(job, &running_num[task_ptr - 1], &tmp);
/* Store task to wait for it. */ /* Store task to wait for it. */
running.push_back(t); running.push_back(t);
...@@ -181,6 +188,17 @@ static void TaskStarter() ...@@ -181,6 +188,17 @@ static void TaskStarter()
} }
} }
auto wait_start = base_clock::now();
while(min.count() > 0 && running.size() > 0) {
auto status = running.front().Wait(min.count()); // TODO factor for anything bigger than milliseconds
if(status == MTAPI_SUCCESS) {
running.erase(running.begin());
}
auto remain = duration_cast<cpp_time_base>(wait_start - base_clock::now());
if(remain.count() > 0) {
min -= remain;
}
}
std::this_thread::sleep_for(min); std::this_thread::sleep_for(min);
cur_time = duration_cast<cpp_time_base>(base_clock::now() - start); cur_time = duration_cast<cpp_time_base>(base_clock::now() - start);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment