diff --git a/Building/Building.c b/Building/Building.c index d830fc2..54b1ae6 100644 --- a/Building/Building.c +++ b/Building/Building.c @@ -206,7 +206,9 @@ 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 + pthread_mutex_lock(this->mutex_cond_get_outside_elevator); pthread_cond_wait(this->condition_floors[destination], this->mutex_cond_get_outside_elevator); + pthread_mutex_unlock(this->mutex_cond_get_outside_elevator); this->elevators[elevator_number]->remove_passenger(this->elevators[elevator_number], passenger); }else{ if (passenger->type == RESIDENT) diff --git a/Elevator/Elevator.c b/Elevator/Elevator.c index 31dd3ed..b831668 100644 --- a/Elevator/Elevator.c +++ b/Elevator/Elevator.c @@ -33,7 +33,7 @@ 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 à l'étage %d\nIl y a maintenant %d passagers dans l'ascenseur %s\n", this->name, + printf("L'ascenseur %s recoit le passager %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); @@ -140,23 +140,20 @@ void *runnable_Elevator(void * void_this){ if(this->target_floor == this->get_floor(this)){ next_passenger_stop = this->get_next_passenger_stop(this); next_call = building->get_next_call(building, this->floor); - if (!(next_passenger_stop == this->get_floor(this) || next_call == this->get_floor(this))){ - printf("Ascenseur %s attends pour déposer ou prendre un pasager supplémentaire\n", this->name); + if (next_passenger_stop == this->get_floor(this) || next_call == this->get_floor(this)){ + printf("Ascenseur %s attends pour déposer ou prendre un passager supplémentaire\n", this->name); //while pour attendre ? + }else{ if(next_passenger_stop != -1){ this->target_floor = next_passenger_stop; }else if(next_call != -1){ this->target_floor = next_call; - } + } } } 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 call from user : %d\n", next_call); - printf("\n\n");*/ - fflush(stdout); } } diff --git a/Elevator/Elevator.h b/Elevator/Elevator.h index a5f847b..a0f44cb 100644 --- a/Elevator/Elevator.h +++ b/Elevator/Elevator.h @@ -11,7 +11,7 @@ #include "../Passenger/Passenger.h" //#define MAX_ELEVATOR_CAPACITY 10 -#define MAX_ELEVATOR_CAPACITY 3 +#define MAX_ELEVATOR_CAPACITY 10 typedef enum {RUNNING, WAITING, SLEEPING, BROKEN} ELEVATOR_STATE; diff --git a/Resident/Resident.c b/Resident/Resident.c index ede284f..4b8d2d7 100644 --- a/Resident/Resident.c +++ b/Resident/Resident.c @@ -25,7 +25,10 @@ void * runnable_Resident(void * void_this){ 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); - data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger); + if(this->position == this->destination) + printf("Résident %s : je reste chez moi\n", this->name); + else + data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger); return NULL; }