From 27b2f7d1d2b6f9fedcadf1d4052e5ed86a0080ac Mon Sep 17 00:00:00 2001
From: "remi.greub" <remi.greub@hes-so.ch>
Date: Mon, 14 Apr 2025 12:43:46 +0200
Subject: [PATCH] modifs city.h et main.c

---
 G17_bykes/city.h | 29 +++++++++++++++--------------
 G17_bykes/main.c |  2 --
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/G17_bykes/city.h b/G17_bykes/city.h
index c1c5940..317b287 100644
--- a/G17_bykes/city.h
+++ b/G17_bykes/city.h
@@ -11,25 +11,26 @@
 #include <semaphore.h>
 
 
-#define CITY_CAPACITY_MIN 2
-#define DEPOT  0
-#define USLEEP 0
+#define CITY_CAPACITY_MIN 2 //min nb of bikes
+#define DEPOT  0        //depot's index
+
+#define USLEEP 1        //activate usleep() = 1 or no = 0
 
 struct terminal{
-    int nb_bikesParked;
-    int nb_P_waiting;
-    sem_t *sem_FreeSlot;
-    sem_t *sem_BikeFree;
-    pthread_mutex_t *mutex;
+    int nb_bikesParked; //number of bikes parked in terminal
+    int nb_P_waiting;   //number of persons waiting in terminal
+    sem_t *sem_FreeSlot;    //semaphore of the free parking slots -> one each terminal
+    sem_t *sem_BikeFree;    //semaphore of the free bike -> one each terminal
+    pthread_mutex_t *mutex; //mutex -> one for each terminal
 };
 
 struct city{
-    int npersons;
-    int nSlots;
-    int nTerminal;
-    int personsFinished;
-    pthread_barrier_t b;
-    struct terminal *terminals;
+    int npersons;   //nb of persons in the city
+    int nSlots;     //nb of slots for each terminal
+    int nTerminal;  //nb of terminals in the city
+    int personsFinished;    //nb of persons that finished it's iterations
+    pthread_barrier_t b;    //barrier to wait for every person before ending the programm
+    struct terminal *terminals; //all the terminals in the city
 };
 
 void init_city(struct city* city, int nbTerminals, int npersons, int nbSlots);
diff --git a/G17_bykes/main.c b/G17_bykes/main.c
index 74519e5..cc2b337 100644
--- a/G17_bykes/main.c
+++ b/G17_bykes/main.c
@@ -29,10 +29,8 @@ int main(int argc, char **argv){
     struct person *persons = malloc(sizeof(struct person)*nbpersons);
     struct Truck truck;
     init_city(&city, nbterminals, nbpersons, nbslots);
-    printf("COUOCU COUCOU COUCOU %d\n",city.npersons);
     init_civilians(persons, &city, nbTravels);
     init_truck(&truck, &city);
-    printf("COUOCU COUCOU COUCOU \n");
 
     if(pthread_create(threadTruck, NULL, trucks, (void*)&truck)!=0){
         perror("thread creation error");
-- 
GitLab