From: Lukas Jiriste Date: Thu, 30 May 2024 11:06:51 +0000 (+0200) Subject: Make semaphores lose conditionally X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=598a6d1007f4fe56697e423156c2a8ceb6f67522;p=42%2Fphilosophers.git Make semaphores lose conditionally This is done to make helgrind stop emitting an error about closing non-existent semaphore hence saving me some explaining during evaluation. --- diff --git a/philo_bonus/mem_management.c b/philo_bonus/mem_management.c index f7a503b..76fc540 100644 --- a/philo_bonus/mem_management.c +++ b/philo_bonus/mem_management.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 09:39:55 by ljiriste #+# #+# */ -/* Updated: 2024/05/30 11:18:25 by ljiriste ### ########.fr */ +/* Updated: 2024/05/30 13:01:59 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,12 +53,18 @@ int init(unsigned int count, pid_t **philo_pids, t_sems *semaphores) void close_semaphores(t_sems *semaphores) { - sem_close(semaphores->forks); - sem_close(semaphores->fed); - sem_close(semaphores->death); - sem_close(semaphores->term); - sem_close(semaphores->end); - sem_close(semaphores->check_end); + if (semaphores->forks != SEM_FAILED) + sem_close(semaphores->forks); + if (semaphores->fed != SEM_FAILED) + sem_close(semaphores->fed); + if (semaphores->death != SEM_FAILED) + sem_close(semaphores->death); + if (semaphores->term != SEM_FAILED) + sem_close(semaphores->term); + if (semaphores->end != SEM_FAILED) + sem_close(semaphores->end); + if (semaphores->check_end != SEM_FAILED) + sem_close(semaphores->check_end); return ; } diff --git a/philo_bonus/philo.c b/philo_bonus/philo.c index bb44b9c..1e14c13 100644 --- a/philo_bonus/philo.c +++ b/philo_bonus/philo.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 08:45:21 by ljiriste #+# #+# */ -/* Updated: 2024/05/30 12:49:14 by ljiriste ### ########.fr */ +/* Updated: 2024/05/30 13:00:26 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ static int open_semaphores(t_philo *philo) || philo->semaphores.term == SEM_FAILED || philo->semaphores.end == SEM_FAILED) return (2); - philo->semaphores.check_end = NULL; + philo->semaphores.check_end = SEM_FAILED; return (0); }