Skip to content

Commit

Permalink
Merge pull request #87 from biralavor/86-set-philo-think-routine-to-o…
Browse files Browse the repository at this point in the history
…nly-after-eating

86 set philo think routine to only after eating
  • Loading branch information
biralavor authored Nov 4, 2024
2 parents a60375d + 8a05d53 commit 80d465b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions philo/headers/philo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 16:04:11 by umeneses #+# #+# */
/* Updated: 2024/11/04 12:45:31 by umeneses ### ########.fr */
/* Updated: 2024/11/04 15:00:21 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -159,7 +159,7 @@ void philos_in_async_mode(t_philo *philo);

/* dinner routines functions */
void let_philo_eat_routine(t_philo *philo);
void let_philo_think_routine(t_philo *philo);
void let_philo_think_routine(t_philo *philo, bool before_spinlock);
void let_philo_sleep_routine(t_philo *philo);
bool is_philo_dead_manager(t_philo *philo);
void *lonely_philo_routine(void *data);
Expand Down
4 changes: 2 additions & 2 deletions philo/src/08.dinner_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/29 10:01:45 by umeneses #+# #+# */
/* Updated: 2024/11/03 17:46:51 by umeneses ### ########.fr */
/* Updated: 2024/11/04 15:09:04 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -61,7 +61,7 @@ void *dinner_runner(void *data)
break ;
let_philo_eat_routine(philo);
let_philo_sleep_routine(philo);
let_philo_think_routine(philo);
let_philo_think_routine(philo, false);
}
return (NULL);
}
4 changes: 2 additions & 2 deletions philo/src/10.synchronizers.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/29 15:42:40 by umeneses #+# #+# */
/* Updated: 2024/11/03 17:46:14 by umeneses ### ########.fr */
/* Updated: 2024/11/04 14:59:17 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -48,6 +48,6 @@ void philos_in_async_mode(t_philo *philo)
else
{
if (philo->id % 2 == 1)
let_philo_think_routine(philo);
let_philo_think_routine(philo, true);
}
}
7 changes: 4 additions & 3 deletions philo/src/12.dinner_routines.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:19:23 by umeneses #+# #+# */
/* Updated: 2024/11/04 12:45:31 by umeneses ### ########.fr */
/* Updated: 2024/11/04 15:02:28 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -71,12 +71,13 @@ void let_philo_eat_routine(t_philo *philo)
safe_mutex_handler(&philo->second_chops->chops_mtx, UNLOCK);
}

void let_philo_think_routine(t_philo *philo)
void let_philo_think_routine(t_philo *philo, bool before_spinlock)
{
long think_time;

think_time = 0;
printer_with_mutex(THINKING, philo, DEBUG_MODE);
if (!before_spinlock)
printer_with_mutex(THINKING, philo, DEBUG_MODE);
if (philo->table->set.total_philos % 2 == 0)
return ;
else
Expand Down

0 comments on commit 80d465b

Please sign in to comment.