1
0
mirror of https://gitlab.com/klmp200/LO41.git synced 2024-11-21 16:23:22 +00:00

fixed a bug. I think ???

This commit is contained in:
Aethor 2018-06-21 21:34:34 +02:00
parent 653734ec1f
commit 036d4b55b7
2 changed files with 7 additions and 13 deletions

View File

@ -204,13 +204,6 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
elevator_number = this->get_inside_elevator(this, origin, passenger);
if (elevator_number != -1){ //passenger accepted in elevator
this->waiting_floors[origin]--;//on retire de la liste des attentes
if (passenger->type == RESIDENT)
printf("Le résident %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->get_name(passenger),
this->elevators[elevator_number]->name, origin);
else if (passenger->type == VISITOR)
printf("Le visiteur %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->get_name(passenger),
this->elevators[elevator_number]->name, origin);
pthread_cond_wait(this->condition_floors[destination], this->mutex_cond_get_outside_elevator);
this->elevators[elevator_number]->remove_passenger(this->elevators[elevator_number], passenger);
}else{
@ -219,7 +212,7 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
else if (passenger->type == VISITOR)
printf("Le visiteur %s à l'étage %d n'a pas pu rentrer dans un ascenseur. Préempté !\n", passenger->get_name(passenger), origin);
//reloading fire
//this->go_to_floor(this, origin, destination, passenger);
this->go_to_floor(this, origin, destination, passenger);
}
}

View File

@ -33,8 +33,9 @@ void _free__Elevator(THIS(Elevator)){
void add_passenger_Elevator(THIS(Elevator), Passenger * passenger){
pthread_mutex_lock(&this->mutex_passengers);
this->passengers->insert_tail(this->passengers, ((void *)passenger), sizeof(Passenger));
printf("L'ascenseur %s recoit le visiteur %s\nIl y a maintenant %d passagers dans l'ascenseur %s\n", this->name,
printf("L'ascenseur %s recoit le visiteur %s à l'étage %d\nIl y a maintenant %d passagers dans l'ascenseur %s\n", this->name,
passenger->get_name(passenger),
this->get_floor(this),
this->passengers->get_size(this->passengers), this->name);
if (this->passengers->get_size(this->passengers) >= MAX_ELEVATOR_CAPACITY)
this->set_state(this, SLEEPING);
@ -87,7 +88,7 @@ int get_next_passenger_stop_Elevator(THIS(Elevator)){
temp_element = this->passengers->get_element(this->passengers, i);
temp_passenger = (Passenger*) temp_element->get_data(temp_element);
temp_floor = temp_passenger->get_destination(temp_passenger);
if(abs(this->floor - temp_floor) < min_diff && temp_floor != this->floor){
if(abs(this->floor - temp_floor) < min_diff /*&& temp_floor != this->floor*/){
min_diff = abs(this->floor - temp_floor);
next_floor = temp_floor;
}
@ -141,13 +142,13 @@ void *runnable_Elevator(void * void_this){
}
}
if(this->get_floor(this) != this->target_floor){
this->set_floor(this, this->target_floor);
printf("Ascenseur %s en route vers l'étage %d\n", this->name, this->target_floor);
printf("DEBUG : Next passenger stop : %d\n", next_passenger_stop);
/*printf("DEBUG : Next passenger stop : %d\n", next_passenger_stop);
printf("DEBUG : Next call from user : %d\n", next_call);
printf("\n\n");
printf("\n\n");*/
fflush(stdout);
}
this->set_floor(this, this->target_floor);
}
return NULL;