Commit b32b484a authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Refactored common code, made children waiting generic.

parent f58adda7
Pipeline #106 skipped
......@@ -39,7 +39,8 @@ VPATH=src
SRC= \
init.c \
task1.c \
task2.c
task2.c \
common.c
SUFFIX=$(CFG).$(FPU_SUFFIX).$(LEON)
......
#include "system.h"
#include <stdio.h>
void task_begin(int task_no)
{
printf("[TASK %d] Starting...\n", task_no);
fflush(stdout);
}
void task_end(int task_no)
{
rtems_event_send(g_init_task_id, RTEMS_EVENT_0 + task_no);
rtems_task_delete(RTEMS_SELF);
}
......@@ -44,22 +44,25 @@ rtems_task Init(rtems_task_argument argument)
i == 0 ? Task1_EntryPoint : Task2_EntryPoint,
i);
}
// To give coverage code room to breathe!
printf("[PARENT] Parent task waits for his children to complete...\n");
// To give coverage code the opportunity to work, wait for child tasks to die first.
// We use RTEMS events here, but you can use any sync API you want.
{
printf("[PARENT] Parent task waits for children to complete...\n");
rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
rtems_event_set in = (RTEMS_EVENT_0 | RTEMS_EVENT_1);
rtems_event_set in = 0;
for (i=0; i<TASKS; i++)
in |= (RTEMS_EVENT_0 + i);
rtems_event_set out;
rtems_event_set completed = 0;
while((completed & in) != (RTEMS_EVENT_0 | RTEMS_EVENT_1)) {
rtems_event_set non_completed = in;
while (non_completed) {
status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
if ( status == RTEMS_SUCCESSFUL ) {
completed |= out;
printf("[PARENT] Task completed!\n");
non_completed &= ~out;
printf("[PARENT] Child task completed.\n");
fflush(stdout);
}
}
printf("[PARENT] All tasks completed!\n");
printf("[PARENT] All tasks completed.\n");
fflush(stdout);
}
exit(0);
......
......@@ -6,6 +6,8 @@
rtems_task Init(rtems_task_argument argument);
rtems_task Task1_EntryPoint(rtems_task_argument argument);
rtems_task Task2_EntryPoint(rtems_task_argument argument);
void task_begin(int task_no);
void task_end(int task_no);
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 64
......
......@@ -4,8 +4,7 @@
rtems_task Task1_EntryPoint(rtems_task_argument argument)
{
int task_no = (int) argument;
printf("[TASK %d] Starting...\n", task_no);
fflush(stdout);
task_begin(task_no);
int j;
double d=task_no;
......@@ -16,6 +15,6 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument)
d*=1.0001;
}
printf("[TASK %d] Computed value was %ld\n", task_no, (long)d);
rtems_event_send(g_init_task_id, RTEMS_EVENT_0);
rtems_task_delete(RTEMS_SELF);
task_end(task_no);
}
......@@ -4,8 +4,7 @@
rtems_task Task2_EntryPoint(rtems_task_argument argument)
{
int task_no = (int) argument;
printf("[TASK %d] Starting...\n", task_no);
fflush(stdout);
task_begin(task_no);
int j;
long long int dummy = 0;
......@@ -16,6 +15,5 @@ rtems_task Task2_EntryPoint(rtems_task_argument argument)
dummy++;
}
printf("[TASK %d] Computed value was %lld\n", task_no, dummy);
rtems_event_send(g_init_task_id, RTEMS_EVENT_1);
rtems_task_delete(RTEMS_SELF);
task_end((int) argument);
}
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 to comment