-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
40 lines (35 loc) · 1.52 KB
/
print.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gichlee <gichlee@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 17:49:42 by gichlee #+# #+# */
/* Updated: 2023/08/04 13:57:20 by gichlee ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
int print(t_phil *p, char *msg)
{
size_t time;
size_t current_ms_from_start;
pthread_mutex_lock(&(p->s->m_print));
time = get_time_in_ms();
current_ms_from_start = time - p->start;
if (!check_dead(p))
printf("%zd %d %s\n", current_ms_from_start, p->phil_num + 1, msg);
pthread_mutex_unlock(&(p->s->m_print));
return (0);
}
int print_dead(t_phil *p)
{
size_t time;
size_t current_ms_from_start;
pthread_mutex_lock(&(p->s->m_print));
time = get_time_in_ms();
current_ms_from_start = time - p->start;
printf("%zd %d %s\n", current_ms_from_start, p->phil_num + 1, "died");
pthread_mutex_unlock(&(p->s->m_print));
return (0);
}