Change the context of the time variables
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 26 Mar 2024 08:55:55 +0000 (09:55 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 26 Mar 2024 08:55:55 +0000 (09:55 +0100)
This change is preliminary as the code that handles this is yet to be
written. I decided to do this because I think it will not add any
complexity but will make the code more portable (as useconds_t needs
not be huge this way)?

philo/philo.h

index a618cd5d0d9d39b85f0a82a67e4c2e83ea007ebe..5b27c95045df73e2ed46cca8ea1b1b8b151a2098 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/03/22 11:10:17 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/03/26 09:13:38 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/03/26 09:55:46 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 # include <pthread.h>
 # include <sys/time.h>
 
+//     The .start member holds the result of gettimeofday
+//     Every other member that holds time info counts
+//     microseconds from that point (in other structures also)
 typedef struct s_settings
 {
        int                             end;
        int                             should_check_hunger;
-       size_t                  philo_count;
-       suseconds_t             time_to_die;
-       suseconds_t             time_to_eat;
-       suseconds_t             time_to_sleep;
-       suseconds_t             start;
        unsigned int    min_eat_num;
+       useconds_t              time_to_die;
+       useconds_t              time_to_eat;
+       useconds_t              time_to_sleep;
+       size_t                  philo_count;
+       struct timeval  start;
        pthread_mutex_t terminal_lock;
        pthread_mutex_t end_lock;
 }                                      t_settings;
@@ -35,7 +38,7 @@ typedef struct s_philosopher
 {
        int                             num_eaten;
        size_t                  id;
-       suseconds_t             last_eaten;
+       useconds_t              last_eaten;
        t_settings              *settings;
        pthread_mutex_t *forks[2];
        pthread_mutex_t philo_lock;