]> wirehaze git hosting - ppos.git/blob - ppos/test/pingpong-task3.c

wirehaze git hosting

add ppos/
[ppos.git] / ppos / test / pingpong-task3.c
1 // PingPongOS - PingPong Operating System
2 // Prof. Carlos A. Maziero, DINF UFPR
3 // Versão 2.0 -- Junho de 2025
4
5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO;
6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO.
7
8 // Teste da gestão básica de tarefas
9
10 #include <assert.h>
11 #include "lib/libc.h"
12 #include "ppos.h"
13
14 #define NUMTASKS 512
15
16 static struct task_t *task;
17
18 // corpo das tarefas
19 void body_task(void *)
20 {
21 printf("\tEstou na tarefa %5d\n", task_id(NULL));
22 task_switch(NULL);
23 }
24
25 // corpo da tarefa principal
26 void user_main(void *arg)
27 {
28 int status;
29 char *name = task_name(NULL);
30
31 printf("%s: inicio\n", name);
32
33 for (int i = 0; i < NUMTASKS; i++)
34 {
35 // cria a tarefa
36 task = task_create(NULL, body_task, NULL);
37 assert(task);
38
39 // ativa a tarefa
40 status = task_switch(task);
41 assert(status == NOERROR);
42
43 // após retornar, destroi o descritor
44 status = task_destroy(task);
45 assert(status == NOERROR);
46 }
47
48 printf("%s: fim\n", name);
49
50 task_switch(NULL);
51 }