proxygen
folly::ThreadLocal< T, Tag, AccessMode > Class Template Reference

#include <ThreadLocal.h>

Public Types

typedef ThreadLocalPtr< T, Tag, AccessMode >::Accessor Accessor
 

Public Member Functions

constexpr ThreadLocal ()
 
template<typename F , _t< std::enable_if< is_invocable_r< T *, F >::value, int >> = 0>
 ThreadLocal (F &&constructor)
 
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN Tget () const
 
Toperator-> () const
 
Toperator* () const
 
void reset (T *newPtr=nullptr)
 
Accessor accessAllThreads () const
 
 ThreadLocal (ThreadLocal &&)=default
 
ThreadLocaloperator= (ThreadLocal &&)=default
 

Private Member Functions

 ThreadLocal (const ThreadLocal &)=delete
 
ThreadLocaloperator= (const ThreadLocal &)=delete
 
FOLLY_NOINLINE TmakeTlp () const
 

Private Attributes

ThreadLocalPtr< T, Tag, AccessMode > tlp_
 
std::function< T *()> constructor_
 

Detailed Description

template<class T, class Tag = void, class AccessMode = void>
class folly::ThreadLocal< T, Tag, AccessMode >

Definition at line 59 of file ThreadLocal.h.

Member Typedef Documentation

template<class T, class Tag = void, class AccessMode = void>
typedef ThreadLocalPtr<T, Tag, AccessMode>::Accessor folly::ThreadLocal< T, Tag, AccessMode >::Accessor

Definition at line 86 of file ThreadLocal.h.

Constructor & Destructor Documentation

template<class T, class Tag = void, class AccessMode = void>
constexpr folly::ThreadLocal< T, Tag, AccessMode >::ThreadLocal ( )
inline

Definition at line 61 of file ThreadLocal.h.

Referenced by folly::ThreadLocal< std::queue< folly::Function > >::accessAllThreads().

61 : constructor_([]() { return new T(); }) {}
std::function< T *()> constructor_
Definition: ThreadLocal.h:107
folly::std T
template<class T, class Tag = void, class AccessMode = void>
template<typename F , _t< std::enable_if< is_invocable_r< T *, F >::value, int >> = 0>
folly::ThreadLocal< T, Tag, AccessMode >::ThreadLocal ( F &&  constructor)
inlineexplicit

Definition at line 66 of file ThreadLocal.h.

67  : constructor_(std::forward<F>(constructor)) {}
std::function< T *()> constructor_
Definition: ThreadLocal.h:107
template<class T, class Tag = void, class AccessMode = void>
folly::ThreadLocal< T, Tag, AccessMode >::ThreadLocal ( ThreadLocal< T, Tag, AccessMode > &&  )
default
template<class T, class Tag = void, class AccessMode = void>
folly::ThreadLocal< T, Tag, AccessMode >::ThreadLocal ( const ThreadLocal< T, Tag, AccessMode > &  )
privatedelete

Member Function Documentation

template<class T, class Tag = void, class AccessMode = void>
Accessor folly::ThreadLocal< T, Tag, AccessMode >::accessAllThreads ( ) const
inline

Definition at line 87 of file ThreadLocal.h.

Referenced by folly::SingletonThreadLocal< T, Tag, Make, TLTag >::accessAllThreads(), SimpleThreadCachedInt::read(), and TEST().

87  {
88  return tlp_.accessAllThreads();
89  }
ThreadLocalPtr< T, Tag, AccessMode > tlp_
Definition: ThreadLocal.h:106
template<class T, class Tag = void, class AccessMode = void>
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN T* folly::ThreadLocal< T, Tag, AccessMode >::get ( ) const
inline

Definition at line 69 of file ThreadLocal.h.

Referenced by TEST().

69  {
70  auto const ptr = tlp_.get();
71  return FOLLY_LIKELY(!!ptr) ? ptr : makeTlp();
72  }
void * ptr
FOLLY_NOINLINE T * makeTlp() const
Definition: ThreadLocal.h:100
ThreadLocalPtr< T, Tag, AccessMode > tlp_
Definition: ThreadLocal.h:106
#define FOLLY_LIKELY(x)
Definition: Likely.h:35
template<class T, class Tag = void, class AccessMode = void>
FOLLY_NOINLINE T* folly::ThreadLocal< T, Tag, AccessMode >::makeTlp ( ) const
inlineprivate

Definition at line 100 of file ThreadLocal.h.

Referenced by folly::ThreadLocal< std::queue< folly::Function > >::get().

100  {
101  auto const ptr = constructor_();
102  tlp_.reset(ptr);
103  return ptr;
104  }
void * ptr
std::function< T *()> constructor_
Definition: ThreadLocal.h:107
ThreadLocalPtr< T, Tag, AccessMode > tlp_
Definition: ThreadLocal.h:106
template<class T, class Tag = void, class AccessMode = void>
T& folly::ThreadLocal< T, Tag, AccessMode >::operator* ( ) const
inline

Definition at line 78 of file ThreadLocal.h.

78  {
79  return *get();
80  }
template<class T, class Tag = void, class AccessMode = void>
T* folly::ThreadLocal< T, Tag, AccessMode >::operator-> ( ) const
inline

Definition at line 74 of file ThreadLocal.h.

74  {
75  return get();
76  }
template<class T, class Tag = void, class AccessMode = void>
ThreadLocal& folly::ThreadLocal< T, Tag, AccessMode >::operator= ( ThreadLocal< T, Tag, AccessMode > &&  )
default
template<class T, class Tag = void, class AccessMode = void>
ThreadLocal& folly::ThreadLocal< T, Tag, AccessMode >::operator= ( const ThreadLocal< T, Tag, AccessMode > &  )
privatedelete
template<class T, class Tag = void, class AccessMode = void>
void folly::ThreadLocal< T, Tag, AccessMode >::reset ( T newPtr = nullptr)
inline

Definition at line 82 of file ThreadLocal.h.

Referenced by folly::ThreadLocalPtr< SubscriberMap >::reset(), and TEST().

82  {
83  tlp_.reset(newPtr);
84  }
ThreadLocalPtr< T, Tag, AccessMode > tlp_
Definition: ThreadLocal.h:106

Member Data Documentation

template<class T, class Tag = void, class AccessMode = void>
std::function<T*()> folly::ThreadLocal< T, Tag, AccessMode >::constructor_
private

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