aboutsummaryrefslogtreecommitdiff
path: root/philo_two/src/philo_two.h
blob: a697382290d9d075a2d8cbd1689264d40d98b063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   philo_two.h                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 22:47:23 by cacharle          #+#    #+#             */
/*   Updated: 2020/09/30 10:02:50 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef PHILO_TWO_H
# define PHILO_TWO_H

# include <unistd.h>
# include <stdbool.h>
# include <pthread.h>
# include <semaphore.h>

# include "common.h"

typedef struct
{
	long int		philo_num;
	t_time 			timeout_death;
	t_time			timeout_eat;
	t_time			timeout_sleep;
	long int		meal_num;
	bool			all_alive;
	pthread_mutex_t	mutex_stdout;
}					t_philo_conf;

typedef struct
{
	long int		id;
	t_philo_conf	*conf;
	t_time			time_last_eat;
	sem_t			*forks;
}					t_philo;

/*
** routine.c
*/

void			*routine_philo(t_philo *arg);
void			*routine_death(t_philo *arg);
t_philo			*routine_create_philos(t_philo_conf *conf, sem_t *forks);

/*
** io.c
*/

void			event_take_fork(t_philo *arg);
void			event_eat(t_philo *arg);
void			event_think(t_philo *arg);
void			event_sleep(t_philo *arg);
void			event_die(t_philo *arg);

#endif