ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::Internal::THolderCache Class Reference

Singleton, thread-safe THolder cache. More...

#include <THolderCache.h>

Collaboration diagram for xAOD::Internal::THolderCache:

Public Member Functions

std::pair< bool, ::TClass * > getClass (const std::type_info &ti) const
 Get the dictionary for a given type info.
void addClass (const std::type_info &ti, ::TClass *cl)
 Add the dictionary for a given type.
int getRef (void *ptr) const
 Get the reference count of an object in memory.
int incRef (void *ptr)
 Increment the reference count of an object in memory.
int decRef (void *ptr)
 Decrease the reference count of an object in memory.

Static Public Member Functions

static THolderCache & instance ()
 Singleton accessor.

Private Member Functions

 THolderCache ()
 Hide the constructor of the class from the outside.
 THolderCache (const THolderCache &)=delete
 Delete the copy constructor.

Private Attributes

std::map< const std::type_info *, TClass * > m_typeMap
 The type map.
std::map< void *, int > m_refMap
 The reference count map.
std::shared_timed_mutex m_typeMapMutex
 Mutex for the type map.
std::shared_timed_mutex m_refMapMutex
 Mutex for the reference count map.

Detailed Description

Singleton, thread-safe THolder cache.

The xAOD::THolder class needs to keep some global caches internally, due to the way it manages its own memory. This singleton helps doing that in a thread-safe way.

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 31 of file THolderCache.h.

Constructor & Destructor Documentation

◆ THolderCache() [1/2]

xAOD::Internal::THolderCache::THolderCache ( )
private

Hide the constructor of the class from the outside.

Definition at line 105 of file THolderCache.cxx.

107
108 }
std::shared_timed_mutex m_typeMapMutex
Mutex for the type map.
std::shared_timed_mutex m_refMapMutex
Mutex for the reference count map.
std::map< const std::type_info *, TClass * > m_typeMap
The type map.
std::map< void *, int > m_refMap
The reference count map.

◆ THolderCache() [2/2]

xAOD::Internal::THolderCache::THolderCache ( const THolderCache & )
privatedelete

Delete the copy constructor.

Member Function Documentation

◆ addClass()

void xAOD::Internal::THolderCache::addClass ( const std::type_info & ti,
::TClass * cl )

Add the dictionary for a given type.

Definition at line 49 of file THolderCache.cxx.

49 {
50
51 // Get a "write lock":
53
54 // Extend the map:
55 m_typeMap[ &ti ] = cl;
56 }
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
std::unique_lock< std::shared_timed_mutex > unique_lock_t
Helper type definition.

◆ decRef()

int xAOD::Internal::THolderCache::decRef ( void * ptr)

Decrease the reference count of an object in memory.

Definition at line 81 of file THolderCache.cxx.

81 {
82
83 // Get a "write lock":
85
86 // Check if we know about this pointer:
87 auto itr = m_refMap.find( ptr );
88 if( itr == m_refMap.end() ) {
89 return 0;
90 }
91
92 // Decrease the reference count, and remember the value:
93 const int count = --( m_refMap[ ptr ] );
94
95 // If the reference count went down to zero, let's forget about this
96 // pointer:
97 if( count == 0 ) {
98 m_refMap.erase( itr );
99 }
100
101 // Return the new count:
102 return count;
103 }
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
void * ptr(T *p)
Definition SGImplSvc.cxx:76

◆ getClass()

std::pair< bool,::TClass * > xAOD::Internal::THolderCache::getClass ( const std::type_info & ti) const

Get the dictionary for a given type info.

Definition at line 35 of file THolderCache.cxx.

35 {
36
37 // Get a "read lock":
39
40 // Look for the type in the cache:
41 auto itr = m_typeMap.find( &ti );
42 if( itr != m_typeMap.end() ) {
43 return std::pair< bool, ::TClass* >( true, itr->second );
44 } else {
45 return std::pair< bool, ::TClass* >( false, nullptr );
46 }
47 }
std::shared_lock< std::shared_timed_mutex > shared_lock_t
Helper type definition.

◆ getRef()

int xAOD::Internal::THolderCache::getRef ( void * ptr) const

Get the reference count of an object in memory.

Definition at line 58 of file THolderCache.cxx.

58 {
59
60 // Get a "read lock":
62
63 // Get the reference count:
64 auto itr = m_refMap.find( ptr );
65 if( itr != m_refMap.end() ) {
66 return itr->second;
67 } else {
68 return 0;
69 }
70 }

◆ incRef()

int xAOD::Internal::THolderCache::incRef ( void * ptr)

Increment the reference count of an object in memory.

Definition at line 72 of file THolderCache.cxx.

72 {
73
74 // Get a "write lock":
76
77 // Increment the reference count, and return the new value:
78 return ++( m_refMap[ ptr ] );
79 }

◆ instance()

THolderCache & xAOD::Internal::THolderCache::instance ( )
static

Singleton accessor.

Definition at line 29 of file THolderCache.cxx.

29 {
30 static THolderCache cache ATLAS_THREAD_SAFE; // this class is thread-safe
31 return cache;
32 }
#define ATLAS_THREAD_SAFE
THolderCache()
Hide the constructor of the class from the outside.
const IIntersectionCache * cache() const
Retrieve the associated cache block, if it exists.

Member Data Documentation

◆ m_refMap

std::map< void*, int > xAOD::Internal::THolderCache::m_refMap
private

The reference count map.

Definition at line 59 of file THolderCache.h.

◆ m_refMapMutex

std::shared_timed_mutex xAOD::Internal::THolderCache::m_refMapMutex
mutableprivate

Mutex for the reference count map.

Definition at line 64 of file THolderCache.h.

◆ m_typeMap

std::map< const std::type_info*, TClass* > xAOD::Internal::THolderCache::m_typeMap
private

The type map.

Definition at line 57 of file THolderCache.h.

◆ m_typeMapMutex

std::shared_timed_mutex xAOD::Internal::THolderCache::m_typeMapMutex
mutableprivate

Mutex for the type map.

Definition at line 62 of file THolderCache.h.


The documentation for this class was generated from the following files: