mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
philip correctly points out that local static init from constants isn't thread-safe, and we shouldn't rely on the compiler moving variables to BSS if their constant initializer is 0.
This was SVN commit r7055.
This commit is contained in:
@@ -215,7 +215,12 @@ LibError debug_WriteCrashlog(const wchar_t* text)
|
||||
BUSY,
|
||||
FAILED
|
||||
};
|
||||
static volatile uintptr_t state = IDLE;
|
||||
// note: the initial state is IDLE. we rely on zero-init because
|
||||
// initializing local static objects from constants may happen when
|
||||
// this is first called, which isn't thread-safe. (see C++ 6.7.4)
|
||||
cassert(IDLE == 0);
|
||||
static volatile uintptr_t state;
|
||||
|
||||
if(!cpu_CAS(&state, IDLE, BUSY))
|
||||
return ERR::REENTERED; // NOWARN
|
||||
|
||||
|
||||
Reference in New Issue
Block a user