Skip to content
Snippets Groups Projects
Commit 11e0e6d6 authored by Philippe Canal's avatar Philippe Canal
Browse files

TIsAProxy switch fClass to non-atomic.

Since fClass is modified only 'once' at init time of the IsAProxy object, it is actual more efficient
to protect the initialization by a lock rather than having fClass being atomic.
parent 6587b658
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ private: ...@@ -36,7 +36,7 @@ private:
static constexpr UInt_t fgMaxLastSlot = 8; static constexpr UInt_t fgMaxLastSlot = 8;
const std::type_info *fType; //Actual typeid of the proxy const std::type_info *fType; //Actual typeid of the proxy
Atomic_t<TClass*> fClass; //Actual TClass TClass *fClass; //Actual TClass
Char_t fSubTypes[72];//map of known sub-types Char_t fSubTypes[72];//map of known sub-types
mutable Atomic_t<UInt_t> fSubTypesReaders; //number of readers of fSubTypes mutable Atomic_t<UInt_t> fSubTypesReaders; //number of readers of fSubTypes
Atomic_t<Bool_t> fSubTypesWriteLockTaken; //True if there is a writer Atomic_t<Bool_t> fSubTypesWriteLockTaken; //True if there is a writer
......
...@@ -85,30 +85,29 @@ void TIsAProxy::SetClass(TClass *cl) ...@@ -85,30 +85,29 @@ void TIsAProxy::SetClass(TClass *cl)
TClass* TIsAProxy::operator()(const void *obj) TClass* TIsAProxy::operator()(const void *obj)
{ {
if ( !fInit ) { if ( !fInit ) {
if ( !fClass.load() && fType ) { R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
auto cls = TClass::GetClass(*fType); if ( !fClass && fType ) {
TClass* expected = nullptr; fClass = TClass::GetClass(*fType);
fClass.compare_exchange_strong(expected,cls);
} }
if ( !fClass.load() ) return nullptr; if ( !fClass ) return nullptr;
fVirtual = (*fClass).ClassProperty() & kClassHasVirtual; fVirtual = (*fClass).ClassProperty() & kClassHasVirtual;
fInit = kTRUE; fInit = kTRUE;
} }
if ( !obj || !fVirtual ) { if ( !obj || !fVirtual ) {
return fClass.load(); return fClass;
} }
// Avoid the case that the first word is a virtual_base_offset_table instead of // Avoid the case that the first word is a virtual_base_offset_table instead of
// a virtual_function_table // a virtual_function_table
Long_t offset = **(Long_t**)obj; Long_t offset = **(Long_t**)obj;
if ( offset == 0 ) { if ( offset == 0 ) {
return fClass.load(); return fClass;
} }
DynamicType* ptr = (DynamicType*)obj; DynamicType* ptr = (DynamicType*)obj;
const std::type_info* typ = &typeid(*ptr); const std::type_info* typ = &typeid(*ptr);
if ( typ == fType ) { if ( typ == fType ) {
return fClass.load(); return fClass;
} }
for(auto& slot : fLasts) { for(auto& slot : fLasts) {
auto last = ToPair(slot); auto last = ToPair(slot);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment