protection segfault creation zero philosophs + deplacement fichiers dans philo + ajout exeption philo folder dans gitignore
This commit is contained in:
27
philo/headers/philo.h
Normal file
27
philo/headers/philo.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* philo.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:27:01 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 15:27:02 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PHILO_H
|
||||
# define PHILO_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
# include <pthread.h>
|
||||
# include <sys/time.h>
|
||||
|
||||
# include "philo_struct.h"
|
||||
# include "philo_proto.h"
|
||||
# include "philo_macro.h"
|
||||
|
||||
#endif
|
||||
36
philo/headers/philo_macro.h
Normal file
36
philo/headers/philo_macro.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* philo_macro.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:27:08 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 15:27:09 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PHILO_MACRO_H
|
||||
# define PHILO_MACRO_H
|
||||
|
||||
# define GRAY "\e[0;30m"
|
||||
# define RED "\e[0;31m"
|
||||
# define GREEN "\e[0;32m"
|
||||
# define YELLOW "\e[0;33m"
|
||||
# define BLUE "\e[0;34m"
|
||||
# define PURPLE "\e[0;35m"
|
||||
# define CYAN "\e[0;36m"
|
||||
# define WHITE "\e[0;37m"
|
||||
|
||||
# define B_GRAY "\e[1;30m"
|
||||
# define B_RED "\e[1;31m"
|
||||
# define B_GREEN "\e[1;32m"
|
||||
# define B_YELLOW "\e[1;33m"
|
||||
# define B_BLUE "\e[1;34m"
|
||||
# define B_PURPLE "\e[1;35m"
|
||||
# define B_CYAN "\e[1;36m"
|
||||
# define B_WHITE "\e[1;37m"
|
||||
|
||||
# define RESET "\e[0m"
|
||||
|
||||
#endif
|
||||
38
philo/headers/philo_proto.h
Normal file
38
philo/headers/philo_proto.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* philo_proto.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:27:13 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 17:50:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PHILO_PROTO_H
|
||||
# define PHILO_PROTO_H
|
||||
|
||||
// init.c
|
||||
t_philo *init(int ac, char **av, pthread_t **id);
|
||||
|
||||
// launch.c
|
||||
void launch(t_philo *philo, pthread_t *id);
|
||||
|
||||
// exec.c
|
||||
void *philo_exec(void *arg);
|
||||
|
||||
// generic.c
|
||||
void init_time(t_philo *philo);
|
||||
void update_time(t_philo *philo);
|
||||
int diff_time(t_time *old, struct timeval *new);
|
||||
int print_message(t_philo *philo, char *clr, char *msg);
|
||||
|
||||
// utils.c
|
||||
int ft_isdigit_2d_arr(char **str);
|
||||
size_t ft_strlen(char *str);
|
||||
int ft_strncmp(char *s1, char *s2, size_t n);
|
||||
int ft_int_overflow(char *str);
|
||||
int ft_atoi(const char *str);
|
||||
|
||||
#endif
|
||||
52
philo/headers/philo_struct.h
Normal file
52
philo/headers/philo_struct.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* philo_struct.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:27:23 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 15:29:09 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PHILO_STRUCT_H
|
||||
# define PHILO_STRUCT_H
|
||||
|
||||
typedef pthread_mutex_t t_mtx;
|
||||
|
||||
typedef struct s_time
|
||||
{
|
||||
long int ts;
|
||||
long int tu;
|
||||
} t_time;
|
||||
|
||||
typedef struct s_params
|
||||
{
|
||||
int n_phi;
|
||||
int t_die;
|
||||
int t_eat;
|
||||
int t_slp;
|
||||
int n_eat;
|
||||
} t_params;
|
||||
|
||||
typedef struct s_global
|
||||
{
|
||||
int stop;
|
||||
int satiated_count;
|
||||
t_time t_start;
|
||||
t_mtx m_print;
|
||||
} t_global;
|
||||
|
||||
typedef struct s_philo
|
||||
{
|
||||
t_params *params;
|
||||
t_global *global;
|
||||
int p_nbr;
|
||||
t_mtx m_fork;
|
||||
t_time t_last_meal;
|
||||
int eat_count;
|
||||
struct s_philo *next;
|
||||
} t_philo;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user