@@ -43,8 +43,8 @@ AbstractTypeUser::~AbstractTypeUser() {}
43
43
// Type Class Implementation
44
44
// ===----------------------------------------------------------------------===//
45
45
46
- // Reader/writer lock used for guarding access to the type maps.
47
- static ManagedStatic<sys::SmartRWMutex <true > > TypeMapLock;
46
+ // Lock used for guarding access to the type maps.
47
+ static ManagedStatic<sys::SmartMutex <true > > TypeMapLock;
48
48
49
49
// Recursive lock used for guarding access to AbstractTypeUsers.
50
50
// NOTE: The true template parameter means this will no-op when we're not in
@@ -1006,23 +1006,13 @@ const IntegerType *IntegerType::get(unsigned NumBits) {
1006
1006
1007
1007
// First, see if the type is already in the table, for which
1008
1008
// a reader lock suffices.
1009
- TypeMapLock-> reader_acquire ( );
1009
+ sys::SmartScopedLock< true > L (&*TypeMapLock );
1010
1010
ITy = IntegerTypes->get (IVT);
1011
- TypeMapLock->reader_release ();
1012
1011
1013
1012
if (!ITy) {
1014
- // OK, not in the table, get a writer lock.
1015
- sys::SmartScopedWriter<true > Writer (&*TypeMapLock);
1016
- ITy = IntegerTypes->get (IVT);
1017
-
1018
- // We need to _recheck_ the table in case someone
1019
- // put it in between when we released the reader lock
1020
- // and when we gained the writer lock!
1021
- if (!ITy) {
1022
- // Value not found. Derive a new type!
1023
- ITy = new IntegerType (NumBits);
1024
- IntegerTypes->add (IVT, ITy);
1025
- }
1013
+ // Value not found. Derive a new type!
1014
+ ITy = new IntegerType (NumBits);
1015
+ IntegerTypes->add (IVT, ITy);
1026
1016
}
1027
1017
#ifdef DEBUG_MERGE_TYPES
1028
1018
DOUT << " Derived new type: " << *ITy << " \n " ;
@@ -1089,23 +1079,14 @@ FunctionType *FunctionType::get(const Type *ReturnType,
1089
1079
FunctionValType VT (ReturnType, Params, isVarArg);
1090
1080
FunctionType *FT = 0 ;
1091
1081
1092
- TypeMapLock-> reader_acquire ( );
1082
+ sys::SmartScopedLock< true > L (&*TypeMapLock );
1093
1083
FT = FunctionTypes->get (VT);
1094
- TypeMapLock->reader_release ();
1095
1084
1096
1085
if (!FT) {
1097
- sys::SmartScopedWriter<true > Writer (&*TypeMapLock);
1098
-
1099
- // Have to check again here, because it might have
1100
- // been inserted between when we release the reader
1101
- // lock and when we acquired the writer lock.
1102
- FT = FunctionTypes->get (VT);
1103
- if (!FT) {
1104
- FT = (FunctionType*) operator new (sizeof (FunctionType) +
1105
- sizeof (PATypeHandle)*(Params.size ()+1 ));
1106
- new (FT) FunctionType (ReturnType, Params, isVarArg);
1107
- FunctionTypes->add (VT, FT);
1108
- }
1086
+ FT = (FunctionType*) operator new (sizeof (FunctionType) +
1087
+ sizeof (PATypeHandle)*(Params.size ()+1 ));
1088
+ new (FT) FunctionType (ReturnType, Params, isVarArg);
1089
+ FunctionTypes->add (VT, FT);
1109
1090
}
1110
1091
1111
1092
#ifdef DEBUG_MERGE_TYPES
@@ -1148,19 +1129,12 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
1148
1129
ArrayValType AVT (ElementType, NumElements);
1149
1130
ArrayType *AT = 0 ;
1150
1131
1151
- TypeMapLock-> reader_acquire ( );
1132
+ sys::SmartScopedLock< true > L (&*TypeMapLock );
1152
1133
AT = ArrayTypes->get (AVT);
1153
- TypeMapLock->reader_release ();
1154
-
1134
+
1155
1135
if (!AT) {
1156
- sys::SmartScopedWriter<true > Writer (&*TypeMapLock);
1157
-
1158
- // Recheck. Might have changed between release and acquire.
1159
- AT = ArrayTypes->get (AVT);
1160
- if (!AT) {
1161
- // Value not found. Derive a new type!
1162
- ArrayTypes->add (AVT, AT = new ArrayType (ElementType, NumElements));
1163
- }
1136
+ // Value not found. Derive a new type!
1137
+ ArrayTypes->add (AVT, AT = new ArrayType (ElementType, NumElements));
1164
1138
}
1165
1139
#ifdef DEBUG_MERGE_TYPES
1166
1140
DOUT << " Derived new type: " << *AT << " \n " ;
@@ -1214,17 +1188,11 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
1214
1188
VectorValType PVT (ElementType, NumElements);
1215
1189
VectorType *PT = 0 ;
1216
1190
1217
- TypeMapLock-> reader_acquire ( );
1191
+ sys::SmartScopedLock< true > L (&*TypeMapLock );
1218
1192
PT = VectorTypes->get (PVT);
1219
- TypeMapLock->reader_release ();
1220
1193
1221
1194
if (!PT) {
1222
- sys::SmartScopedWriter<true > Writer (&*TypeMapLock);
1223
- PT = VectorTypes->get (PVT);
1224
- // Recheck. Might have changed between release and acquire.
1225
- if (!PT) {
1226
- VectorTypes->add (PVT, PT = new VectorType (ElementType, NumElements));
1227
- }
1195
+ VectorTypes->add (PVT, PT = new VectorType (ElementType, NumElements));
1228
1196
}
1229
1197
#ifdef DEBUG_MERGE_TYPES
1230
1198
DOUT << " Derived new type: " << *PT << " \n " ;
@@ -1282,21 +1250,15 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
1282
1250
StructValType STV (ETypes, isPacked);
1283
1251
StructType *ST = 0 ;
1284
1252
1285
- TypeMapLock-> reader_acquire ( );
1253
+ sys::SmartScopedLock< true > L (&*TypeMapLock );
1286
1254
ST = StructTypes->get (STV);
1287
- TypeMapLock->reader_release ();
1288
1255
1289
1256
if (!ST) {
1290
- sys::SmartScopedWriter<true > Writer (&*TypeMapLock);
1291
- ST = StructTypes->get (STV);
1292
- // Recheck. Might have changed between release and acquire.
1293
- if (!ST) {
1294
- // Value not found. Derive a new type!
1295
- ST = (StructType*) operator new (sizeof (StructType) +
1296
- sizeof (PATypeHandle) * ETypes.size ());
1297
- new (ST) StructType (ETypes, isPacked);
1298
- StructTypes->add (STV, ST);
1299
- }
1257
+ // Value not found. Derive a new type!
1258
+ ST = (StructType*) operator new (sizeof (StructType) +
1259
+ sizeof (PATypeHandle) * ETypes.size ());
1260
+ new (ST) StructType (ETypes, isPacked);
1261
+ StructTypes->add (STV, ST);
1300
1262
}
1301
1263
#ifdef DEBUG_MERGE_TYPES
1302
1264
DOUT << " Derived new type: " << *ST << " \n " ;
@@ -1367,18 +1329,12 @@ PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
1367
1329
1368
1330
PointerType *PT = 0 ;
1369
1331
1370
- TypeMapLock-> reader_acquire ( );
1332
+ sys::SmartScopedLock< true > L (&*TypeMapLock );
1371
1333
PT = PointerTypes->get (PVT);
1372
- TypeMapLock->reader_release ();
1373
1334
1374
1335
if (!PT) {
1375
- sys::SmartScopedWriter<true > Writer (&*TypeMapLock);
1376
- PT = PointerTypes->get (PVT);
1377
- // Recheck. Might have changed between release and acquire.
1378
- if (!PT) {
1379
- // Value not found. Derive a new type!
1380
- PointerTypes->add (PVT, PT = new PointerType (ValueType, AddressSpace));
1381
- }
1336
+ // Value not found. Derive a new type!
1337
+ PointerTypes->add (PVT, PT = new PointerType (ValueType, AddressSpace));
1382
1338
}
1383
1339
#ifdef DEBUG_MERGE_TYPES
1384
1340
DOUT << " Derived new type: " << *PT << " \n " ;
@@ -1532,7 +1488,7 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) {
1532
1488
void DerivedType::refineAbstractTypeTo (const Type *NewType) {
1533
1489
// All recursive calls will go through unlockedRefineAbstractTypeTo,
1534
1490
// to avoid deadlock problems.
1535
- sys::SmartScopedWriter <true > Writer (&*TypeMapLock);
1491
+ sys::SmartScopedLock <true > L (&*TypeMapLock);
1536
1492
unlockedRefineAbstractTypeTo (NewType);
1537
1493
}
1538
1494
0 commit comments