From 71ad6c7bbd3cfbe6b6a32b616654565095225587 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Fri, 11 Nov 2022 23:59:24 -0800 Subject: [PATCH] Update server to have mutex --- server_main.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/server_main.c b/server_main.c index 2a65557..09eecf9 100644 --- a/server_main.c +++ b/server_main.c @@ -1,11 +1,35 @@ +#define MINIAUDIO_IMPLEMENTATION +#include "miniaudio.h" #include "types.h" #define SOKOL_IMPL #include "sokol_time.h" +#include +#include + +ServerThreadInfo server_info = { + .world_save = "world.bin", +}; + +void term(int signum) +{ + ma_mutex_lock(&server_info.info_mutex); + server_info.running = false; + ma_mutex_unlock(&server_info.info_mutex); +} + + int main(int argc, char **argv) { + struct sigaction action; + memset(&action, 0, sizeof(struct sigaction)); + action.sa_handler = term; + sigaction(SIGTERM, &action, NULL); + stm_setup(); - server("world.bin"); + ma_mutex_init(&server_info.info_mutex); + server(&server_info); + ma_mutex_uninit(&server_info.info_mutex); return 0; }