#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)); 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; } void pthread_monano_thread_execution(pthread_monano_t* t, pthread_monano_id_t id) { struct timespec starttime, currenttime; int i; clock_gettime(CLOCK_REALTIME, &starttime); do{ clock_gettime(CLOCK_REALTIME, ¤ttime); if ((t->attr[id].delay.tv_sec!=0)||(t->attr[id].delay.tv_nsec!=0)){ if (ts_compare(currenttime,t->attr[id].departure_selfsuspension)==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"); } } }while (ts_compare(ts_substract(currenttime,starttime),t->attr[id].wcet)<0); } void 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); }