proxygen
folly::fibers::CacheManager Class Reference

Public Member Functions

std::unique_ptr< StackCacheEntrygetStackCache (size_t stackSize)
 

Static Public Member Functions

static CacheManagerinstance ()
 

Private Member Functions

void giveBack (std::unique_ptr< StackCache >)
 

Private Attributes

folly::SpinLock lock_
 
size_t inUse_ {0}
 

Friends

class StackCacheEntry
 

Detailed Description

Definition at line 236 of file GuardPageAllocator.cpp.

Member Function Documentation

std::unique_ptr<StackCacheEntry> folly::fibers::CacheManager::getStackCache ( size_t  stackSize)
inline

Definition at line 243 of file GuardPageAllocator.cpp.

References folly::fibers::StackCache::lock_.

Referenced by folly::fibers::GuardPageAllocator::allocate().

243  {
244  std::lock_guard<folly::SpinLock> lg(lock_);
245  if (inUse_ < kMaxInUse) {
246  ++inUse_;
247  return std::make_unique<StackCacheEntry>(stackSize);
248  }
249 
250  return nullptr;
251  }
constexpr size_t kMaxInUse
void folly::fibers::CacheManager::giveBack ( std::unique_ptr< StackCache )
inlineprivate

Definition at line 259 of file GuardPageAllocator.cpp.

Referenced by folly::fibers::StackCacheEntry::~StackCacheEntry().

259  {
260  assert(inUse_ > 0);
261  --inUse_;
262  /* Note: we can add a free list for each size bucket
263  if stack re-use is important.
264  In this case this needs to be a folly::Singleton
265  to make sure the free list is cleaned up on fork.
266 
267  TODO(t7351705): fix Singleton destruction order
268  */
269  }
static CacheManager& folly::fibers::CacheManager::instance ( )
inlinestatic

Definition at line 238 of file GuardPageAllocator.cpp.

Referenced by folly::fibers::GuardPageAllocator::allocate(), and folly::fibers::StackCacheEntry::~StackCacheEntry().

238  {
239  static auto inst = new CacheManager();
240  return *inst;
241  }

Friends And Related Function Documentation

friend class StackCacheEntry
friend

Definition at line 257 of file GuardPageAllocator.cpp.

Member Data Documentation

size_t folly::fibers::CacheManager::inUse_ {0}
private

Definition at line 255 of file GuardPageAllocator.cpp.

folly::SpinLock folly::fibers::CacheManager::lock_
private

Definition at line 254 of file GuardPageAllocator.cpp.


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