proxygen
folly::pushmi::strand_queue< E, Executor > Class Template Reference

#include <strand.h>

Inheritance diagram for folly::pushmi::strand_queue< E, Executor >:
folly::pushmi::strand_queue_base< E >

Public Member Functions

 ~strand_queue ()
 
 strand_queue (Executor ex)
 
void dispatch () override
 
auto shared_from_that ()
 
template<class Exec >
void value (Exec &&)
 
template<class AE >
void error (AE e) noexcept
 
void done ()
 
- Public Member Functions inherited from folly::pushmi::strand_queue_base< E >
virtual ~strand_queue_base ()
 
strand_item< E > & front ()
 

Public Attributes

Executor ex_
 
- Public Attributes inherited from folly::pushmi::strand_queue_base< E >
std::mutex lock_
 
size_t remaining_ = 0
 
std::queue< strand_item< E > > items_
 

Detailed Description

template<class E, class Executor>
class folly::pushmi::strand_queue< E, Executor >

Definition at line 84 of file strand.h.

Constructor & Destructor Documentation

template<class E , class Executor >
folly::pushmi::strand_queue< E, Executor >::~strand_queue ( )
inline

Definition at line 86 of file strand.h.

86 {}
template<class E , class Executor >
folly::pushmi::strand_queue< E, Executor >::strand_queue ( Executor  ex)
inline

Definition at line 87 of file strand.h.

87 : ex_(std::move(ex)) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Function Documentation

template<class E , class Executor >
void folly::pushmi::strand_queue< E, Executor >::dispatch ( )
overridevirtual

Implements folly::pushmi::strand_queue_base< E >.

Definition at line 169 of file strand.h.

References folly::pushmi::submit.

169  {
170  submit(ex_, strand_queue_receiver<E, Executor>{shared_from_that()});
171 }
PUSHMI_INLINE_VAR constexpr __adl::do_submit_fn submit
template<class E , class Executor >
void folly::pushmi::strand_queue< E, Executor >::done ( )
inline

Definition at line 142 of file strand.h.

References folly::gen::guard(), and folly::pushmi::submit.

142  {
143  std::unique_lock<std::mutex> guard{this->lock_};
144 
145  // only allow one at a time
146  if (this->remaining_ > 0) {
147  return;
148  }
149  // skip when empty
150  if (this->items_.empty()) {
151  return;
152  }
153 
154  auto that = shared_from_that();
155  submit(ex_, strand_queue_receiver<E, Executor>{that});
156  }
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
std::queue< strand_item< E > > items_
Definition: strand.h:71
PUSHMI_INLINE_VAR constexpr __adl::do_submit_fn submit
template<class E , class Executor >
template<class AE >
void folly::pushmi::strand_queue< E, Executor >::error ( AE  e)
inlinenoexcept

Definition at line 129 of file strand.h.

References folly::pushmi::detail::as_const, folly::gen::guard(), folly::gen::move, folly::pushmi::set_error, and folly::pushmi::strand_item< E >::what.

129  {
130  std::unique_lock<std::mutex> guard{this->lock_};
131 
132  this->remaining_ = 0;
133 
134  while (!this->items_.empty()) {
135  auto what{std::move(this->front().what)};
136  this->items_.pop();
137  guard.unlock();
138  set_error(what, detail::as_const(e));
139  guard.lock();
140  }
141  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
strand_item< E > & front()
Definition: strand.h:75
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
std::queue< strand_item< E > > items_
Definition: strand.h:71
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::detail::as_const_fn as_const
template<class E , class Executor >
auto folly::pushmi::strand_queue< E, Executor >::shared_from_that ( )
inline

Definition at line 92 of file strand.h.

92  {
93  return std::static_pointer_cast<strand_queue<E, Executor>>(
94  this->shared_from_this());
95  }
template<class E , class Executor >
template<class Exec >
void folly::pushmi::strand_queue< E, Executor >::value ( Exec &&  )
inline

Definition at line 98 of file strand.h.

References folly::gen::guard(), folly::gen::move, folly::pushmi::set_done, and folly::pushmi::set_value.

98  {
99  //
100  // pull ready items from the queue in order.
101 
102  std::unique_lock<std::mutex> guard{this->lock_};
103 
104  // only allow one at a time
105  if (this->remaining_ > 0) {
106  return;
107  }
108  // skip when empty
109  if (this->items_.empty()) {
110  return;
111  }
112 
113  // do not allow recursive queueing to block this executor
114  this->remaining_ = this->items_.size();
115 
116  auto that = shared_from_that();
117  auto subEx = strand_executor<E, Executor>{that};
118 
119  while (!this->items_.empty() && --this->remaining_ >= 0) {
120  auto item{std::move(this->front())};
121  this->items_.pop();
122  guard.unlock();
123  set_value(item.what, any_executor_ref<E>{subEx});
124  set_done(item.what);
125  guard.lock();
126  }
127  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
strand_item< E > & front()
Definition: strand.h:75
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
std::queue< strand_item< E > > items_
Definition: strand.h:71
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done

Member Data Documentation

template<class E , class Executor >
Executor folly::pushmi::strand_queue< E, Executor >::ex_

Definition at line 88 of file strand.h.


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