Protect global data with locks

This commit is contained in:
kamkow1
2025-06-22 15:32:13 +02:00
parent a7f8ebea09
commit 5ee77b4628
7 changed files with 90 additions and 139 deletions

11
timer.c
View File

@ -3,22 +3,27 @@
#include <stdio.h>
#include "timer.h"
#include "locked.h"
time_t rawtime;
locked(time_t) rawtime;
void start_timer(void)
{
time(&rawtime);
lockx(&rawtime);
time(&rawtime.value);
unlockx(&rawtime);
}
void get_timer_string(char *output, size_t size)
{
lockx(&rawtime);
struct tm * timeinfo;
timeinfo = localtime(&rawtime);
timeinfo = localtime(&rawtime.value);
snprintf(output, size, "[%02d %02d %d %02d:%02d:%02d]", timeinfo->tm_mday,
timeinfo->tm_mon + 1, timeinfo->tm_year + 1900,
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
unlockx(&rawtime);
}