From: Lukas Jiriste Date: Tue, 26 Mar 2024 08:55:55 +0000 (+0100) Subject: Change the context of the time variables X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=241a1231dff0a1236ff42c580cc5a356397c7b55;p=42%2Fphilosophers.git Change the context of the time variables 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)? --- diff --git a/philo/philo.h b/philo/philo.h index a618cd5..5b27c95 100644 --- a/philo/philo.h +++ b/philo/philo.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -17,16 +17,19 @@ # include # include +// 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;