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

wirehaze git hosting

add ppos/
[ppos.git] / ppos / test / pingpong-scheduler.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 do escalonador com prioridades dinâmicas
9
10 #include <assert.h>
11 #include "lib/libc.h"
12 #include "ppos.h"
13
14 static struct task_t *pang, *peng, *ping, *pong, *pung;
15
16 // corpo das tarefas
17 void body(void *arg)
18 {
19 printf("%s: inicio (prioridade %d)\n", (char *)arg, sched_getprio(NULL));
20
21 for (int i = 0; i < 10; i++)
22 {
23 printf("%s: %d\n", (char *)arg, i);
24 task_yield();
25 }
26 printf("%s: fim\n", (char *)arg);
27 task_exit(0);
28 }
29
30 // corpo da tarefa principal
31 void user_main(void *arg)
32 {
33 printf("user: inicio\n");
34
35 // cria tarefas
36 pang = task_create("pang", body, "\tPang");
37 assert(pang);
38 peng = task_create("peng", body, "\t\tPeng");
39 assert(peng);
40 ping = task_create("ping", body, "\t\t\tPing");
41 assert(ping);
42 pong = task_create("pong", body, "\t\t\t\tPong");
43 assert(pong);
44 pung = task_create("pung", body, "\t\t\t\t\tPung");
45 assert(pung);
46
47 // ajusta prioridades
48 sched_setprio(pang, 0);
49 sched_setprio(peng, 2);
50 sched_setprio(ping, 4);
51 sched_setprio(pong, 6);
52 sched_setprio(pung, 8);
53
54 printf("user: fim\n");
55
56 task_exit(0);
57 }