ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 
void addClass (const std::type_info &ti, ::TClass *cl)
 Add the dictionary for a given type. More...
 
int getRef (void *ptr) const
 Get the reference count of an object in memory. More...
 
int incRef (void *ptr)
 Increment the reference count of an object in memory. More...
 
int decRef (void *ptr)
 Decrease the reference count of an object in memory. More...
 

Static Public Member Functions

static THolderCacheinstance ()
 Singleton accessor. More...
 

Private Member Functions

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

Private Attributes

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

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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

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:
xAOD::Internal::THolderCache::m_refMap
std::map< void *, int > m_refMap
The reference count map.
Definition: THolderCache.h:59
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
xAOD::Internal::THolderCache::m_typeMap
std::map< const std::type_info *, TClass * > m_typeMap
The type map.
Definition: THolderCache.h:57
xAOD::Internal::THolderCache::m_typeMapMutex
std::shared_timed_mutex m_typeMapMutex
Mutex for the type map.
Definition: THolderCache.h:62
xAOD::Internal::THolderCache::THolderCache
THolderCache()
Hide the constructor of the class from the outside.
Definition: THolderCache.cxx:105
xAOD::Internal::unique_lock_t
std::unique_lock< std::shared_timed_mutex > unique_lock_t
Helper type definition.
Definition: THolderCache.cxx:27
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
xAOD::Internal::THolderCache::m_refMapMutex
std::shared_timed_mutex m_refMapMutex
Mutex for the reference count map.
Definition: THolderCache.h:64
xAOD::Internal::shared_lock_t
std::shared_lock< std::shared_timed_mutex > shared_lock_t
Helper type definition.
Definition: THolderCache.cxx:25