proxygen
folly::futures::detail::WaitExecutor Class Referencefinal

#include <Future-inl.h>

Inheritance diagram for folly::futures::detail::WaitExecutor:
folly::Executor

Classes

struct  Queue
 

Public Types

using Clock = std::chrono::steady_clock
 

Public Member Functions

void add (Func func) override
 
void drive ()
 
bool driveUntil (Clock::time_point deadline)
 
void detach ()
 
- Public Member Functions inherited from folly::Executor
virtual ~Executor ()
 
virtual void addWithPriority (Func, int8_t priority)
 
virtual uint8_t getNumPriorities () const
 

Static Public Member Functions

static KeepAlive< WaitExecutorcreate ()
 
- 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

 WaitExecutor ()
 
bool keepAliveAcquire () override
 
void keepAliveRelease () override
 

Private Attributes

folly::Synchronized< Queuequeue_
 
FutureBatonType baton_
 
std::atomic< ssize_t > keepAliveCount_ {1}
 

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 610 of file Future-inl.h.

Member Typedef Documentation

using folly::futures::detail::WaitExecutor::Clock = std::chrono::steady_clock

Definition at line 633 of file Future-inl.h.

Constructor & Destructor Documentation

folly::futures::detail::WaitExecutor::WaitExecutor ( )
inlineprivate

Definition at line 661 of file Future-inl.h.

661 {}

Member Function Documentation

void folly::futures::detail::WaitExecutor::add ( Func  )
inlineoverridevirtual

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

Implements folly::Executor.

Definition at line 612 of file Future-inl.h.

References folly::empty(), and folly::gen::move.

612  {
613  auto wQueue = queue_.wlock();
614  if (wQueue->detached) {
615  return;
616  }
617  bool empty = wQueue->funcs.empty();
618  wQueue->funcs.push_back(std::move(func));
619  if (empty) {
620  baton_.post();
621  }
622  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
folly::Synchronized< Queue > queue_
Definition: Future-inl.h:684
static KeepAlive<WaitExecutor> folly::futures::detail::WaitExecutor::create ( )
inlinestatic

Definition at line 656 of file Future-inl.h.

Referenced by folly::SemiFuture< T >::wait().

656  {
657  return makeKeepAlive<WaitExecutor>(new WaitExecutor());
658  }
void folly::futures::detail::WaitExecutor::detach ( )
inline

Definition at line 647 of file Future-inl.h.

References folly::gen::move.

647  {
648  // Make sure we don't hold the lock while destroying funcs.
649  [&] {
650  auto wQueue = queue_.wlock();
651  wQueue->detached = true;
652  return std::move(wQueue->funcs);
653  }();
654  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Synchronized< Queue > queue_
Definition: Future-inl.h:684
void folly::futures::detail::WaitExecutor::drive ( )
inline

Definition at line 624 of file Future-inl.h.

References folly::exchange(), and folly::gen::move.

624  {
625  baton_.wait();
626  baton_.reset();
627  auto funcs = std::move(queue_.wlock()->funcs);
628  for (auto& func : funcs) {
629  std::exchange(func, nullptr)();
630  }
631  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
folly::Synchronized< Queue > queue_
Definition: Future-inl.h:684
bool folly::futures::detail::WaitExecutor::driveUntil ( Clock::time_point  deadline)
inline

Definition at line 635 of file Future-inl.h.

References folly::exchange(), and folly::gen::move.

635  {
636  if (!baton_.try_wait_until(deadline)) {
637  return false;
638  }
639  baton_.reset();
640  auto funcs = std::move(queue_.wlock()->funcs);
641  for (auto& func : funcs) {
642  std::exchange(func, nullptr)();
643  }
644  return true;
645  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
bool try_wait_until(const std::chrono::time_point< Clock, Duration > &deadline)
Definition: Baton.h:133
folly::Synchronized< Queue > queue_
Definition: Future-inl.h:684
bool folly::futures::detail::WaitExecutor::keepAliveAcquire ( )
inlineoverrideprivatevirtual

Reimplemented from folly::Executor.

Definition at line 663 of file Future-inl.h.

663  {
664  auto keepAliveCount =
665  keepAliveCount_.fetch_add(1, std::memory_order_relaxed);
666  DCHECK(keepAliveCount > 0);
667  return true;
668  }
std::atomic< ssize_t > keepAliveCount_
Definition: Future-inl.h:687
void folly::futures::detail::WaitExecutor::keepAliveRelease ( )
inlineoverrideprivatevirtual

Reimplemented from folly::Executor.

Definition at line 670 of file Future-inl.h.

670  {
671  auto keepAliveCount =
672  keepAliveCount_.fetch_sub(1, std::memory_order_acq_rel);
673  DCHECK(keepAliveCount > 0);
674  if (keepAliveCount == 1) {
675  delete this;
676  }
677  }
std::atomic< ssize_t > keepAliveCount_
Definition: Future-inl.h:687

Member Data Documentation

FutureBatonType folly::futures::detail::WaitExecutor::baton_
private

Definition at line 685 of file Future-inl.h.

std::atomic<ssize_t> folly::futures::detail::WaitExecutor::keepAliveCount_ {1}
private

Definition at line 687 of file Future-inl.h.

folly::Synchronized<Queue> folly::futures::detail::WaitExecutor::queue_
private

Definition at line 684 of file Future-inl.h.


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