proxygen
folly::TimedDrivableExecutor Class Reference

#include <TimedDrivableExecutor.h>

Inheritance diagram for folly::TimedDrivableExecutor:
folly::DrivableExecutor folly::Executor

Public Member Functions

 ~TimedDrivableExecutor () noexcept
 
void drive () noexceptoverride
 Implements DrivableExecutor. More...
 
bool try_drive () noexcept
 
template<typename Rep , typename Period >
bool try_drive_for (const std::chrono::duration< Rep, Period > &timeout) noexcept
 
template<typename Clock , typename Duration >
bool try_drive_until (const std::chrono::time_point< Clock, Duration > &deadline) noexcept
 
void add (Func) override
 
size_t run () noexcept
 
size_t drain () noexcept
 
void wait () noexcept
 Wait for work to do. More...
 
bool try_wait () noexcept
 
template<typename Rep , typename Period >
bool try_wait_for (const std::chrono::duration< Rep, Period > &timeout) noexcept
 Wait for work to do or for a period of timeout, whichever is sooner. More...
 
template<typename Clock , typename Duration >
bool try_wait_until (const std::chrono::time_point< Clock, Duration > &deadline) noexcept
 Wait for work to do or until deadline passes, whichever is sooner. More...
 
- Public Member Functions inherited from folly::DrivableExecutor
 ~DrivableExecutor () override=default
 
- Public Member Functions inherited from folly::Executor
virtual ~Executor ()
 
virtual void addWithPriority (Func, int8_t priority)
 
virtual uint8_t getNumPriorities () const
 

Private Attributes

UMPSCQueue< Func, true > queue_
 
Func func_
 

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
 
- Protected Member Functions inherited from folly::Executor
virtual bool keepAliveAcquire ()
 
virtual void keepAliveRelease ()
 
- 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 30 of file TimedDrivableExecutor.h.

Constructor & Destructor Documentation

folly::TimedDrivableExecutor::~TimedDrivableExecutor ( )
inlinenoexcept

Definition at line 32 of file TimedDrivableExecutor.h.

References drain(), drive(), and folly::pushmi::__adl::noexcept().

32  {
33  // Drain on destruction so that if work is added here during the collapse
34  // of a future train, it will propagate.
35  drain();
36  }

Member Function Documentation

void folly::TimedDrivableExecutor::add ( Func  )
overridevirtual

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

Implements folly::Executor.

Definition at line 26 of file TimedDrivableExecutor.cpp.

References folly::gen::move, and queue_.

Referenced by TEST(), and try_drive_until().

26  {
27  queue_.enqueue(std::move(callback));
28 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
UMPSCQueue< Func, true > queue_
size_t folly::TimedDrivableExecutor::drain ( )
noexcept

Definition at line 55 of file TimedDrivableExecutor.cpp.

References run().

Referenced by TEST(), try_drive_until(), and ~TimedDrivableExecutor().

55  {
56  size_t tasksRun = 0;
57  size_t tasksForSingleRun = 0;
58  while ((tasksForSingleRun = run()) != 0) {
59  tasksRun += tasksForSingleRun;
60  }
61  return tasksRun;
62 }
void folly::TimedDrivableExecutor::drive ( )
overridevirtualnoexcept

Implements DrivableExecutor.

Implements folly::DrivableExecutor.

Definition at line 30 of file TimedDrivableExecutor.cpp.

References run(), and wait().

Referenced by ~TimedDrivableExecutor().

30  {
31  wait();
32  run();
33 }
void wait() noexcept
Wait for work to do.
size_t folly::TimedDrivableExecutor::run ( )
noexcept

Do work. Returns the number of functions that were executed (maybe 0). Non-blocking, in the sense that we don't wait for work (we can't control whether one of the functions blocks). This is stable, it will not chase an ever-increasing tail of work. This also means, there may be more work available to perform at the moment that this returns.

Definition at line 35 of file TimedDrivableExecutor.cpp.

References count, f, func_, folly::gen::move, and queue_.

Referenced by drain(), drive(), TEST(), try_drive(), try_drive_for(), and try_drive_until().

35  {
36  size_t count = 0;
37  size_t n = queue_.size();
38 
39  // If we have waited already, then func_ may have a value
40  if (func_) {
41  auto f = std::move(func_);
42  f();
43  count = 1;
44  }
45 
46  while (count < n && queue_.try_dequeue(func_)) {
47  auto f = std::move(func_);
48  f();
49  ++count;
50  }
51 
52  return count;
53 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
UMPSCQueue< Func, true > queue_
int * count
bool folly::TimedDrivableExecutor::try_drive ( )
inlinenoexcept

Definition at line 43 of file TimedDrivableExecutor.h.

References run(), and try_wait().

Referenced by TEST().

43  {
44  return try_wait() && run() > 0;
45  }
template<typename Rep , typename Period >
bool folly::TimedDrivableExecutor::try_drive_for ( const std::chrono::duration< Rep, Period > &  timeout)
inlinenoexcept

Definition at line 51 of file TimedDrivableExecutor.h.

References run(), folly::detail::timeout, and try_wait_for().

Referenced by TEST().

52  {
53  return try_wait_for(timeout) && run() > 0;
54  }
bool try_wait_for(const std::chrono::duration< Rep, Period > &timeout) noexcept
Wait for work to do or for a period of timeout, whichever is sooner.
template<typename Clock , typename Duration >
bool folly::TimedDrivableExecutor::try_drive_until ( const std::chrono::time_point< Clock, Duration > &  deadline)
inlinenoexcept

Definition at line 60 of file TimedDrivableExecutor.h.

References add(), drain(), folly::pushmi::__adl::noexcept(), run(), try_wait_until(), and wait().

Referenced by TEST(), and folly::futures::detail::waitViaImpl().

61  {
62  return try_wait_until(deadline) && run() > 0;
63  }
bool try_wait_until(const std::chrono::time_point< Clock, Duration > &deadline) noexcept
Wait for work to do or until deadline passes, whichever is sooner.
bool folly::TimedDrivableExecutor::try_wait ( )
inlinenoexcept

Definition at line 87 of file TimedDrivableExecutor.h.

References func_, and queue_.

Referenced by try_drive().

87  {
88  return func_ || queue_.try_dequeue(func_);
89  }
UMPSCQueue< Func, true > queue_
template<typename Rep , typename Period >
bool folly::TimedDrivableExecutor::try_wait_for ( const std::chrono::duration< Rep, Period > &  timeout)
inlinenoexcept

Wait for work to do or for a period of timeout, whichever is sooner.

Definition at line 93 of file TimedDrivableExecutor.h.

References func_, queue_, and folly::detail::timeout.

Referenced by try_drive_for().

94  {
95  return func_ || queue_.try_dequeue_for(func_, timeout);
96  }
UMPSCQueue< Func, true > queue_
template<typename Clock , typename Duration >
bool folly::TimedDrivableExecutor::try_wait_until ( const std::chrono::time_point< Clock, Duration > &  deadline)
inlinenoexcept

Wait for work to do or until deadline passes, whichever is sooner.

Definition at line 100 of file TimedDrivableExecutor.h.

References func_, and queue_.

Referenced by try_drive_until().

101  {
102  return func_ || queue_.try_dequeue_until(func_, deadline);
103  }
UMPSCQueue< Func, true > queue_
void folly::TimedDrivableExecutor::wait ( )
noexcept

Wait for work to do.

Definition at line 64 of file TimedDrivableExecutor.cpp.

References func_, and queue_.

Referenced by drive(), and try_drive_until().

64  {
65  if (!func_) {
66  queue_.dequeue(func_);
67  }
68 }
UMPSCQueue< Func, true > queue_

Member Data Documentation

Func folly::TimedDrivableExecutor::func_
private

Definition at line 107 of file TimedDrivableExecutor.h.

Referenced by run(), try_wait(), try_wait_for(), try_wait_until(), and wait().

UMPSCQueue<Func, true> folly::TimedDrivableExecutor::queue_
private

Definition at line 106 of file TimedDrivableExecutor.h.

Referenced by add(), run(), try_wait(), try_wait_for(), try_wait_until(), and wait().


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