llvm.org GIT mirror llvm / d8110fb
Get rid of this horrible "benign race" by exploiting ManagedStatic to initialize the array on its first access. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80040 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
1 changed file(s) with 14 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
50135013 AddNodeIDNode(ID, this);
50145014 }
50155015
5016 namespace {
5017 struct EVTArray {
5018 std::vector VTs;
5019
5020 EVTArray() {
5021 VTs.reserve(MVT::LAST_VALUETYPE);
5022 for (unsigned i = 0; i < MVT::LAST_VALUETYPE; ++i)
5023 VTs.push_back(MVT((MVT::SimpleValueType)i));
5024 }
5025 };
5026 }
5027
50165028 static ManagedStatic > EVTs;
5017 static EVT VTs[MVT::LAST_VALUETYPE];
5029 static ManagedStatic SimpleVTArray;
50185030 static ManagedStatic > VTMutex;
50195031
50205032 /// getValueTypeList - Return a pointer to the specified value type.
50245036 sys::SmartScopedLock Lock(*VTMutex);
50255037 return &(*EVTs->insert(VT).first);
50265038 } else {
5027 // All writes to this location will have the same value, so it's ok
5028 // to race on it. We only need to ensure that at least one write has
5029 // succeeded before we return the pointer into the array.
5030 VTs[VT.getSimpleVT().SimpleTy] = VT;
5031 sys::MemoryFence();
5032 return VTs + VT.getSimpleVT().SimpleTy;
5039 return &SimpleVTArray->VTs[VT.getSimpleVT().SimpleTy];
50335040 }
50345041 }
50355042