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

12
locked.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef LOCKED_H_
#define LOCKED_H_
#include <pthread.h>
#define locked_init(x) { .value = (x), .lock = PTHREAD_MUTEX_INITIALIZER }
#define locked(T) struct { T value; pthread_mutex_t lock; }
#define lockx(x) pthread_mutex_lock(&(x)->lock)
#define unlockx(x) pthread_mutex_unlock(&(x)->lock)
#endif // LOCKED_H_