/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* simple_philosophers.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ruiferna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/09 18:23:48 by ruiferna #+# #+# */ /* Updated: 2025/10/09 18:24:44 by ruiferna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef SIMPLE_PHILOSOPHERS_H # define SIMPLE_PHILOSOPHERS_H #include #include #include #include #include #include #include long long get_current_time() { struct timeval tv; gettimeofday(&tv,NULL); /* A stuct tv tem tv_sec que sao os segundos desde a epoch e temos a tv_usec que retorna os microsegundos ate completar 1 segundo (um milhão de microssegundos = 1 segundo). Por isso, para conseguirmos realmente medir os milisegundos precisamos de juntar os dois */ return ((tv.tv_sec * 1000LL) + (tv.tv_usec / 1000LL)); } long long time_diff(long long start, long long end) { return (end - start); } void precise_sleep(int ms) { long long start_time; start_time = get_current_time(); while ((get_current_time() - start_time) < ms) { usleep(100); } } #endif