#include #include #include #include #include #include #include #include #include "returncode.h" #include "ts.h" #include "monano.h" #include "monano_data.h" struct pthread_monano_list *dependencies_list=NULL; struct pthread_monano_list *processor_speed_list=NULL; struct pthread_monano_list *thread_preemption_list=NULL; //add a thread in a list at the begin pthread_monano_list* pthread_monano_add_thread(pthread_monano_list* l, pthread_monano_id_t val) { pthread_monano_list* n=malloc(sizeof(pthread_monano_list)); printf("sizeof pthread_monano_list,%d\n", sizeof(pthread_monano_list)); n->id=val; n->suivant=l; return n; } // to find if a thread is in a list pthread_monano_list* pthread_monano_search_thread(pthread_monano_list* l, pthread_monano_id_t val) { pthread_monano_list* n=l; while(n != NULL) { if (n->id==val) return n; n=n->suivant; } return NULL; } //remove a thread in a list pthread_monano_list* pthread_monano_remove_thread(pthread_monano_list* l) { if(l!=NULL){ pthread_monano_list* n =l->suivant; free(l); return n; } else return NULL; } pthread_monano_id_t pthread_monano_head_thread(pthread_monano_list* l) { return l->id; } /*to have the number of thread in the list */ int pthread_monano_count_thread(pthread_monano_list* l){ pthread_monano_list* n=l; int nb=0; while(n != NULL) { nb++; n=n->suivant; } return nb; } int pthread_monano_thread_execution(pthread_monano_t* t, pthread_monano_id_t id) { struct timespec starttime, currenttime; pthread_monano_attr_t attr; struct timespec wcet, delay, self_suspension; int i; clock_gettime(CLOCK_REALTIME, &starttime); printf("debut de thread_execution de %x \n",pthread_self() ); attr=pthread_monano_get_attribute(t, id); wcet=pthread_monano_attr_getwcet(attr); delay=pthread_monano_attr_getdelay(attr); self_suspension=pthread_monano_attr_getdeparture_selfsuspension(attr); do{ clock_gettime(CLOCK_REALTIME, ¤ttime); if ((delay.tv_sec!=0)&&(delay.tv_nsec!=0)){ if(ts_compare(currenttime,self_suspension)==0){ // measure_start(&measure_ts_start); for (i=0; i<1000;i++) pthread_monano_signal_departure_selfsuspending_time(t,id); // measure_end(measure_ts_start, "departure_selfsuspending_time"); nanosleep(&t->attr[id].delay, NULL); // measure_start(&measure_ts_start); for (i=0; i<1000;i++) pthread_monano_signal_end_selfsuspending_time(t,id); // measure_end(measure_ts_start, "end_selfsuspending_time"); } } attr=pthread_monano_get_attribute(t, id); }while (ts_compare(ts_substract(currenttime,starttime),ts_add(wcet,pthread_monano_attr_getpreemption_time(attr)))<0); printf("fin de thread_execution de %x \n",pthread_self() ); return 0; } int pthread_monano_thread_interruption(struct timespec h) { struct timespec starttime_interruption, currenttime; clock_gettime(CLOCK_REALTIME, &starttime_interruption); do{ clock_gettime(CLOCK_REALTIME, ¤ttime); }while (ts_compare(ts_substract(currenttime,starttime_interruption),h)<0); return 0; }