proxygen
folly::fibers::Fiber::LocalData Class Reference

Public Member Functions

 LocalData ()
 
 ~LocalData ()
 
 LocalData (const LocalData &other)
 
LocalDataoperator= (const LocalData &other)
 
template<typename T >
Tget ()
 
void reset ()
 
template<typename T >
FOLLY_NOINLINE TgetSlow ()
 
template<typename T >
TgetSlow ()
 

Static Public Member Functions

static void * allocateHeapBuffer (size_t size)
 
static void freeHeapBuffer (void *buffer)
 
template<typename T >
static void dataCopyConstructor (void *, const void *)
 
template<typename T >
static void dataBufferDestructor (void *)
 
template<typename T >
static void dataHeapDestructor (void *)
 

Public Attributes

std::aligned_storage< kBufferSize >::type buffer_
 
size_t dataSize_
 
const std::type_info * dataType_
 
void(* dataDestructor_ )(void *)
 
void(* dataCopyConstructor_ )(void *, const void *)
 
void * data_ {nullptr}
 

Static Public Attributes

static constexpr size_t kBufferSize = 128
 

Detailed Description

Definition at line 131 of file Fiber.h.

Constructor & Destructor Documentation

folly::fibers::Fiber::LocalData::LocalData ( )
inline

Definition at line 133 of file Fiber.h.

References operator=(), and ~LocalData().

133 {}
folly::fibers::Fiber::LocalData::~LocalData ( )

Definition at line 197 of file Fiber.cpp.

Referenced by LocalData().

197  {
198  reset();
199 }
folly::fibers::Fiber::LocalData::LocalData ( const LocalData other)

Definition at line 201 of file Fiber.cpp.

201  : data_(nullptr) {
202  *this = other;
203 }

Member Function Documentation

void * folly::fibers::Fiber::LocalData::allocateHeapBuffer ( size_t  size)
static

Definition at line 236 of file Fiber.cpp.

References folly::size().

Referenced by get(), and operator=().

236  {
237  return new char[size];
238 }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
template<typename T >
void folly::fibers::Fiber::LocalData::dataBufferDestructor ( void *  ptr)
static

Definition at line 66 of file Fiber-inl.h.

References ptr, and folly::T.

Referenced by get().

66  {
67  reinterpret_cast<T*>(ptr)->~T();
68 }
void * ptr
folly::std T
template<typename T >
void folly::fibers::Fiber::LocalData::dataCopyConstructor ( void *  ptr,
const void *  other 
)
static

Definition at line 61 of file Fiber-inl.h.

References ptr, and folly::T.

Referenced by get().

61  {
62  new (reinterpret_cast<T*>(ptr)) T(*reinterpret_cast<const T*>(other));
63 }
void * ptr
folly::std T
template<typename T >
void folly::fibers::Fiber::LocalData::dataHeapDestructor ( void *  ptr)
static

Definition at line 71 of file Fiber-inl.h.

References ptr, and folly::T.

Referenced by get().

71  {
72  reinterpret_cast<T*>(ptr)->~T();
74 }
void * ptr
static void freeHeapBuffer(void *buffer)
Definition: Fiber.cpp:240
folly::std T
void folly::fibers::Fiber::LocalData::freeHeapBuffer ( void *  buffer)
static

Definition at line 240 of file Fiber.cpp.

References buffer().

Referenced by get().

240  {
241  delete[] reinterpret_cast<char*>(buffer);
242 }
std::vector< uint8_t > buffer(kBufferSize+16)
template<typename T >
T& folly::fibers::Fiber::LocalData::get ( )
inline

Definition at line 139 of file Fiber.h.

References allocateHeapBuffer(), buffer(), data_, dataBufferDestructor(), dataCopyConstructor(), dataHeapDestructor(), dataType_, FOLLY_NOINLINE, freeHeapBuffer(), getSlow(), reset(), folly::size(), and folly::T.

Referenced by folly::fibers::FiberManager::local().

139  {
140  if (data_) {
141  assert(*dataType_ == typeid(T));
142  return *reinterpret_cast<T*>(data_);
143  }
144  return getSlow<T>();
145  }
const std::type_info * dataType_
Definition: Fiber.h:167
folly::std T
template<typename T >
T& folly::fibers::Fiber::LocalData::getSlow ( )

Definition at line 43 of file Fiber-inl.h.

References buffer_, data_, kBufferSize, and folly::T.

43  {
44  dataSize_ = sizeof(T);
45  dataType_ = &typeid(T);
46  if (sizeof(T) <= kBufferSize) {
47  dataDestructor_ = dataBufferDestructor<T>;
48  data_ = &buffer_;
49  } else {
50  dataDestructor_ = dataHeapDestructor<T>;
52  }
53  dataCopyConstructor_ = dataCopyConstructor<T>;
54 
55  new (reinterpret_cast<T*>(data_)) T();
56 
57  return *reinterpret_cast<T*>(data_);
58 }
void(* dataDestructor_)(void *)
Definition: Fiber.h:168
std::aligned_storage< kBufferSize >::type buffer_
Definition: Fiber.h:164
const std::type_info * dataType_
Definition: Fiber.h:167
folly::std T
static void * allocateHeapBuffer(size_t size)
Definition: Fiber.cpp:236
static constexpr size_t kBufferSize
Definition: Fiber.h:163
void(* dataCopyConstructor_)(void *, const void *)
Definition: Fiber.h:169
template<typename T >
FOLLY_NOINLINE T& folly::fibers::Fiber::LocalData::getSlow ( )

Referenced by get().

Fiber::LocalData & folly::fibers::Fiber::LocalData::operator= ( const LocalData other)

Definition at line 205 of file Fiber.cpp.

References allocateHeapBuffer(), buffer_, data_, dataCopyConstructor_, dataDestructor_, dataSize_, dataType_, kBufferSize, and reset().

Referenced by LocalData().

205  {
206  reset();
207  if (!other.data_) {
208  return *this;
209  }
210 
211  dataSize_ = other.dataSize_;
212  dataType_ = other.dataType_;
213  dataDestructor_ = other.dataDestructor_;
214  dataCopyConstructor_ = other.dataCopyConstructor_;
215 
216  if (dataSize_ <= kBufferSize) {
217  data_ = &buffer_;
218  } else {
220  }
221 
222  dataCopyConstructor_(data_, other.data_);
223 
224  return *this;
225 }
void(* dataDestructor_)(void *)
Definition: Fiber.h:168
std::aligned_storage< kBufferSize >::type buffer_
Definition: Fiber.h:164
const std::type_info * dataType_
Definition: Fiber.h:167
static void * allocateHeapBuffer(size_t size)
Definition: Fiber.cpp:236
static constexpr size_t kBufferSize
Definition: Fiber.h:163
void(* dataCopyConstructor_)(void *, const void *)
Definition: Fiber.h:169
void folly::fibers::Fiber::LocalData::reset ( )

Definition at line 227 of file Fiber.cpp.

References data_, and dataDestructor_.

Referenced by get(), operator=(), and folly::fibers::FiberManager::runReadyFiber().

227  {
228  if (!data_) {
229  return;
230  }
231 
233  data_ = nullptr;
234 }
void(* dataDestructor_)(void *)
Definition: Fiber.h:168

Member Data Documentation

std::aligned_storage<kBufferSize>::type folly::fibers::Fiber::LocalData::buffer_

Definition at line 164 of file Fiber.h.

Referenced by operator=().

void* folly::fibers::Fiber::LocalData::data_ {nullptr}

Definition at line 170 of file Fiber.h.

Referenced by get(), operator=(), and reset().

void(* folly::fibers::Fiber::LocalData::dataCopyConstructor_) (void *, const void *)

Definition at line 169 of file Fiber.h.

Referenced by operator=().

void(* folly::fibers::Fiber::LocalData::dataDestructor_) (void *)

Definition at line 168 of file Fiber.h.

Referenced by operator=(), and reset().

size_t folly::fibers::Fiber::LocalData::dataSize_

Definition at line 165 of file Fiber.h.

Referenced by operator=().

const std::type_info* folly::fibers::Fiber::LocalData::dataType_

Definition at line 167 of file Fiber.h.

Referenced by get(), and operator=().

constexpr size_t folly::fibers::Fiber::LocalData::kBufferSize = 128
static

Definition at line 163 of file Fiber.h.

Referenced by operator=().


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