Browse Source

Normalement c'est réglé, enfin

master
Antoine Bartuccio 1 year ago
parent
commit
b00cb030be
Signed by: klmp200 <klmp200@klmp200.net> GPG Key ID: E7245548C53F904B
3 changed files with 21 additions and 15 deletions
  1. +15
    -13
      SharedData/SharedData.c
  2. +5
    -1
      Visitor/Visitor.c
  3. +1
    -1
      main.c

+ 15
- 13
SharedData/SharedData.c View File

@@ -38,7 +38,7 @@ void start_all_threads_SharedData(THIS(SharedData)){
else {
residents = this->main_building->residents;
visitors = this->main_building->visitors;
this->threads_nb = residents->get_size(residents) + visitors->get_size(visitors) + ELEVATOR_NB;
this->threads_nb = residents->get_size(residents) + visitors->get_size(visitors) + ELEVATOR_NB + 1;
this->threads = malloc_or_die(sizeof(pthread_t*) * this->threads_nb);

for (i=0; i < this->threads_nb; i++)
@@ -49,35 +49,37 @@ void start_all_threads_SharedData(THIS(SharedData)){

/* starts threading elevators */
for (i=1; i<ELEVATOR_NB; i++) {
for (i=0; i<ELEVATOR_NB; i++) {
this->start_thread(this, this->main_building->elevators[i]->runnable,
this->main_building->elevators[i], i);
this->main_building->elevators[i]->set_thread_number(this->main_building->elevators[i], i);
}

/* starts threading visitors */
current = visitors->get_head(visitors);
/* starting the elevator breaker */
this->start_thread(this, this->elevator_breaker->runnable, this->elevator_breaker, i);
this->elevator_breaker->set_thread_number(this->elevator_breaker, i);
i++;

/* starts threading residents */
current = residents->get_head(residents);
while (current != NULL){
this->start_thread(this, ((Visitor*)current->get_data(current))->runnable, current->get_data(current), i);
((Visitor*)current->get_data(current))->set_thread_number((Visitor*)current->get_data(current), i);
this->start_thread(this, ((Resident*)current->get_data(current))->runnable, current->get_data(current), i);
((Resident*)current->get_data(current))->set_thread_number((Resident*)current->get_data(current), i);
current = current->get_next(current);
this->active_passengers++;
i++;
}

/* starts threading residents */
current = residents->get_head(residents);
/* starts threading visitors */
current = visitors->get_head(visitors);
while (current != NULL){
this->start_thread(this, ((Resident*)current->get_data(current))->runnable, current->get_data(current), i);
((Resident*)current->get_data(current))->set_thread_number((Resident*)current->get_data(current), i);
this->start_thread(this, ((Visitor*)current->get_data(current))->runnable, current->get_data(current), i);
((Visitor*)current->get_data(current))->set_thread_number((Visitor*)current->get_data(current), i);
current = current->get_next(current);
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);

+ 5
- 1
Visitor/Visitor.c View File

@@ -23,7 +23,11 @@ void * runnable_Visitor(void * void_this){

printf("Visiteur %s : Je souhaite rendre visite a %s\n", this->name, this->contact_name);
printf("Visiteur %s : J'apelle à l'interphone\nVisiteur %s : J'apprends que %s habite à l'étage %d\n", this->name, this->name, this->contact_name, (this->destination = data->use_call_box(data, this->contact_name)));
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);
if (this->destination == this->position)
printf("Visiteur %s : pas besoin de prendre l'ascenseur pour cet étage, je vais y aller à pied\n", this->name);
else
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);

data->decrement_active_passengers(data);
data->unregister_thread(data, this->thread_number);
return NULL;

+ 1
- 1
main.c View File

@@ -23,7 +23,7 @@ int main(int argc, char* argv[]) {
if(argc == 3){
shared_data->set_main_building(shared_data, NEW(Building, argv[1], argv[2]));
} else if (argc == 1){
shared_data->set_main_building(shared_data, NEW(Building, "../residents.txt", "../visitors.txt"));
shared_data->set_main_building(shared_data, NEW(Building, "../Scripts/residents_500.txt", "../Scripts/visitors_500.txt"));
} else{
CRASH("Arguments invalides\nUsage : ./LO41 [residents_file visitors_file]\n");
}

Loading…
Cancel
Save