mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-11-24 18:14:19 +00:00
PREEMPTE
This commit is contained in:
parent
7315e1595e
commit
f066e22419
@ -168,8 +168,8 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
|
|||||||
this->waiting_passengers->insert_tail(this->waiting_passengers, (void*) passenger, sizeof(Passenger));//todo : check if inside list
|
this->waiting_passengers->insert_tail(this->waiting_passengers, (void*) passenger, sizeof(Passenger));//todo : check if inside list
|
||||||
}
|
}
|
||||||
pthread_cond_wait(this->condition_floors[origin], this->mutex_cond_get_inside_elevator);
|
pthread_cond_wait(this->condition_floors[origin], this->mutex_cond_get_inside_elevator);
|
||||||
elevator_number = this->get_inside_elevator(this, origin, passenger);
|
|
||||||
|
|
||||||
|
elevator_number = this->get_inside_elevator(this, origin, passenger);
|
||||||
if (elevator_number != -1){ //passenger accepted in elevator
|
if (elevator_number != -1){ //passenger accepted in elevator
|
||||||
if (passenger->type == RESIDENT)
|
if (passenger->type == RESIDENT)
|
||||||
printf("Le résident %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->get_name(passenger),
|
printf("Le résident %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->get_name(passenger),
|
||||||
@ -191,7 +191,7 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
|
|||||||
else if (passenger->type == VISITOR)
|
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);
|
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
|
//reloading fire
|
||||||
this->go_to_floor(this, origin, destination, passenger);
|
//this->go_to_floor(this, origin, destination, passenger);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ int get_next_floor_Elevator(THIS(Elevator)){
|
|||||||
for(i=0;i<this->passengers->get_size(this->passengers);i++){
|
for(i=0;i<this->passengers->get_size(this->passengers);i++){
|
||||||
temp_element = this->passengers->get_element(this->passengers, i);
|
temp_element = this->passengers->get_element(this->passengers, i);
|
||||||
temp_passenger = (Passenger*) temp_element->get_data(temp_element);
|
temp_passenger = (Passenger*) temp_element->get_data(temp_element);
|
||||||
temp_floor = temp_passenger->type == RESIDENT ? temp_passenger->resident->destination : temp_passenger->visitor->destination;
|
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);
|
min_diff = abs(this->floor - temp_floor);
|
||||||
next_floor = temp_floor;
|
next_floor = temp_floor;
|
||||||
|
Loading…
Reference in New Issue
Block a user