ATLAS Offline Software
Loading...
Searching...
No Matches
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

Public Member Functions

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

Protected Attributes

ThreadMap_t m_threadMap
 The wrapped thread-local storage container.

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
inherited
Initial value:
tbb::concurrent_unordered_map< MapKey_t, MapVal_t, MapHash_t >

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 }
ThreadMap_t m_threadMap
The wrapped thread-local storage container.
A ThreadLocalHolder which owns its objects.

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 {
62 if(itr == m_threadMap.end()) return nullptr;
63 return itr->second;
64 }
A thread-local storage wrapper.

◆ 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();
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: