-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcte.cpp
97 lines (93 loc) · 3.11 KB
/
pcte.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "pcte.h"
#include "chargement.h"
pcte::pcte(){
tme = 0;
tma = 0;
}
pcte::~pcte(){
}
void pcte::addProcess(Processus &proc){
l.ajouterProcessus(&proc);
}
void pcte::affectList(){
l = chargerDonneesDepuisFichier("C://Users//cheik//OneDrive//Bureau//data.txt");
}
void pcte::traiterProcessus(){
int nb_processes = l.listProcessSize();
int tour = 0;
int mustSort = 0;
while (!l.estVide()){
if (tour == 0)
mustSort = 1;
if(!processeur.estVide() && processeur.premierProcessus()->estEnCalcul() && processeur.premierProcessus()->getTeteTache().temps == 0){
Processus* proc = processeur.premierProcessus();
processeur.defiler();
proc->supprimerTache();
mustSort = 1;
}
if(!disque.estVide() && !disque.premierProcessus()->estEnCalcul() && disque.premierProcessus()->getTeteTache().temps == 0){
Processus* proc = disque.premierProcessus();
disque.defiler();
proc->supprimerTache();
}
l.init();
while (l.existe()){
Processus *proc = l.prochain();
if(proc){
if(!proc->tachesVide() && tour >= proc->getTempsArrivee()){
if(proc->estEnCalcul()){
if(!processeur.recherche(proc->getNomProcessus())){
processeur.enfiler(proc);
}
}
else{
if(!disque.recherche(proc->getNomProcessus()))
disque.enfiler(proc);
}
}
}
}
if(mustSort){
processeur.sortByTime();
mustSort = 0;
}
l.init();
while (l.existe()){
int iswaiting = 1;
Processus *proc = l.prochain();
if(proc && tour >= proc->getTempsArrivee()){
if(!proc->tachesVide() && !proc->estEnCalcul())
proc->setEtat("Bloque");
else if(!processeur.estVide() && processeur.estEnTete(proc->getNomProcessus())){
proc->setEtat("Actif");
iswaiting = 0;
}
else if(processeur.recherche(proc->getNomProcessus()))
proc->setEtat("Pret");
else if(proc->tachesVide()){
tma += proc->getTempsAttente();
proc->setTempsFin(tour + 1);
tme += (proc->getTempsFin() - proc->getTempsArrivee());
l.supprimer(proc->getNomProcessus());
}
if(iswaiting && !proc->tachesVide())
proc->upgradeWaiting();
}
}
if(!processeur.estVide()){
processeur.premierProcessus()->decrementerTempsDeTeteListeTache();
}
if(!disque.estVide()){
disque.premierProcessus()->decrementerTempsDeTeteListeTache();
}
tour++;
}
tma /= nb_processes;
tme /= nb_processes;
}
float pcte::getTme(){
return tme;
}
float pcte::getTma(){
return tma;
}