/** * @fn void sim_int_clock(void) * Fonction appelée à chaque tick (= handler de SIGALRM) */ void sim_int_clock() { struct callo *p1; int courant; /* processus en cours d'exécution */ if(verbose) { printf("TICK\n"); fflush(stdout); /* affichage du vecteur de callout */ /* printTab(); */ } /* augmentation du nombre de ticks utilisés par le processus */ courant = GetElecProc(); Tproc[courant].p_tick++; /* test pour la commutation */ if(!--nbtick) { nbtick=Quantum; commut(NULL); } /* decrementer la premiere entree */ MASK_ALRM; if (v.ve_callout[0].c_func != 0) { p1 = &(v.ve_callout[0]); while(p1->c_time<=0 && p1->c_func!=0) p1++; p1->c_time--; } /* restart va-t-elle être appelée */ if((v.ve_callout[0].c_func!=0) && (v.ve_callout[0].c_time<=0)) restart_flag |= CALLOUT; UNMASK_ALRM; /* printf("*** MAJ ***\n"); */ /* printTab(); */ /* s'il y a de CALLOUT à traiter */ if(restart_flag & CALLOUT) { /* printf("CALLOUT\n"); */ fflush(stdout); /* s'il n'y a pas de CALLOUT en traitement */ if(!(restart_flag & RESTART_EXECUTION)) { /* printf("RESTART\n"); */ fflush(stdout); restart_flag &= ~CALLOUT; restart_flag |= RESTART_EXECUTION; restart(); restart_flag &= ~RESTART_EXECUTION; } else { /* printf("NO RESTART\n"); */ fflush(stdout); } } else ;/* printf("pas de restart\n"); */ }
void DeposerFile(t_fmsg *f, void *d) { /* Code du TP à ajouter */ while(f->nb_msg >= MAXMSG) tsleep(GetElecProc(),f->file_pleine); lock(); f->nb_msg++; f->deposer++; f->deposer %= MAXMSG; f->file[f->deposer].data = d; f->file[f->deposer].exp = GetElecProc() ; unlock(); twakeup(f->file_vide); }
void *RetirerFile(t_fmsg *f, int *exp) { /* Code du TP à ajouter */ while(f->nb_msg <= 0) tsleep(GetElecProc(),f->file_vide); lock(); f->nb_msg--; f->retirer++; f->retirer %= MAXMSG; *exp = f->file[f->retirer].exp ; unlock(); twakeup(f->file_pleine); return f->file[f->retirer].data; }