tgrekov-philosophers
HIVE philosophers July 2024
Loading...
Searching...
No Matches
status.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* status.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/07/27 07:03:10 by tgrekov #+# #+# */
9/* Updated: 2024/08/06 16:56:12 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <stdio.h>
21#include "../utils/utils.h"
22#include "philo.h"
23
32static int status_print_verify(t_thread *thread, unsigned long ts, char *str)
33{
34 return (printf("%lu %d %s\n", ts, thread->i + 1, str)
35 != (ullen(ts) + intlen(thread->i + 1) + ft_strlen(str) + 3));
36}
37
46int status(t_thread *thread, char *str, int ignore_end)
47{
48 unsigned long ts;
49
50 pthread_mutex_lock(&thread->global->printing);
51 if (ignore_end || !check_end(thread->global))
52 {
53 ts = timestamp();
54 if (status_print_verify(thread, ts, str))
55 thread->err = 1;
56 }
57 pthread_mutex_unlock(&thread->global->printing);
58 return (thread->err);
59}
int check_end(t_global *global)
Check if the simulation has ended.
Definition sim_end.c:28
int status(t_thread *thread, char *str, int ignore_end)
Thread safe philosopher state logging.
Definition status.c:46
static int status_print_verify(t_thread *thread, unsigned long ts, char *str)
Print status and verify correct length.
Definition status.c:32
unsigned long timestamp(void)
Millisecond timestamp since this function was first called.
Definition timestamp.c:27