mirror of
				https://gitlab.com/klmp200/LO41.git
				synced 2025-10-30 08:43:54 +00:00 
			
		
		
		
	A mort les state, mais la préemption est toujours forte vis-à-vis des résidents
This commit is contained in:
		| @@ -37,8 +37,8 @@ void add_passenger_Elevator(THIS(Elevator), Passenger * passenger){ | ||||
| 	       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); | ||||
| 	/*if (this->passengers->get_size(this->passengers) >= MAX_ELEVATOR_CAPACITY) | ||||
| 	  this->set_state(this, SLEEPING);*/ | ||||
| 	pthread_mutex_unlock(&this->mutex_passengers); | ||||
| } | ||||
|  | ||||
| @@ -107,8 +107,10 @@ 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 == WAITING &&*/ this->floor == floor); | ||||
|  | ||||
| 	if(this->floor != floor) | ||||
| 	  printf("DEBUG : Cause de la préemption : l'ascenseur %s n'est pas là !\n", this->name); | ||||
| 	pthread_mutex_unlock(&this->mutex_floor); | ||||
| 	pthread_mutex_unlock(&this->mutex_state); | ||||
| 	pthread_mutex_unlock(&this->mutex_passengers); | ||||
| @@ -134,12 +136,19 @@ void *runnable_Elevator(void * void_this){ | ||||
| 	printf("Initialisation de l'ascenseur %s\n", this->name); | ||||
| 	for (;;){ | ||||
| 		building->signal_elevator_at_floor(data->main_building, this->get_floor(this)); | ||||
| 		usleep(500000); | ||||
| 		if(this->target_floor == this->get_floor(this)){ | ||||
| 			if((next_passenger_stop = this->get_next_passenger_stop(this)) != -1){ | ||||
| 				this->target_floor = next_passenger_stop; | ||||
| 			}else if((next_call = building->get_next_call(building, this->floor)) != -1){ | ||||
| 				this->target_floor = next_call; | ||||
| 			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 != -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user