proxygen
folly::DefaultKeepAliveExecutor::WeakRef Class Reference
Inheritance diagram for folly::DefaultKeepAliveExecutor::WeakRef:
folly::Executor

Public Member Functions

void add (Func f) override
 
void addWithPriority (Func f, int8_t priority) override
 
virtual uint8_t getNumPriorities () const override
 
- Public Member Functions inherited from folly::Executor
virtual ~Executor ()
 

Static Public Member Functions

static folly::Executor::KeepAlive create (std::shared_ptr< ControlBlock > controlBlock, Executor *executor)
 
- Static Public Member Functions inherited from folly::Executor
template<typename ExecutorT >
static KeepAlive< ExecutorT > getKeepAliveToken (ExecutorT *executor)
 
template<typename ExecutorT >
static KeepAlive< ExecutorT > getKeepAliveToken (ExecutorT &executor)
 

Private Member Functions

 WeakRef (std::shared_ptr< ControlBlock > controlBlock, Executor *executor)
 
bool keepAliveAcquire () override
 
void keepAliveRelease () override
 
folly::Executor::KeepAlive lock ()
 

Private Attributes

std::atomic< size_t > keepAliveCount_ {1}
 
std::shared_ptr< ControlBlockcontrolBlock_
 
Executorexecutor_
 
uint8_t numPriorities_
 

Additional Inherited Members

- Static Public Attributes inherited from folly::Executor
static const int8_t LO_PRI = SCHAR_MIN
 
static const int8_t MID_PRI = 0
 
static const int8_t HI_PRI = SCHAR_MAX
 
- Static Protected Member Functions inherited from folly::Executor
template<typename ExecutorT >
static bool isKeepAliveDummy (const KeepAlive< ExecutorT > &keepAlive)
 
template<typename ExecutorT >
static KeepAlive< ExecutorT > makeKeepAlive (ExecutorT *executor)
 

Detailed Description

Definition at line 54 of file DefaultKeepAliveExecutor.h.

Constructor & Destructor Documentation

folly::DefaultKeepAliveExecutor::WeakRef::WeakRef ( std::shared_ptr< ControlBlock controlBlock,
Executor executor 
)
inlineprivate

Definition at line 79 of file DefaultKeepAliveExecutor.h.

80  : controlBlock_(std::move(controlBlock)),
82  numPriorities_(executor->getNumPriorities()) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< ControlBlock > controlBlock_
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor

Member Function Documentation

void folly::DefaultKeepAliveExecutor::WeakRef::add ( Func  )
inlineoverridevirtual

Enqueue a function to executed by this executor. This and all variants must be threadsafe.

Implements folly::Executor.

Definition at line 62 of file DefaultKeepAliveExecutor.h.

References folly::pushmi::executor, folly::lock(), and folly::gen::move.

62  {
63  if (auto executor = lock()) {
64  executor->add(std::move(f));
65  }
66  }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
void folly::DefaultKeepAliveExecutor::WeakRef::addWithPriority ( Func  ,
int8_t  priority 
)
inlineoverridevirtual

Enqueue a function with a given priority, where 0 is the medium priority This is up to the implementation to enforce

Reimplemented from folly::Executor.

Definition at line 68 of file DefaultKeepAliveExecutor.h.

References folly::pushmi::executor, folly::lock(), and folly::gen::move.

68  {
69  if (auto executor = lock()) {
70  executor->addWithPriority(std::move(f), priority);
71  }
72  }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
static folly::Executor::KeepAlive folly::DefaultKeepAliveExecutor::WeakRef::create ( std::shared_ptr< ControlBlock controlBlock,
Executor executor 
)
inlinestatic

Definition at line 56 of file DefaultKeepAliveExecutor.h.

References folly::Executor::makeKeepAlive(), and folly::gen::move.

Referenced by folly::DefaultKeepAliveExecutor::weakRef().

58  {
59  return makeKeepAlive(new WeakRef(std::move(controlBlock), executor));
60  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
WeakRef(std::shared_ptr< ControlBlock > controlBlock, Executor *executor)
static KeepAlive< ExecutorT > makeKeepAlive(ExecutorT *executor)
Definition: Executor.h:179
virtual uint8_t folly::DefaultKeepAliveExecutor::WeakRef::getNumPriorities ( ) const
inlineoverridevirtual

Reimplemented from folly::Executor.

Definition at line 74 of file DefaultKeepAliveExecutor.h.

bool folly::DefaultKeepAliveExecutor::WeakRef::keepAliveAcquire ( )
inlineoverrideprivatevirtual

Reimplemented from folly::Executor.

Definition at line 84 of file DefaultKeepAliveExecutor.h.

References folly::DefaultKeepAliveExecutor::ControlBlock::keepAliveCount_.

84  {
85  auto keepAliveCount =
86  keepAliveCount_.fetch_add(1, std::memory_order_relaxed);
87  // We should never increment from 0
88  DCHECK(keepAliveCount > 0);
89  return true;
90  }
void folly::DefaultKeepAliveExecutor::WeakRef::keepAliveRelease ( )
inlineoverrideprivatevirtual

Reimplemented from folly::Executor.

Definition at line 92 of file DefaultKeepAliveExecutor.h.

References folly::DefaultKeepAliveExecutor::ControlBlock::keepAliveCount_.

92  {
93  auto keepAliveCount =
94  keepAliveCount_.fetch_sub(1, std::memory_order_acq_rel);
95  DCHECK(keepAliveCount >= 1);
96 
97  if (keepAliveCount == 1) {
98  delete this;
99  }
100  }
folly::Executor::KeepAlive folly::DefaultKeepAliveExecutor::WeakRef::lock ( )
inlineprivate

Definition at line 102 of file DefaultKeepAliveExecutor.h.

References folly::DefaultKeepAliveExecutor::controlBlock_, and folly::Executor::makeKeepAlive().

102  {
103  auto controlBlock =
104  controlBlock_->keepAliveCount_.load(std::memory_order_relaxed);
105  do {
106  if (controlBlock == 0) {
107  return {};
108  }
109  } while (!controlBlock_->keepAliveCount_.compare_exchange_weak(
110  controlBlock,
111  controlBlock + 1,
112  std::memory_order_release,
113  std::memory_order_relaxed));
114 
115  return makeKeepAlive(executor_);
116  }
std::shared_ptr< ControlBlock > controlBlock_
static KeepAlive< ExecutorT > makeKeepAlive(ExecutorT *executor)
Definition: Executor.h:179

Member Data Documentation

std::shared_ptr<ControlBlock> folly::DefaultKeepAliveExecutor::WeakRef::controlBlock_
private

Definition at line 120 of file DefaultKeepAliveExecutor.h.

Executor* folly::DefaultKeepAliveExecutor::WeakRef::executor_
private

Definition at line 121 of file DefaultKeepAliveExecutor.h.

std::atomic<size_t> folly::DefaultKeepAliveExecutor::WeakRef::keepAliveCount_ {1}
private

Definition at line 118 of file DefaultKeepAliveExecutor.h.

uint8_t folly::DefaultKeepAliveExecutor::WeakRef::numPriorities_
private

Definition at line 123 of file DefaultKeepAliveExecutor.h.


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