proxygen
folly::parking_lot_detail::Bucket Struct Reference

#include <ParkingLot.h>

Public Member Functions

void push_back (WaitNodeBase *node)
 
void erase (WaitNodeBase *node)
 

Static Public Member Functions

static BucketbucketFor (uint64_t key)
 

Public Attributes

std::mutex mutex_
 
WaitNodeBasehead_
 
WaitNodeBasetail_
 
std::atomic< uint64_tcount_
 

Detailed Description

Definition at line 79 of file ParkingLot.h.

Member Function Documentation

Bucket & folly::parking_lot_detail::Bucket::bucketFor ( uint64_t  key)
static

Definition at line 23 of file ParkingLot.cpp.

References folly::kIsMobile.

Referenced by folly::ParkingLot< Data >::park_until(), and folly::ParkingLot< Data >::unpark().

23  {
24  constexpr size_t const kNumBuckets = kIsMobile ? 256 : 4096;
25 
26  // Statically allocating this lets us use this in allocation-sensitive
27  // contexts. This relies on the assumption that std::mutex won't dynamically
28  // allocate memory, which we assume to be the case on Linux and iOS.
29  static Indestructible<std::array<Bucket, kNumBuckets>> gBuckets;
30  return (*gBuckets)[key % kNumBuckets];
31 }
constexpr auto kIsMobile
Definition: Portability.h:355
void folly::parking_lot_detail::Bucket::erase ( WaitNodeBase node)
inline

Definition at line 99 of file ParkingLot.h.

References FOLLY_SAFE_DCHECK, folly::parking_lot_detail::WaitNodeBase::next_, and folly::parking_lot_detail::WaitNodeBase::prev_.

99  {
100  FOLLY_SAFE_DCHECK(count_.load(std::memory_order_relaxed) >= 1, "");
101  if (head_ == node && tail_ == node) {
102  FOLLY_SAFE_DCHECK(node->prev_ == nullptr, "");
103  FOLLY_SAFE_DCHECK(node->next_ == nullptr, "");
104  head_ = nullptr;
105  tail_ = nullptr;
106  } else if (head_ == node) {
107  FOLLY_SAFE_DCHECK(node->prev_ == nullptr, "");
108  FOLLY_SAFE_DCHECK(node->next_, "");
109  head_ = node->next_;
110  head_->prev_ = nullptr;
111  } else if (tail_ == node) {
112  FOLLY_SAFE_DCHECK(node->next_ == nullptr, "");
113  FOLLY_SAFE_DCHECK(node->prev_, "");
114  tail_ = node->prev_;
115  tail_->next_ = nullptr;
116  } else {
117  FOLLY_SAFE_DCHECK(node->next_, "");
118  FOLLY_SAFE_DCHECK(node->prev_, "");
119  node->next_->prev_ = node->prev_;
120  node->prev_->next_ = node->next_;
121  }
122  count_.fetch_sub(1, std::memory_order_relaxed);
123  }
std::atomic< uint64_t > count_
Definition: ParkingLot.h:83
#define FOLLY_SAFE_DCHECK(expr, msg)
Definition: SafeAssert.h:42
void folly::parking_lot_detail::Bucket::push_back ( WaitNodeBase node)
inline

Definition at line 87 of file ParkingLot.h.

References FOLLY_SAFE_DCHECK, folly::parking_lot_detail::WaitNodeBase::next_, and folly::parking_lot_detail::WaitNodeBase::prev_.

87  {
88  if (tail_) {
90  node->prev_ = tail_;
91  tail_->next_ = node;
92  tail_ = node;
93  } else {
94  tail_ = node;
95  head_ = node;
96  }
97  }
#define FOLLY_SAFE_DCHECK(expr, msg)
Definition: SafeAssert.h:42

Member Data Documentation

std::atomic<uint64_t> folly::parking_lot_detail::Bucket::count_

Definition at line 83 of file ParkingLot.h.

WaitNodeBase* folly::parking_lot_detail::Bucket::head_

Definition at line 81 of file ParkingLot.h.

std::mutex folly::parking_lot_detail::Bucket::mutex_

Definition at line 80 of file ParkingLot.h.

WaitNodeBase* folly::parking_lot_detail::Bucket::tail_

Definition at line 82 of file ParkingLot.h.


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