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

A thread-local storage wrapper. More...

#include <ThreadLocalHolder.h>

Inheritance diagram for thread_utils::ThreadLocalHolder< T >:
Collaboration diagram for thread_utils::ThreadLocalHolder< 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

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::ThreadLocalHolder< T >

A thread-local storage wrapper.

This container is implemented as a wrapper for a concurrent map keyed by std thread ID. It is thus fully thread-safe (in theory).

This container is non-owning. It doesn't clean up memory. For a corresponding container which owns its objects, see ThreadLocalOwner.

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

Definition at line 48 of file ThreadLocalHolder.h.

Member Typedef Documentation

◆ MapHash_t

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

Definition at line 55 of file ThreadLocalHolder.h.

◆ MapKey_t

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

Definition at line 53 of file ThreadLocalHolder.h.

◆ MapVal_t

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

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 >

Definition at line 56 of file ThreadLocalHolder.h.

Member Function Documentation

◆ get()

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

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
inline

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)
inline

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
protected

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:132