proxygen
folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output > Class Template Reference

#include <ParallelMap-inl.h>

Inheritance diagram for folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >:
folly::gen::GenImpl< Output, Generator< Value, Source, Input, Output > > folly::gen::FBounded< Self >

Classes

class  ExecutionPipeline
 

Public Member Functions

 Generator (Source source, const Predicate &pred, size_t nThreads)
 
template<class Body >
void foreach (Body &&body) const
 
template<class Handler >
bool apply (Handler &&handler) const
 
- Public Member Functions inherited from folly::gen::GenImpl< Output, Generator< Value, Source, Input, Output > >
bool apply (Handler &&handler) const
 
void foreach (Body &&body) const
 
- Public Member Functions inherited from folly::gen::FBounded< Self >
const Self & self () const
 
Self & self ()
 

Static Public Attributes

static constexpr bool infinite = Source::infinite
 
- Static Public Attributes inherited from folly::gen::GenImpl< Output, Generator< Value, Source, Input, Output > >
static constexpr bool infinite
 

Private Attributes

Source source_
 
Predicate pred_
 
const size_t nThreads_
 

Additional Inherited Members

- Public Types inherited from folly::gen::GenImpl< Output, Generator< Value, Source, Input, Output > >
typedef Output ValueType
 
typedef std::decay< Output >::type StorageType
 
- Protected Member Functions inherited from folly::gen::GenImpl< Output, Generator< Value, Source, Input, Output > >
 GenImpl ()=default
 
 GenImpl (GenImpl &&)=default
 
 GenImpl (const GenImpl &)=default
 
GenImploperator= (GenImpl &&)=default
 
GenImploperator= (const GenImpl &)=default
 

Detailed Description

template<class Predicate>
template<class Value, class Source, class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
class folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >

Definition at line 63 of file ParallelMap-inl.h.

Constructor & Destructor Documentation

template<class Predicate >
template<class Value , class Source , class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::Generator ( Source  source,
const Predicate &  pred,
size_t  nThreads 
)
inline

Definition at line 151 of file ParallelMap-inl.h.

152  : source_(std::move(source)),
153  pred_(pred),
154  nThreads_(nThreads ? nThreads : sysconf(_SC_NPROCESSORS_ONLN)) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Function Documentation

template<class Predicate >
template<class Value , class Source , class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
template<class Handler >
bool folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::apply ( Handler &&  handler) const
inline

Definition at line 194 of file ParallelMap-inl.h.

References folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::blockingRead(), folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::blockingWrite(), handler(), folly::gen::move, folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::read(), folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::stop(), folly::value(), testing::Value(), and folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::write().

194  {
195  ExecutionPipeline pipeline(pred_, nThreads_);
196 
197  size_t wrote = 0;
198  size_t read = 0;
199  bool more = true;
200  source_.apply([&](Value value) {
201  if (pipeline.write(std::forward<Value>(value))) {
202  // input queue not yet full, saturate it before we process
203  // anything downstream
204  ++wrote;
205  return true;
206  }
207 
208  // input queue full; drain ready items from the queue
209  Output out;
210  while (pipeline.read(out)) {
211  ++read;
212  if (!handler(std::move(out))) {
213  more = false;
214  return false;
215  }
216  }
217 
218  // write the value we were going to write before we made room.
219  pipeline.blockingWrite(std::forward<Value>(value));
220  ++wrote;
221  return true;
222  });
223 
224  pipeline.stop();
225 
226  // flush the output queue
227  while (read < wrote) {
228  Output out;
229  pipeline.blockingRead(out);
230  ++read;
231  if (more) {
232  more = more && handler(std::move(out));
233  }
234  }
235  return more;
236  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
bool Value(const T &value, M matcher)
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
template<class Predicate >
template<class Value , class Source , class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
template<class Body >
void folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::foreach ( Body &&  body) const
inline

Definition at line 157 of file ParallelMap-inl.h.

References folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::blockingRead(), folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::blockingWrite(), folly::gen::move, folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::read(), folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::stop(), folly::value(), testing::Value(), and folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::ExecutionPipeline::write().

157  {
158  ExecutionPipeline pipeline(pred_, nThreads_);
159 
160  size_t wrote = 0;
161  size_t read = 0;
162  source_.foreach([&](Value value) {
163  if (pipeline.write(std::forward<Value>(value))) {
164  // input queue not yet full, saturate it before we process
165  // anything downstream
166  ++wrote;
167  return;
168  }
169 
170  // input queue full; drain ready items from the queue
171  Output out;
172  while (pipeline.read(out)) {
173  ++read;
174  body(std::move(out));
175  }
176 
177  // write the value we were going to write before we made room.
178  pipeline.blockingWrite(std::forward<Value>(value));
179  ++wrote;
180  });
181 
182  pipeline.stop();
183 
184  // flush the output queue
185  while (read < wrote) {
186  Output out;
187  pipeline.blockingRead(out);
188  ++read;
189  body(std::move(out));
190  }
191  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool Value(const T &value, M matcher)
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)

Member Data Documentation

template<class Predicate >
template<class Value , class Source , class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
constexpr bool folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::infinite = Source::infinite
static

Definition at line 238 of file ParallelMap-inl.h.

template<class Predicate >
template<class Value , class Source , class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
const size_t folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::nThreads_
private

Definition at line 67 of file ParallelMap-inl.h.

Referenced by folly::gen::detail::PMap< Predicate >::compose().

template<class Predicate >
template<class Value , class Source , class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
Predicate folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::pred_
private

Definition at line 66 of file ParallelMap-inl.h.

template<class Predicate >
template<class Value , class Source , class Input = typename std::decay<Value>::type, class Output = typename std::decay<invoke_result_t<Predicate, Value>>::type>
Source folly::gen::detail::PMap< Predicate >::Generator< Value, Source, Input, Output >::source_
private

Definition at line 65 of file ParallelMap-inl.h.


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