This commit is contained in:
Aethor 2018-06-22 05:49:15 +02:00
parent 3334f77d22
commit 7f160f69f8
4 changed files with 44 additions and 35 deletions

View File

@ -243,7 +243,7 @@ void signal_elevator_at_floor_Building(THIS(Building), int floor){
void ask_elevator_reparation_Building(THIS(Building), Elevator* elevator){
printf("Technicien : l'ascenseur %s attend pour se faire réparer\n", elevator->name);
pthread_mutex_lock(&this->mutex_repair);
usleep(10000);
usleep(500000);
elevator->repair(elevator);
pthread_mutex_unlock(&this->mutex_repair);
printf("Technicien : l'ascenseur %s est maintenant réparé\n", elevator->name);

View File

@ -106,7 +106,7 @@ int can_get_inside_Elevator(THIS(Elevator), int floor){
pthread_mutex_lock(&this->mutex_floor);
permission = (this->passengers->get_size(this->passengers) < MAX_ELEVATOR_CAPACITY &&
/*this->state == WAITING &&*/ this->floor == floor);
this->state == RUNNING && this->floor == floor);
//if(this->floor != floor)
//printf("DEBUG : Cause de la préemption : l'ascenseur %s n'est pas là !\n", this->name);
@ -140,6 +140,7 @@ void *runnable_Elevator(void * void_this){
printf("Ascenseur %s : Initialisation...\n", this->name);
while (data->is_active_passengers_left(data)){
usleep(250000);
if(this->get_state(this) == RUNNING){
if(this->target_floor == this->get_floor(this)){
pthread_mutex_lock(&this->mutex_passengers);//on débarque les passagers
@ -171,6 +172,12 @@ void *runnable_Elevator(void * void_this){
this->set_floor(this, this->target_floor);
printf("Ascenseur %s : Je suis en route vers l'étage %d\n", this->name, this->target_floor);
}
}else if(this->get_state(this) == BROKEN){
building->ask_elevator_reparation(building, this);
}else{
//CRASH("ERROR : Undefined behaviour\n");
}
}
data->unregister_thread(data, this->thread_number);
@ -205,7 +212,7 @@ Elevator *_init_Elevator(char * name){
);
new_elevator->set_floor(new_elevator, 0);
new_elevator->set_state(new_elevator, WAITING);
new_elevator->set_state(new_elevator, RUNNING);
return new_elevator;
}

View File

@ -47,9 +47,6 @@ void start_all_threads_SharedData(THIS(SharedData)){
pthread_mutex_lock(&this->mutex_active_passengers);
pthread_mutex_lock(&this->mutex_threads);
/* starting the elevator breaker */
this->start_thread(this, this->elevator_breaker->runnable, this->elevator_breaker, 0);
this->elevator_breaker->set_thread_number(this->elevator_breaker, 0);
/* starts threading elevators */
for (i=1; i<ELEVATOR_NB; i++) {
@ -77,6 +74,11 @@ void start_all_threads_SharedData(THIS(SharedData)){
this->active_passengers++;
i++;
}
/* starting the elevator breaker */
this->start_thread(this, this->elevator_breaker->runnable, this->elevator_breaker, 0);
this->elevator_breaker->set_thread_number(this->elevator_breaker, 0);
pthread_mutex_unlock(&this->mutex_threads);
pthread_mutex_unlock(&this->mutex_active_passengers);
}