Skip to content

Commit

Permalink
Remove global missingTypes list
Browse files Browse the repository at this point in the history
The global missingTypes list was not thread safe and the operations it was used for could not be made safe even with a concurrent container. Therefore all functions which used to manipulate the global list now require a local list be passed as an argument.
  • Loading branch information
Dr15Jones committed Feb 12, 2016
1 parent edb1732 commit 986ed31
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
13 changes: 6 additions & 7 deletions FWCore/Utilities/interface/DictionaryTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ class TypeID;
class TypeWithDict;
using TypeSet = std::set<TypeID>;

bool checkClassDictionary(TypeID const& type);
void checkClassDictionaries(TypeID const& type, bool recursive = true);
bool checkTypeDictionary(TypeID const& type);
void checkTypeDictionaries(TypeID const& type, bool recursive = true);
void throwMissingDictionariesException();
void loadMissingDictionaries();
TypeSet& missingTypes();
bool checkClassDictionary(TypeID const& type, TypeSet& missingTypes);
void checkClassDictionaries(TypeID const& type, TypeSet& missingTypes, bool recursive = true);
bool checkTypeDictionary(TypeID const& type, TypeSet& missingTypes);
void checkTypeDictionaries(TypeID const& type, TypeSet& missingTypes, bool recursive = true);
void throwMissingDictionariesException(TypeSet const&);
void loadMissingDictionaries(TypeSet missingTypes);

void public_base_classes(TypeWithDict const& type,
std::vector<TypeWithDict>& baseTypes);
Expand Down
45 changes: 19 additions & 26 deletions FWCore/Utilities/src/DictionaryTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,22 @@

namespace edm {

static TypeSet missingTypes_;

TypeSet&
missingTypes() {
return missingTypes_;
}

bool
checkTypeDictionary(TypeID const& type) {
checkTypeDictionary(TypeID const& type, TypeSet& missingTypes) {
TClass *cl = TClass::GetClass(type.typeInfo(), true);
if(cl == nullptr) {
// Assume not a class
return true;
}
if(!cl->HasDictionary()) {
missingTypes().insert(type);
missingTypes.insert(type);
return false;
}
return true;
}

void
checkTypeDictionaries(TypeID const& type, bool recursive) {
checkTypeDictionaries(TypeID const& type, TypeSet& missingTypes, bool recursive) {
TClass *cl = TClass::GetClass(type.typeInfo(), true);
if(cl == nullptr) {
// Assume not a class
Expand All @@ -52,26 +45,26 @@ namespace edm {
cl->GetMissingDictionaries(result, recursive);
for(auto const& item : result) {
TClass const* cl = static_cast<TClass const*>(item);
missingTypes().insert(TypeID(cl->GetTypeInfo()));
missingTypes.insert(TypeID(cl->GetTypeInfo()));
}
}

bool
checkClassDictionary(TypeID const& type) {
checkClassDictionary(TypeID const& type, TypeSet& missingTypes) {
TClass *cl = TClass::GetClass(type.typeInfo(), true);
if(cl == nullptr) {
throw Exception(errors::DictionaryNotFound)
<< "No TClass for class: '" << type.className() << "'" << std::endl;
}
if(!cl->HasDictionary()) {
missingTypes().insert(type);
missingTypes.insert(type);
return false;
}
return true;
}

void
checkClassDictionaries(TypeID const& type, bool recursive) {
checkClassDictionaries(TypeID const& type, TypeSet& missingTypes, bool recursive) {
TClass *cl = TClass::GetClass(type.typeInfo(), true);
if(cl == nullptr) {
throw Exception(errors::DictionaryNotFound)
Expand All @@ -81,15 +74,15 @@ namespace edm {
cl->GetMissingDictionaries(result, recursive);
for(auto const& item : result) {
TClass const* cl = static_cast<TClass const*>(item);
missingTypes().insert(TypeID(cl->GetTypeInfo()));
missingTypes.insert(TypeID(cl->GetTypeInfo()));
}
}

void
throwMissingDictionariesException() {
if (!missingTypes().empty()) {
throwMissingDictionariesException(TypeSet const& missingTypes) {
if (!missingTypes.empty()) {
std::ostringstream ostr;
for(auto const& item : missingTypes()) {
for(auto const& item : missingTypes) {
ostr << item << "\n\n";
}
throw Exception(errors::DictionaryNotFound)
Expand All @@ -108,28 +101,28 @@ namespace edm {
}

void
loadMissingDictionaries() {
while (!missingTypes().empty()) {
TypeSet missing(missingTypes());
loadMissingDictionaries(TypeSet missingTypes) {
while (!missingTypes.empty()) {
TypeSet missing(missingTypes);
for(auto const& item : missing) {
try {
TClass::GetClass(item.typeInfo(), kTRUE);
}
// We don't want to fail if we can't load a plug-in.
catch (...) {}
}
missingTypes().clear();
missingTypes.clear();
for(auto const& item : missing) {
checkTypeDictionaries(item, true);
checkTypeDictionaries(item, missingTypes,true);
}
if (missingTypes() == missing) {
if (missingTypes == missing) {
break;
}
}
if (missingTypes().empty()) {
if (missingTypes.empty()) {
return;
}
throwMissingDictionariesException();
throwMissingDictionariesException(missingTypes);
}

void
Expand Down

0 comments on commit 986ed31

Please sign in to comment.