ConstantsLock->reader_release();
if (!Slot) {
- ConstantsLock->writer_acquire();
+ sys::ScopedWriter Writer(&*ConstantsLock);
ConstantInt *&Slot = (*IntConstants)[Key];
if (!Slot) {
Slot = new ConstantInt(ITy, V);
}
- ConstantsLock->writer_release();
}
return Slot;
ConstantsLock->reader_release();
if (!Slot) {
- ConstantsLock->writer_acquire();
+ sys::ScopedWriter Writer(&*ConstantsLock);
Slot = (*FPConstants)[Key];
if (!Slot) {
const Type *Ty;
Slot = new ConstantFP(Ty, V);
}
- ConstantsLock->writer_release();
}
return Slot;
ConstantsLock->reader_release();
if (!Result) {
- ConstantsLock->writer_acquire();
+ sys::ScopedWriter Writer(&*ConstantsLock);
I = Map.find(Lookup);
// Is it in the map?
if (I != Map.end())
}
}
}
- ConstantsLock->writer_release();
}
return Result;
// If the type became concrete without being refined to any other existing
// type, we just remove ourselves from the ATU list.
void typeBecameConcrete(const DerivedType *AbsTy) {
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
- AbsTy->removeAbstractTypeUser(this);
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
+ if (llvm_is_multithreaded()) {
+ sys::ScopedWriter Writer(&*ConstantsLock);
+ AbsTy->removeAbstractTypeUser(this);
+ } else
+ AbsTy->removeAbstractTypeUser(this);
}
void dump() const {
// destroyConstant - Remove the constant from the constant table...
//
void ConstantVector::destroyConstant() {
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
- VectorConstants->remove(this);
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
+
+ if (llvm_is_multithreaded()) {
+ sys::ScopedWriter Write(&*ConstantsLock);
+ VectorConstants->remove(this);
+ } else
+ VectorConstants->remove(this);
destroyConstantImpl();
}
// destroyConstant - Remove the constant from the constant table...
//
void ConstantPointerNull::destroyConstant() {
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
- NullPtrConstants->remove(this);
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
+ if (llvm_is_multithreaded()) {
+ sys::ScopedWriter Writer(&*ConstantsLock);
+ NullPtrConstants->remove(this);
+ } else
+ NullPtrConstants->remove(this);
destroyConstantImpl();
}
static ManagedStatic<StringMap<MDString*> > MDStringCache;
MDString *MDString::get(const char *StrBegin, const char *StrEnd) {
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
- StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(StrBegin,
- StrEnd);
- MDString *&S = Entry.getValue();
- if (!S) S = new MDString(Entry.getKeyData(),
- Entry.getKeyData() + Entry.getKeyLength());
-
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
- return S;
+ if (llvm_is_multithreaded()) {
+ sys::ScopedWriter Writer(&*ConstantsLock);
+ StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
+ StrBegin, StrEnd);
+ MDString *&S = Entry.getValue();
+ if (!S) S = new MDString(Entry.getKeyData(),
+ Entry.getKeyData() + Entry.getKeyLength());
+
+ return S;
+ } else {
+ StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
+ StrBegin, StrEnd);
+ MDString *&S = Entry.getValue();
+ if (!S) S = new MDString(Entry.getKeyData(),
+ Entry.getKeyData() + Entry.getKeyLength());
+
+ return S;
+ }
}
void MDString::destroyConstant() {
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
- MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
+ if (llvm_is_multithreaded()) {
+ sys::ScopedWriter Writer(&*ConstantsLock);
+ MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));
+ } else
+ MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));
+
destroyConstantImpl();
}
ConstantsLock->reader_release();
if (!N) {
- ConstantsLock->writer_acquire();
+ sys::ScopedWriter Writer(&*ConstantsLock);
N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint);
if (!N) {
// InsertPoint will have been set by the FindNodeOrInsertPos call.
MDNode *N = new(0) MDNode(Vals, NumVals);
MDNodeSet->InsertNode(N, InsertPoint);
}
- ConstantsLock->writer_release();
}
return N;
}
void MDNode::destroyConstant() {
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
- MDNodeSet->RemoveNode(this);
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
+ if (llvm_is_multithreaded()) {
+ sys::ScopedWriter Writer(&*ConstantsLock);
+ MDNodeSet->RemoveNode(this);
+ } else
+ MDNodeSet->RemoveNode(this);
+
destroyConstantImpl();
}
// destroyConstant - Remove the constant from the constant table...
//
void ConstantExpr::destroyConstant() {
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
- ExprConstants->remove(this);
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
+ if (llvm_is_multithreaded()) {
+ sys::ScopedWriter Writer(&*ConstantsLock);
+ ExprConstants->remove(this);
+ } else
+ ExprConstants->remove(this);
+
destroyConstantImpl();
}
Replacement = ConstantAggregateZero::get(getType());
} else {
// Check to see if we have this array type already.
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
+ sys::ScopedWriter Writer(&*ConstantsLock);
bool Exists;
ArrayConstantsTy::MapTy::iterator I =
ArrayConstants->InsertOrGetItem(Lookup, Exists);
if (getOperand(i) == From)
setOperand(i, ToC);
}
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
return;
}
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
}
// Otherwise, I do need to replace this with an existing value.
Replacement = ConstantAggregateZero::get(getType());
} else {
// Check to see if we have this array type already.
- if (llvm_is_multithreaded()) ConstantsLock->writer_acquire();
+ sys::ScopedWriter Writer(&*ConstantsLock);
bool Exists;
StructConstantsTy::MapTy::iterator I =
StructConstants->InsertOrGetItem(Lookup, Exists);
// Update to the new value.
setOperand(OperandToUpdate, ToC);
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
return;
}
- if (llvm_is_multithreaded()) ConstantsLock->writer_release();
}
assert(Replacement != this && "I didn't contain From!");