Use std::call_once in spv::Parameterize()
There was a race condition in this function as it used a static variable to attempt to ensure global initialization was only done once, which was not thread-safe. Instead, use std::call_once, which was added to C++11 for this exact case. Fixes #342
This commit is contained in:
parent
d9a6fb2247
commit
f47028995c
@ -45,6 +45,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
|
||||
namespace spv {
|
||||
extern "C" {
|
||||
@ -1540,10 +1541,8 @@ EnumParameters MemoryAccessParams[MemoryAccessCeiling];
|
||||
void Parameterize()
|
||||
{
|
||||
// only do this once.
|
||||
static bool initialized = false;
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
static std::once_flag initialized;
|
||||
std::call_once(initialized, [](){
|
||||
|
||||
// Exceptions to having a result <id> and a resulting type <id>.
|
||||
// (Everything is initialized to have both).
|
||||
@ -3287,6 +3286,7 @@ void Parameterize()
|
||||
InstructionDesc[OpColorAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
||||
InstructionDesc[OpStencilAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
||||
InstructionDesc[OpDepthAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
||||
});
|
||||
}
|
||||
|
||||
}; // end spv namespace
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user