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 <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace spv {
|
namespace spv {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -1540,10 +1541,8 @@ EnumParameters MemoryAccessParams[MemoryAccessCeiling];
|
|||||||
void Parameterize()
|
void Parameterize()
|
||||||
{
|
{
|
||||||
// only do this once.
|
// only do this once.
|
||||||
static bool initialized = false;
|
static std::once_flag initialized;
|
||||||
if (initialized)
|
std::call_once(initialized, [](){
|
||||||
return;
|
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
// Exceptions to having a result <id> and a resulting type <id>.
|
// Exceptions to having a result <id> and a resulting type <id>.
|
||||||
// (Everything is initialized to have both).
|
// (Everything is initialized to have both).
|
||||||
@ -3287,6 +3286,7 @@ void Parameterize()
|
|||||||
InstructionDesc[OpColorAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
InstructionDesc[OpColorAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
||||||
InstructionDesc[OpStencilAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
InstructionDesc[OpStencilAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
||||||
InstructionDesc[OpDepthAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
InstructionDesc[OpDepthAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // end spv namespace
|
}; // end spv namespace
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user