Skip to content

Make TClass::fIsAMethod setting thread safe #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/meta/inc/TClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ friend class ROOT::TGenericClassInfo;

TVirtualIsAProxy *fIsA; //!pointer to the class's IsA proxy.
IsAGlobalFunc_t fGlobalIsA; //pointer to a global IsA function.
#if __cplusplus > 199711L
mutable std::atomic<TMethodCall*> fIsAMethod; //!saved info to call a IsA member function
#else
mutable TMethodCall *fIsAMethod; //!saved info to call a IsA member function
#endif

ROOT::MergeFunc_t fMerge; //pointer to a function implementing Merging objects of this class.
ROOT::ResetAfterMergeFunc_t fResetAfterMerge; //pointer to a function implementing Merging objects of this class.
Expand Down
28 changes: 21 additions & 7 deletions core/meta/src/TClass.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ TClass::TClass(const TClass& cl) :
fSharedLibs(cl.fSharedLibs),
fIsA(cl.fIsA),
fGlobalIsA(cl.fGlobalIsA),
fIsAMethod(cl.fIsAMethod),
fIsAMethod(0),
fMerge(cl.fMerge),
fResetAfterMerge(cl.fResetAfterMerge),
fNew(cl.fNew),
Expand Down Expand Up @@ -1326,7 +1326,11 @@ TClass::~TClass()

delete fStreamer;
delete fCollectionProxy;
#if __cplusplus > 199711L
delete fIsAMethod.load();
#else
delete fIsAMethod;
#endif
delete fSchemaRules;
if (fConversionStreamerInfo) {
std::map<std::string, TObjArray*>::iterator it;
Expand Down Expand Up @@ -2268,18 +2272,28 @@ TClass *TClass::GetActualClass(const void *object) const
//will not work if the class derives from TObject but not as primary
//inheritance.
if (fIsAMethod==0) {
fIsAMethod = new TMethodCall((TClass*)this, "IsA", "");
TMethodCall* temp = new TMethodCall((TClass*)this, "IsA", "");

if (!fIsAMethod->GetMethod()) {
delete fIsAMethod;
fIsAMethod = 0;
if (!temp->GetMethod()) {
delete temp;
Error("IsA","Can not find any IsA function for %s!",GetName());
return (TClass*)this;
}

#if __cplusplus > 199711L
//Force cache to be updated here so do not have to worry about concurrency
temp->ReturnType();

TMethodCall* expected = nullptr;
if( not fIsAMethod.compare_exchange_strong(expected,temp) ) {
//another thread beat us to it
delete temp;
}
#else
fIsAMethod = temp;
#endif
}
char * char_result = 0;
fIsAMethod->Execute((void*)object, &char_result);
(*fIsAMethod).Execute((void*)object, &char_result);
return (TClass*)char_result;
}
}
Expand Down