diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-30 09:52:21 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-30 09:52:21 +0200 |
| commit | 94d33564ee659d2fd0b084a4b4046e7b69ee0d9b (patch) | |
| tree | 26557e562ef0629f9023c467be04fcecf3ddb6f4 /philo_one/src/forks.c | |
| parent | 608ae732eccfe50f2727823f9aebe1f32681edfb (diff) | |
| download | philosophers-94d33564ee659d2fd0b084a4b4046e7b69ee0d9b.tar.gz philosophers-94d33564ee659d2fd0b084a4b4046e7b69ee0d9b.tar.bz2 philosophers-94d33564ee659d2fd0b084a4b4046e7b69ee0d9b.zip | |
Refactoring philo_one, removing mutex_all_alive and t_routine_args bloat
Diffstat (limited to 'philo_one/src/forks.c')
| -rw-r--r-- | philo_one/src/forks.c | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/philo_one/src/forks.c b/philo_one/src/forks.c index ebe5261..fef1de0 100644 --- a/philo_one/src/forks.c +++ b/philo_one/src/forks.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/09 23:46:40 by cacharle #+# #+# */ -/* Updated: 2020/09/27 09:26:12 by charles ### ########.fr */ +/* Updated: 2020/09/30 09:45:46 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ pthread_mutex_t *forks_new(int num) { if (pthread_mutex_init(&forks[i], NULL) != 0) { - forks_destroy(forks, i + 1); + forks_destroy(forks, i); return (NULL); } } @@ -37,24 +37,3 @@ void forks_destroy(pthread_mutex_t *forks, int num) pthread_mutex_destroy(&forks[num]); free(forks); } - -t_routine_arg *forks_dispatch( - t_philo *philos, - pthread_mutex_t *forks, - t_philo_conf *conf) -{ - int i; - t_routine_arg *routine_args; - - if ((routine_args = malloc(conf->philo_num * sizeof(t_routine_arg))) == NULL) - return (NULL); - i = -1; - while (++i < conf->philo_num) - { - routine_args[i].conf = conf; - routine_args[i].philo = philos + i; - routine_args[i].fork_left = forks + i % conf->philo_num; - routine_args[i].fork_right = forks + (i + 1) % conf->philo_num; - } - return (routine_args); -} |
