Les ascenseurs en premier

This commit is contained in:
Antoine Bartuccio 2018-06-11 02:31:03 +02:00
parent ab0e742cd4
commit e52cb25c55
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 6 additions and 11 deletions

View File

@ -11,7 +11,7 @@ GETTER(Resident, int, apartment_floor);
void * runnable_Resident(void * void_this){
Resident * this = (Resident*) void_this;
printf("Je suis le RESIDENT %s et je suis a l'etage %d en direction de l'etage %d\n",
printf("Je suis le resident %s et je suis a l'etage %d en direction de l'etage %d\n",
this->name, this->apartment_floor, this->destination);
return NULL;
}

View File

@ -29,15 +29,12 @@ int call_elevator_SharedData(THIS(SharedData), int starting_floor, int destinati
return 0;
}
/* void * runnable_type(void* void_this) */
void start_thread_SharedData(THIS(SharedData), void * (*thread)(void *), void * data, int thread_number){
pthread_create(&this->threads[thread_number], 0, thread, data);
}
void start_all_threads_SharedData(THIS(SharedData)){
int i = 0;
int elevator_index;
Element * current = NULL;
List * residents = NULL;
List * visitors = NULL;
@ -51,6 +48,11 @@ void start_all_threads_SharedData(THIS(SharedData)){
this->threads_nb = residents->get_size(residents) + visitors->get_size(visitors) + ELEVATOR_NB;
this->threads = malloc_or_die(sizeof(pthread_t) * this->threads_nb);
/* starts threading elevators */
for (i=0; i<ELEVATOR_NB; i++)
this->start_thread(this, this->main_building->elevators[i]->runnable,
this->main_building->elevators[i], i);
/* starts threading visitors */
current = visitors->get_head(visitors);
while (current != NULL){
@ -66,13 +68,6 @@ void start_all_threads_SharedData(THIS(SharedData)){
current = current->get_next(current);
i++;
}
/* starts threading elevators */
for (elevator_index=0; elevator_index<ELEVATOR_NB; elevator_index++){
this->start_thread(this, this->main_building->elevators[elevator_index]->runnable,
this->main_building->elevators[elevator_index], i);
i++;
}
}
}
}