ppos

Usermode educational operating system.
Log | Files | Refs

pingpong-dispatcher.c (1315B)


      1 // PingPongOS - PingPong Operating System
      2 // © Prof. Carlos A. Maziero, DINF UFPR
      3 // Versão 2.1 -- 07/2026
      4 
      5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO;
      6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO.
      7 
      8 // Teste do dispatcher com escalonador FCFS
      9 
     10 #include <assert.h>
     11 #include "lib/pplibc.h"
     12 #include "syscall.h"
     13 
     14 struct task_t *pang, *peng, *ping, *pong, *pung;
     15 
     16 // corpo das tarefas
     17 void body(void *arg)
     18 {
     19     printk("%s (id %d): inicio\n",
     20            (char *)arg, task_id(NULL));
     21 
     22     for (int i = 0; i < 5; i++)
     23     {
     24         printk("%s: %d\n", (char *)arg, i);
     25         task_yield();
     26     }
     27     printk("%s: fim\n", (char *)arg);
     28     task_exit(NOERROR);
     29 }
     30 
     31 // corpo da tarefa principal
     32 void user_main(void *arg)
     33 {
     34     int id;
     35     char *name;
     36 
     37     name = task_name(NULL);
     38     id   = task_id(NULL);
     39     printk("%5u ms: %s (id %d): inicio\n", time(), name, id);
     40 
     41     // cria tarefas
     42     pang = task_create("pang", body, "\tPang");
     43     assert(pang);
     44     peng = task_create("peng", body, "\t\tPeng");
     45     assert(peng);
     46     ping = task_create("ping", body, "\t\t\tPing");
     47     assert(ping);
     48     pong = task_create("pong", body, "\t\t\t\tPong");
     49     assert(pong);
     50     pung = task_create("pung", body, "\t\t\t\t\tPung");
     51     assert(pung);
     52 
     53     printk("%5u ms: %s fim\n", time(), name);
     54 
     55     task_exit(NOERROR);
     56 }