proxygen
folly::threadlocal_detail::ElementWrapper Struct Reference

#include <ThreadLocalDetail.h>

Public Types

using DeleterFunType = void(void *, TLPDestructionMode)
 

Public Member Functions

bool dispose (TLPDestructionMode mode)
 
void * release ()
 
template<class Ptr >
void set (Ptr p)
 
template<class Ptr , class Deleter >
void set (Ptr p, const Deleter &d)
 
void cleanup ()
 

Public Attributes

void * ptr
 
union {
   DeleterFunType *   deleter1
 
   std::function< DeleterFunType > *   deleter2
 
}; 
 
bool ownsDeleter
 
ThreadEntryNode node
 

Detailed Description

POD wrapper around an element (a void*) and an associated deleter. This must be POD, as we memset() it to 0 and memcpy() it around.

Definition at line 118 of file ThreadLocalDetail.h.

Member Typedef Documentation

Member Function Documentation

void folly::threadlocal_detail::ElementWrapper::cleanup ( )
inline

Definition at line 180 of file ThreadLocalDetail.h.

References ptr.

180  {
181  if (ownsDeleter) {
182  delete deleter2;
183  }
184  ptr = nullptr;
185  deleter1 = nullptr;
186  ownsDeleter = false;
187  }
std::function< DeleterFunType > * deleter2
bool folly::threadlocal_detail::ElementWrapper::dispose ( TLPDestructionMode  mode)
inline

Definition at line 121 of file ThreadLocalDetail.h.

References mode, and ptr.

121  {
122  if (ptr == nullptr) {
123  return false;
124  }
125 
126  DCHECK(deleter1 != nullptr);
127  ownsDeleter ? (*deleter2)(ptr, mode) : (*deleter1)(ptr, mode);
128  return true;
129  }
folly::Optional< PskKeyExchangeMode > mode
void* folly::threadlocal_detail::ElementWrapper::release ( )
inline

Definition at line 131 of file ThreadLocalDetail.h.

References folly::ssl::cleanup(), and ptr.

Referenced by folly::ThreadLocalPtr< SubscriberMap >::release().

131  {
132  auto retPtr = ptr;
133 
134  if (ptr != nullptr) {
135  cleanup();
136  }
137 
138  return retPtr;
139  }
template<class Ptr >
void folly::threadlocal_detail::ElementWrapper::set ( Ptr  p)
inline

Definition at line 142 of file ThreadLocalDetail.h.

References folly::gen::guard(), folly::makeGuard(), and ptr.

142  {
143  auto guard = makeGuard([&] { delete p; });
144  DCHECK(ptr == nullptr);
145  DCHECK(deleter1 == nullptr);
146 
147  if (p) {
148  node.initIfZero(true /*locked*/);
149  ptr = p;
150  deleter1 = [](void* pt, TLPDestructionMode) {
151  delete static_cast<Ptr>(pt);
152  };
153  ownsDeleter = false;
154  guard.dismiss();
155  }
156  }
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
FOLLY_NODISCARD detail::ScopeGuardImplDecay< F, true > makeGuard(F &&f) noexcept(noexcept(detail::ScopeGuardImplDecay< F, true >(static_cast< F && >(f))))
Definition: ScopeGuard.h:184
template<class Ptr , class Deleter >
void folly::threadlocal_detail::ElementWrapper::set ( Ptr  p,
const Deleter &  d 
)
inline

Definition at line 159 of file ThreadLocalDetail.h.

References folly::gen::guard(), folly::makeGuard(), mode, ptr, and folly::THIS_THREAD.

159  {
160  auto guard = makeGuard([&] {
161  if (p) {
163  }
164  });
165  DCHECK(ptr == nullptr);
166  DCHECK(deleter2 == nullptr);
167  if (p) {
168  node.initIfZero(true /*locked*/);
169  ptr = p;
170  auto d2 = d; // gcc-4.8 doesn't decay types correctly in lambda captures
171  deleter2 = new std::function<DeleterFunType>(
172  [d2](void* pt, TLPDestructionMode mode) {
173  d2(static_cast<Ptr>(pt), mode);
174  });
175  ownsDeleter = true;
176  guard.dismiss();
177  }
178  }
std::function< DeleterFunType > * deleter2
folly::Optional< PskKeyExchangeMode > mode
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
FOLLY_NODISCARD detail::ScopeGuardImplDecay< F, true > makeGuard(F &&f) noexcept(noexcept(detail::ScopeGuardImplDecay< F, true >(static_cast< F && >(f))))
Definition: ScopeGuard.h:184

Member Data Documentation

union { ... }
DeleterFunType* folly::threadlocal_detail::ElementWrapper::deleter1
std::function<DeleterFunType>* folly::threadlocal_detail::ElementWrapper::deleter2

Definition at line 192 of file ThreadLocalDetail.h.

bool folly::threadlocal_detail::ElementWrapper::ownsDeleter

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