Fix assertion race condition in debug mode

Commit 21d206f360 added mutex assertions.

However, the "locker" variable to trace the locker thread id was read
and written by several threads without any protection, so it was racy.

Reported by TSAN.
This commit is contained in:
Romain Vimont
2021-06-26 15:29:08 +02:00
parent 7dca5078e7
commit f33d37976c
2 changed files with 15 additions and 8 deletions

View File

@@ -3,6 +3,7 @@
#include "common.h"
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
@@ -12,7 +13,8 @@ typedef struct SDL_mutex SDL_mutex;
typedef struct SDL_cond SDL_cond;
typedef int sc_thread_fn(void *);
typedef unsigned int sc_thread_id;
typedef unsigned sc_thread_id;
typedef atomic_uint sc_atomic_thread_id;
typedef struct sc_thread {
SDL_Thread *thread;
@@ -21,7 +23,7 @@ typedef struct sc_thread {
typedef struct sc_mutex {
SDL_mutex *mutex;
#ifndef NDEBUG
sc_thread_id locker;
sc_atomic_thread_id locker;
#endif
} sc_mutex;