split files and norminette

This commit is contained in:
whaffman 2025-01-28 17:31:56 +01:00
parent 95ebe2b00b
commit 8cd796f8ac
31 changed files with 161 additions and 85 deletions

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:27:34 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:27:34 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:50 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:32 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:13:50 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:13:50 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:51 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:33 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,28 +6,12 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:44 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:44 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:51 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:34 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "philo.h" #include "philo.h"
int create_philo_mutexes(t_philo *philo)
{
philo->death_lock = malloc(sizeof(pthread_mutex_t));
philo->last_meal_lock = malloc(sizeof(pthread_mutex_t));
philo->n_eat_lock = malloc(sizeof(pthread_mutex_t));
if (!philo->death_lock || !philo->last_meal_lock || !philo->n_eat_lock)
return (FAILURE);
if (pthread_mutex_init(philo->death_lock, NULL))
return (FAILURE);
if (pthread_mutex_init(philo->last_meal_lock, NULL))
return (FAILURE);
if (pthread_mutex_init(philo->n_eat_lock, NULL))
return (FAILURE);
return (SUCCESS);
}
int create_mutexes(t_rules *rules) int create_mutexes(t_rules *rules)
{ {
int i; int i;

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* create_philo_mutexes.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/28 17:29:34 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/28 17:29:34 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "philo.h"
int create_philo_mutexes(t_philo *philo)
{
philo->death_lock = malloc(sizeof(pthread_mutex_t));
philo->last_meal_lock = malloc(sizeof(pthread_mutex_t));
philo->n_eat_lock = malloc(sizeof(pthread_mutex_t));
if (!philo->death_lock || !philo->last_meal_lock || !philo->n_eat_lock)
return (FAILURE);
if (pthread_mutex_init(philo->death_lock, NULL))
return (FAILURE);
if (pthread_mutex_init(philo->last_meal_lock, NULL))
return (FAILURE);
if (pthread_mutex_init(philo->n_eat_lock, NULL))
return (FAILURE);
return (SUCCESS);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:45 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:45 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:52 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:35 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:45 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:45 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:53 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:35 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:46 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:46 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:53 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:36 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:46 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:46 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:54 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:37 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:13:55 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:13:55 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:55 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:37 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:13:56 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:13:56 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:56 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:38 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:13:56 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:13:56 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:56 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:38 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:47 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:47 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:57 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:39 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,18 +6,12 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:48 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:48 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:58 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:39 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "philo.h" #include "philo.h"
void print_usage(void)
{
printf("Usage: ./philo n_philos time_to_die"
"time_to_eat time_to_sleep [n_must_eat]\n");
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
t_rules rules; t_rules rules;

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:13:59 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:13:59 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:59 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:40 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

21
philo/src/one_philo.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* one_philo.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/28 17:29:41 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/28 17:29:41 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "philo.h"
void one_philo(t_philo *philo)
{
pthread_mutex_lock(philo->l_fork);
print_status(philo, "has taken a fork");
pthread_mutex_unlock(philo->l_fork);
philo_sleep(philo, philo->rules->time_to_die);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:48 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:48 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:13:59 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:41 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:14:00 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:14:00 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:00 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:42 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,28 +6,12 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:14:01 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:14:01 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:01 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:42 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "philo.h" #include "philo.h"
void take_forks(t_philo *philo)
{
if (philo->id % 2 == 1)
{
pthread_mutex_lock(philo->r_fork);
print_status(philo, "has taken a fork");
}
pthread_mutex_lock(philo->l_fork);
print_status(philo, "has taken a fork");
if (philo->id % 2 != 1)
{
pthread_mutex_lock(philo->r_fork);
print_status(philo, "has taken a fork");
}
}
int philo_eat(t_philo *philo) int philo_eat(t_philo *philo)
{ {
take_forks(philo); take_forks(philo);

View File

@ -6,34 +6,12 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:49 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:26:49 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:02 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:43 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "philo.h" #include "philo.h"
void unlock_forks(t_philo *philo)
{
pthread_mutex_unlock(philo->l_fork);
pthread_mutex_unlock(philo->r_fork);
}
int think_time(t_rules *rules)
{
int res;
res = (rules->time_to_die - rules->time_to_eat - rules->time_to_sleep) / 5;
return (res);
}
void one_philo(t_philo *philo)
{
pthread_mutex_lock(philo->l_fork);
print_status(philo, "has taken a fork");
pthread_mutex_unlock(philo->l_fork);
philo_sleep(philo, philo->rules->time_to_die);
}
void *philo_routine(void *arg) void *philo_routine(void *arg)
{ {
t_philo *philo; t_philo *philo;

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:14:02 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:14:02 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:02 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:44 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

17
philo/src/print_usage.c Normal file
View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* print_usage.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/28 17:29:44 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/28 17:29:44 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
void print_usage(void)
{
printf("Usage: ./philo n_philos time_to_die"
"time_to_eat time_to_sleep [n_must_eat]\n");
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:14:03 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:14:03 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:03 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:45 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:14:04 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:14:04 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:04 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:46 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/27 14:14:04 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/27 14:14:04 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:04 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:46 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

29
philo/src/take_forks.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* take_forks.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/28 17:29:47 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/28 17:29:47 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "philo.h"
void take_forks(t_philo *philo)
{
if (philo->id % 2 == 1)
{
pthread_mutex_lock(philo->r_fork);
print_status(philo, "has taken a fork");
}
pthread_mutex_lock(philo->l_fork);
print_status(philo, "has taken a fork");
if (philo->id % 2 != 1)
{
pthread_mutex_lock(philo->r_fork);
print_status(philo, "has taken a fork");
}
}

21
philo/src/think_time.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* think_time.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/28 17:29:47 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/28 17:29:47 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "philo.h"
int think_time(t_rules *rules)
{
int res;
res = (rules->time_to_die - rules->time_to_eat - rules->time_to_sleep) / 5;
return (res);
}

19
philo/src/unlock_forks.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* unlock_forks.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/28 17:29:48 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/28 17:29:48 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "philo.h"
void unlock_forks(t_philo *philo)
{
pthread_mutex_unlock(philo->l_fork);
pthread_mutex_unlock(philo->r_fork);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:27:08 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:27:08 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:05 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:48 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:27:09 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:27:09 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:05 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:49 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:27:10 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:27:10 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:06 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:50 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */ /* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:27:10 by whaffman #+#+# #+#+# #+# #+# | */ /* Created: 2025/01/20 14:27:10 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/27 14:14:07 by whaffman ### ### ### ### / \ */ /* Updated: 2025/01/28 17:29:50 by whaffman ### ### ### ### / \ */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */