// Type Class Implementation
//===----------------------------------------------------------------------===//
-// Reader/writer lock used for guarding access to the type maps.
-static ManagedStatic<sys::SmartRWMutex<true> > TypeMapLock;
+// Lock used for guarding access to the type maps.
+static ManagedStatic<sys::SmartMutex<true> > TypeMapLock;
// Recursive lock used for guarding access to AbstractTypeUsers.
// NOTE: The true template parameter means this will no-op when we're not in
// First, see if the type is already in the table, for which
// a reader lock suffices.
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
ITy = IntegerTypes->get(IVT);
- TypeMapLock->reader_release();
if (!ITy) {
- // OK, not in the table, get a writer lock.
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- ITy = IntegerTypes->get(IVT);
-
- // We need to _recheck_ the table in case someone
- // put it in between when we released the reader lock
- // and when we gained the writer lock!
- if (!ITy) {
- // Value not found. Derive a new type!
- ITy = new IntegerType(NumBits);
- IntegerTypes->add(IVT, ITy);
- }
+ // Value not found. Derive a new type!
+ ITy = new IntegerType(NumBits);
+ IntegerTypes->add(IVT, ITy);
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *ITy << "\n";
FunctionValType VT(ReturnType, Params, isVarArg);
FunctionType *FT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
FT = FunctionTypes->get(VT);
- TypeMapLock->reader_release();
if (!FT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
-
- // Have to check again here, because it might have
- // been inserted between when we release the reader
- // lock and when we acquired the writer lock.
- FT = FunctionTypes->get(VT);
- if (!FT) {
- FT = (FunctionType*) operator new(sizeof(FunctionType) +
- sizeof(PATypeHandle)*(Params.size()+1));
- new (FT) FunctionType(ReturnType, Params, isVarArg);
- FunctionTypes->add(VT, FT);
- }
+ FT = (FunctionType*) operator new(sizeof(FunctionType) +
+ sizeof(PATypeHandle)*(Params.size()+1));
+ new (FT) FunctionType(ReturnType, Params, isVarArg);
+ FunctionTypes->add(VT, FT);
}
#ifdef DEBUG_MERGE_TYPES
ArrayValType AVT(ElementType, NumElements);
ArrayType *AT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
AT = ArrayTypes->get(AVT);
- TypeMapLock->reader_release();
-
+
if (!AT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
-
- // Recheck. Might have changed between release and acquire.
- AT = ArrayTypes->get(AVT);
- if (!AT) {
- // Value not found. Derive a new type!
- ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
- }
+ // Value not found. Derive a new type!
+ ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *AT << "\n";
VectorValType PVT(ElementType, NumElements);
VectorType *PT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
PT = VectorTypes->get(PVT);
- TypeMapLock->reader_release();
if (!PT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- PT = VectorTypes->get(PVT);
- // Recheck. Might have changed between release and acquire.
- if (!PT) {
- VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
- }
+ VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *PT << "\n";
StructValType STV(ETypes, isPacked);
StructType *ST = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
ST = StructTypes->get(STV);
- TypeMapLock->reader_release();
if (!ST) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- ST = StructTypes->get(STV);
- // Recheck. Might have changed between release and acquire.
- if (!ST) {
- // Value not found. Derive a new type!
- ST = (StructType*) operator new(sizeof(StructType) +
- sizeof(PATypeHandle) * ETypes.size());
- new (ST) StructType(ETypes, isPacked);
- StructTypes->add(STV, ST);
- }
+ // Value not found. Derive a new type!
+ ST = (StructType*) operator new(sizeof(StructType) +
+ sizeof(PATypeHandle) * ETypes.size());
+ new (ST) StructType(ETypes, isPacked);
+ StructTypes->add(STV, ST);
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *ST << "\n";
PointerType *PT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
PT = PointerTypes->get(PVT);
- TypeMapLock->reader_release();
if (!PT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- PT = PointerTypes->get(PVT);
- // Recheck. Might have changed between release and acquire.
- if (!PT) {
- // Value not found. Derive a new type!
- PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
- }
+ // Value not found. Derive a new type!
+ PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *PT << "\n";
void DerivedType::refineAbstractTypeTo(const Type *NewType) {
// All recursive calls will go through unlockedRefineAbstractTypeTo,
// to avoid deadlock problems.
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
unlockedRefineAbstractTypeTo(NewType);
}