proxygen
folly::DefaultKeepAliveExecutor Class Reference

#include <DefaultKeepAliveExecutor.h>

Inheritance diagram for folly::DefaultKeepAliveExecutor:
folly::Executor folly::ThreadPoolExecutor folly::VirtualExecutor folly::CPUThreadPoolExecutor folly::IOThreadPoolExecutor

Classes

struct  ControlBlock
 
class  WeakRef
 

Public Member Functions

 DefaultKeepAliveExecutor ()
 
virtual ~DefaultKeepAliveExecutor ()
 
folly::Executor::KeepAlive weakRef ()
 
- Public Member Functions inherited from folly::Executor
virtual ~Executor ()
 
virtual void add (Func)=0
 
virtual void addWithPriority (Func, int8_t priority)
 
virtual uint8_t getNumPriorities () const
 

Protected Member Functions

void joinKeepAlive ()
 

Private Member Functions

bool keepAliveAcquire () override
 
void keepAliveRelease () override
 

Private Attributes

std::shared_ptr< ControlBlockcontrolBlock_ {std::make_shared<ControlBlock>()}
 
Baton keepAliveReleaseBaton_
 
KeepAlive< DefaultKeepAliveExecutorkeepAlive_
 

Additional Inherited Members

- 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)
 
- 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

An Executor accepts units of work with add(), which should be threadsafe.

Definition at line 30 of file DefaultKeepAliveExecutor.h.

Constructor & Destructor Documentation

folly::DefaultKeepAliveExecutor::DefaultKeepAliveExecutor ( )
inline

Definition at line 32 of file DefaultKeepAliveExecutor.h.

32 : Executor() {}
virtual folly::DefaultKeepAliveExecutor::~DefaultKeepAliveExecutor ( )
inlinevirtual

Definition at line 34 of file DefaultKeepAliveExecutor.h.

References keepAlive_.

34  {
35  DCHECK(!keepAlive_);
36  }
KeepAlive< DefaultKeepAliveExecutor > keepAlive_

Member Function Documentation

void folly::DefaultKeepAliveExecutor::joinKeepAlive ( )
inlineprotected

Definition at line 43 of file DefaultKeepAliveExecutor.h.

References keepAlive_, keepAliveReleaseBaton_, and folly::Baton< MayBlock, Atom >::wait().

Referenced by folly::ThreadPoolExecutor::joinKeepAliveOnce(), and folly::VirtualExecutor::~VirtualExecutor().

43  {
44  DCHECK(keepAlive_);
45  keepAlive_.reset();
47  }
FOLLY_ALWAYS_INLINE void wait(const WaitOptions &opt=wait_options()) noexcept
Definition: Baton.h:170
KeepAlive< DefaultKeepAliveExecutor > keepAlive_
bool folly::DefaultKeepAliveExecutor::keepAliveAcquire ( )
inlineoverrideprivatevirtual

Reimplemented from folly::Executor.

Definition at line 126 of file DefaultKeepAliveExecutor.h.

References controlBlock_.

126  {
127  auto keepAliveCount =
128  controlBlock_->keepAliveCount_.fetch_add(1, std::memory_order_relaxed);
129  // We should never increment from 0
130  DCHECK(keepAliveCount > 0);
131  return true;
132  }
std::shared_ptr< ControlBlock > controlBlock_
void folly::DefaultKeepAliveExecutor::keepAliveRelease ( )
inlineoverrideprivatevirtual

Reimplemented from folly::Executor.

Definition at line 134 of file DefaultKeepAliveExecutor.h.

References controlBlock_, keepAliveReleaseBaton_, and folly::Baton< MayBlock, Atom >::post().

134  {
135  auto keepAliveCount =
136  controlBlock_->keepAliveCount_.fetch_sub(1, std::memory_order_acquire);
137  DCHECK(keepAliveCount >= 1);
138 
139  if (keepAliveCount == 1) {
140  keepAliveReleaseBaton_.post(); // std::memory_order_release
141  }
142  }
std::shared_ptr< ControlBlock > controlBlock_
void post() noexcept
Definition: Baton.h:123
folly::Executor::KeepAlive folly::DefaultKeepAliveExecutor::weakRef ( )
inline

Definition at line 38 of file DefaultKeepAliveExecutor.h.

References controlBlock_, and folly::DefaultKeepAliveExecutor::WeakRef::create().

38  {
39  return WeakRef::create(controlBlock_, this);
40  }
std::shared_ptr< ControlBlock > controlBlock_
static folly::Executor::KeepAlive create(std::shared_ptr< ControlBlock > controlBlock, Executor *executor)

Member Data Documentation

std::shared_ptr<ControlBlock> folly::DefaultKeepAliveExecutor::controlBlock_ {std::make_shared<ControlBlock>()}
private
KeepAlive<DefaultKeepAliveExecutor> folly::DefaultKeepAliveExecutor::keepAlive_
private
Initial value:
{
makeKeepAlive<DefaultKeepAliveExecutor>(this)}

Definition at line 146 of file DefaultKeepAliveExecutor.h.

Referenced by joinKeepAlive(), folly::VirtualExecutor::wrapFunc(), and ~DefaultKeepAliveExecutor().

Baton folly::DefaultKeepAliveExecutor::keepAliveReleaseBaton_
private

Definition at line 145 of file DefaultKeepAliveExecutor.h.

Referenced by joinKeepAlive(), and keepAliveRelease().


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