ajout static, renames, pere fouettard tweaks
This commit is contained in:
24
srcs/exec.c
24
srcs/exec.c
@@ -3,29 +3,29 @@
|
||||
/* ::: :::::::: */
|
||||
/* exec.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:30:28 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 15:32:57 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/01/26 16:29:49 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "philo.h"
|
||||
|
||||
void action_delay(t_philo *philo, int action_time)
|
||||
static void action_delay(t_philo *philo, int action_time)
|
||||
{
|
||||
struct timeval stime;
|
||||
int time_to_death;
|
||||
int death_time;
|
||||
|
||||
gettimeofday(&stime, NULL);
|
||||
time_to_death = philo->params->t_die - diff_time(philo->t_last_meal, stime);
|
||||
if (time_to_death > action_time)
|
||||
death_time = philo->params->t_die - diff_time(&philo->t_last_meal, &stime);
|
||||
if (death_time > action_time)
|
||||
usleep(action_time * 1000);
|
||||
else if (time_to_death > 0)
|
||||
else if (death_time > 0)
|
||||
usleep(philo->params->t_die * 1000);
|
||||
}
|
||||
|
||||
int ret_err_unlock(t_philo *philo, int nbr_fork)
|
||||
static int ret_err_unlock(t_philo *philo, int nbr_fork)
|
||||
{
|
||||
pthread_mutex_unlock(&philo->m_fork);
|
||||
if (nbr_fork == 2)
|
||||
@@ -33,7 +33,7 @@ int ret_err_unlock(t_philo *philo, int nbr_fork)
|
||||
return (1);
|
||||
}
|
||||
|
||||
int eat(t_philo *philo)
|
||||
static int eat(t_philo *philo)
|
||||
{
|
||||
pthread_mutex_lock(&(philo->m_fork));
|
||||
if (print_message(philo, WHITE, "has taken a fork"))
|
||||
@@ -44,9 +44,9 @@ int eat(t_philo *philo)
|
||||
update_time(philo);
|
||||
if (print_message(philo, B_YELLOW, "is eating"))
|
||||
return (ret_err_unlock(philo, 2));
|
||||
philo->eat++;
|
||||
if (philo->eat == philo->params->n_eat)
|
||||
philo->global->n_eat++;
|
||||
philo->eat_count++;
|
||||
if (philo->eat_count == philo->params->n_eat)
|
||||
philo->global->satiated_count++;
|
||||
action_delay(philo, philo->params->t_eat);
|
||||
pthread_mutex_unlock(&(philo->next->m_fork));
|
||||
pthread_mutex_unlock(&(philo->m_fork));
|
||||
|
||||
Reference in New Issue
Block a user