tgrekov-philosophers
HIVE philosophers July 2024
Loading...
Searching...
No Matches
philo_sleep.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* philo_sleep.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/07/23 04:54:29 by tgrekov #+# #+# */
9/* Updated: 2024/07/27 08:33:02 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
21#include <unistd.h>
22#include "../utils/utils.h"
23#include "philo.h"
24
33int philo_sleep(unsigned long ms, t_thread *thread)
34{
35 unsigned long start;
36 int stopped;
37
38 start = timestamp();
39 stopped = 0;
40 while (!stopped && (timestamp() - start) < ms)
41 {
42 stopped = usleep(200);
43 if (!stopped)
44 stopped = stop(thread);
45 }
46 return (stopped || check_end(thread->global));
47}
int check_end(t_global *global)
Check if the simulation has ended.
Definition sim_end.c:28
int stop(t_thread *thread)
Determine if this thread's philo should die, or if the thread has reported an error.
Definition stop.c:30
int philo_sleep(unsigned long ms, t_thread *thread)
Sleep in 200 microsecond intervals until ms millis have elapsed, or stop has returned non-zero.
Definition philo_sleep.c:33
unsigned long timestamp(void)
Millisecond timestamp since this function was first called.
Definition timestamp.c:27