diff options
| author | Dominik Kaiser | 2025-01-28 13:56:07 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2025-01-28 13:56:07 +0100 |
| commit | c33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115 (patch) | |
| tree | a33a18e211b4fcae9e6d6dd8257ac56a5ae603f9 /philo/src/sim_controls.c | |
| parent | ec7a989cf45440e41d43e7fa2d2ce660fa499933 (diff) | |
| download | Philosophers-c33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115.tar.gz Philosophers-c33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115.zip | |
Protect simulation_running with mutex
Diffstat (limited to 'philo/src/sim_controls.c')
| -rw-r--r-- | philo/src/sim_controls.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/philo/src/sim_controls.c b/philo/src/sim_controls.c new file mode 100644 index 0000000..6489211 --- /dev/null +++ b/philo/src/sim_controls.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sim_controls.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/28 13:32:28 by dkaiser #+# #+# */ +/* Updated: 2025/01/28 13:45:20 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "philo.h" + +int is_simulation_running(t_phdata *data) +{ + int result; + + pthread_mutex_lock(&data->sr_mutex); + result = data->simulation_running; + pthread_mutex_unlock(&data->sr_mutex); + return (result); +} + +void stop_simulation(t_phdata *data) +{ + pthread_mutex_lock(&data->sr_mutex); + data->simulation_running = 0; + pthread_mutex_unlock(&data->sr_mutex); +} |
