Skip to content

Commit

Permalink
Merge pull request #47 from biralavor/46-building-let-philo-sleep-rou…
Browse files Browse the repository at this point in the history
…tine

46 building let philo sleep routine
  • Loading branch information
biralavor authored Oct 30, 2024
2 parents 1a6ba0b + ac500fc commit f6f3a67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 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/10/30 16:29:38 by umeneses ### ########.fr */
/* Updated: 2024/10/30 16:40:57 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -148,7 +148,8 @@ void printer_with_mutex_debug(t_philo_status status, t_philo *philo, bool debbug

/* dinner routines functions */
void let_philo_eat_routine(t_philo *philo);
void let_think_routine(t_philo *philo);
void let_philo_think_routine(t_philo *philo);
void let_philo_sleep_routine(t_philo *philo);

/* LIBFT utility functions */
int ft_strlen(const char *str);
Expand Down
6 changes: 3 additions & 3 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/10/30 16:29:27 by umeneses ### ########.fr */
/* Updated: 2024/10/30 16:39:45 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -58,7 +58,7 @@ void dinner_startup_runner(t_table *table)
if (table->philo->full) // TODO: thread safe
break ;
let_philo_eat_routine(table->philo);
let_think_routine(table->philo);
// let_sleep_routine(table->philo); // TODO
let_philo_think_routine(table->philo);
let_philo_sleep_routine(table->philo);
}
}
10 changes: 8 additions & 2 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/10/30 16:37:26 by umeneses ### ########.fr */
/* Updated: 2024/10/30 16:41:36 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -30,9 +30,15 @@ void let_philo_eat_routine(t_philo *philo)
safe_mutex_handler(&philo->second_chops->chops_mtx, UNLOCK);
}

void let_think_routine(t_philo *philo)
void let_philo_think_routine(t_philo *philo)
{
printer_with_mutex(THINKING, philo, false);
// safe_mutex_handler(philo->philo_mtx, LOCK);
// safe_mutex_handler(philo->philo_mtx, UNLOCK);
}

void let_philo_sleep_routine(t_philo *philo)
{
printer_with_mutex(SLEEPING, philo, false);
precise_usleep(philo->table->set->time_to_sleep, philo->table);
}

0 comments on commit f6f3a67

Please sign in to comment.