ATLAS Offline Software
Public Types | Public Member Functions | Protected Attributes | List of all members
thread_utils::ThreadLocalOwner< T > Class Template Reference

A ThreadLocalHolder which owns its objects. More...

#include <ThreadLocalHolder.h>

Inheritance diagram for thread_utils::ThreadLocalOwner< T >:
Collaboration diagram for thread_utils::ThreadLocalOwner< T >:

Public Types

using MapKey_t = std::thread::id
 
using MapVal_t = T *
 
using MapHash_t = std::hash< MapKey_t >
 
using ThreadMap_t = tbb::concurrent_unordered_map< MapKey_t, MapVal_t, MapHash_t >
 

Public Member Functions

 ~ThreadLocalOwner ()
 Destructor will clean up the storage. More...
 
T * get ()
 Get the object of the current thread. More...
 
void set (T *obj)
 Assign the object of the current thread. More...
 
const ThreadMap_tgetMap () const
 Constant access for iteration, etc. More...
 

Protected Attributes

ThreadMap_t m_threadMap
 The wrapped thread-local storage container. More...
 

Detailed Description

template<class T>
class thread_utils::ThreadLocalOwner< T >

A ThreadLocalHolder which owns its objects.

This class merely adds deletion of the map elements in the destructor.

Author
Steve Farrell Steve.nosp@m.n.Fa.nosp@m.rrell.nosp@m.@cer.nosp@m.n.ch

Definition at line 93 of file ThreadLocalHolder.h.

Member Typedef Documentation

◆ MapHash_t

template<class T >
using thread_utils::ThreadLocalHolder< T >::MapHash_t = std::hash<MapKey_t>
inherited

Definition at line 55 of file ThreadLocalHolder.h.

◆ MapKey_t

template<class T >
using thread_utils::ThreadLocalHolder< T >::MapKey_t = std::thread::id
inherited

Definition at line 53 of file ThreadLocalHolder.h.

◆ MapVal_t

template<class T >
using thread_utils::ThreadLocalHolder< T >::MapVal_t = T*
inherited

Definition at line 54 of file ThreadLocalHolder.h.

◆ ThreadMap_t

template<class T >
using thread_utils::ThreadLocalHolder< T >::ThreadMap_t = tbb::concurrent_unordered_map< MapKey_t, MapVal_t, MapHash_t >
inherited

Definition at line 56 of file ThreadLocalHolder.h.

Constructor & Destructor Documentation

◆ ~ThreadLocalOwner()

template<class T >
thread_utils::ThreadLocalOwner< T >::~ThreadLocalOwner ( )
inline

Destructor will clean up the storage.

Definition at line 97 of file ThreadLocalHolder.h.

97  {
98  for(auto& mapPair : this->m_threadMap)
99  delete mapPair.second;
100  }

Member Function Documentation

◆ get()

template<class T >
T* thread_utils::ThreadLocalHolder< T >::get ( )
inlineinherited

Get the object of the current thread.

Definition at line 60 of file ThreadLocalHolder.h.

60  {
61  auto itr = m_threadMap.find( std::this_thread::get_id() );
62  if(itr == m_threadMap.end()) return nullptr;
63  return itr->second;
64  }

◆ getMap()

template<class T >
const ThreadMap_t& thread_utils::ThreadLocalHolder< T >::getMap ( ) const
inlineinherited

Constant access for iteration, etc.

Definition at line 73 of file ThreadLocalHolder.h.

73  {
74  return m_threadMap;
75  }

◆ set()

template<class T >
void thread_utils::ThreadLocalHolder< T >::set ( T *  obj)
inlineinherited

Assign the object of the current thread.

Definition at line 67 of file ThreadLocalHolder.h.

67  {
68  const auto tid = std::this_thread::get_id();
69  m_threadMap.insert( std::make_pair(tid, obj) );
70  }

Member Data Documentation

◆ m_threadMap

template<class T >
ThreadMap_t thread_utils::ThreadLocalHolder< T >::m_threadMap
protectedinherited

The wrapped thread-local storage container.

Definition at line 80 of file ThreadLocalHolder.h.


The documentation for this class was generated from the following file:
thread_utils::ThreadLocalHolder::m_threadMap
ThreadMap_t m_threadMap
The wrapped thread-local storage container.
Definition: ThreadLocalHolder.h:80
python.PyAthena.obj
obj
Definition: PyAthena.py:135