proxygen
from.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
23 
24 namespace folly {
25 namespace pushmi {
26 
28  template(class R)
29  concept Range,
30  requires(R&& r)(
31  implicitly_convertible_to<bool>(std::begin(r) == std::end(r)))
32 );
33 
34 namespace operators {
35 
36 PUSHMI_INLINE_VAR constexpr struct from_fn {
37  private:
38  struct sender_base : many_sender<ignoreSF, inlineEXF> {
39  using properties = property_set<
41  is_many<>,
44  };
45  template <class I, class S>
46  struct out_impl {
47  I begin_;
48  S end_;
49  PUSHMI_TEMPLATE(class Out)
50  (requires ReceiveValue<
51  Out,
52  typename std::iterator_traits<I>::value_type>)
53  void operator()(sender_base&, Out out) const {
54  auto c = begin_;
55  for (; c != end_; ++c) {
56  set_value(out, *c);
57  }
58  set_done(out);
59  }
60  };
61 
62  public:
63  PUSHMI_TEMPLATE(class I, class S)
64  (requires DerivedFrom<
65  typename std::iterator_traits<I>::iterator_category,
66  std::forward_iterator_tag>)
67  auto operator()(I begin, S end) const {
69  }
70 
71  PUSHMI_TEMPLATE(class R)
73  auto operator()(R&& range) const {
74  return (*this)(std::begin(range), std::end(range));
75  }
76 } from{};
77 
78 template <class I, class S, class Out, class Exec>
80  flow_from_producer(I begin, S end, Out out, Exec exec, bool s)
81  : c(begin),
82  end(end),
83  out(std::move(out)),
84  exec(std::move(exec)),
85  stop(s) {}
86  I c;
87  S end;
88  Out out;
89  Exec exec;
90  std::atomic<bool> stop;
91 };
92 
93 template <class Producer>
94 struct flow_from_up {
96 
97  explicit flow_from_up(std::shared_ptr<Producer> p) : p(std::move(p)) {}
98  std::shared_ptr<Producer> p;
99 
100  void value(std::ptrdiff_t requested) {
101  if (requested < 1) {
102  return;
103  }
104  // submit work to exec
106  p->exec, make_receiver([p = p, requested](auto) {
107  auto remaining = requested;
108  // this loop is structured to work when there is
109  // re-entrancy out.value in the loop may call up.value.
110  // to handle this the state of p->c must be captured and
111  // the remaining and p->c must be changed before
112  // out.value is called.
113  while (remaining-- > 0 && !p->stop && p->c != p->end) {
114  auto i = (p->c)++;
115  set_value(p->out, ::folly::pushmi::detail::as_const(*i));
116  }
117  if (p->c == p->end) {
118  set_done(p->out);
119  }
120  }));
121  }
122 
123  template <class E>
124  void error(E) noexcept {
125  p->stop.store(true);
127  p->exec, make_receiver([p = p](auto) { set_done(p->out); }));
128  }
129 
130  void done() {
131  p->stop.store(true);
133  p->exec, make_receiver([p = p](auto) { set_done(p->out); }));
134  }
135 };
136 
137 PUSHMI_INLINE_VAR constexpr struct flow_from_fn {
138  private:
139  template <class I, class S, class Exec>
140  struct out_impl {
142  S end_;
143  mutable Exec exec_;
144  PUSHMI_TEMPLATE(class Out)
145  (requires ReceiveValue<
146  Out,
147  typename std::iterator_traits<I>::value_type>)
148  void operator()(Out out) const {
149  using Producer = flow_from_producer<I, S, Out, Exec>;
150  auto p = std::make_shared<Producer>(
151  begin_, end_, std::move(out), exec_, false);
152 
154  exec_, make_receiver([p](auto) {
155  // pass reference for cancellation.
157  }));
158  }
159  };
160 
161  public:
162  PUSHMI_TEMPLATE(class I, class S)
163  (requires DerivedFrom<
164  typename std::iterator_traits<I>::iterator_category,
165  std::forward_iterator_tag>)
166  auto operator()(I begin, S end) const {
167  return (*this)(begin, end, trampoline());
168  }
169 
170  PUSHMI_TEMPLATE(class R)
172  auto operator()(R&& range) const {
173  return (*this)(std::begin(range), std::end(range), trampoline());
174  }
175 
176  PUSHMI_TEMPLATE(class I, class S, class Exec)
177  (requires DerivedFrom<
178  typename std::iterator_traits<I>::iterator_category,
179  std::forward_iterator_tag>&& Sender<Exec, is_single<>, is_executor<>>)
180  auto operator()(I begin, S end, Exec exec) const {
182  }
183 
184  PUSHMI_TEMPLATE(class R, class Exec)
185  (requires Range<R>&& Sender<Exec, is_single<>, is_executor<>>)
186  auto operator()(
187  R&& range,
188  Exec exec) const {
189  return (*this)(std::begin(range), std::end(range), exec);
190  }
191 } flow_from{};
192 
193 } // namespace operators
194 
195 } // namespace pushmi
196 } // namespace folly
flow_from_up(std::shared_ptr< Producer > p)
Definition: from.h:97
detail::delegator< E > trampoline()
Definition: trampoline.h:261
std::enable_if_t< PropertySet< __properties_t< property_set_traits< T >>>, __properties_t< property_set_traits< T >>> properties_t
Definition: properties.h:105
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
auto begin(TestAdlIterable &instance)
Definition: ForeachTest.cpp:56
std::shared_ptr< Producer > p
Definition: from.h:98
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
static void stop()
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_flow_many_sender_fn make_flow_many_sender
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_many_sender_fn make_many_sender
PUSHMI_CONCEPT_DEF(template(class PS) concept Cardinality, has_cardinality_v< PS >)
flow_from_producer(I begin, S end, Out out, Exec exec, bool s)
Definition: from.h:80
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
#define concept
constexpr Range< Iter > range(Iter first, Iter last)
Definition: Range.h:1114
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::flow_from_fn flow_from
if(FOLLY_USE_SYMBOLIZER) add_library(folly_exception_tracer_base ExceptionTracer.cpp StackTrace.cpp) apply_folly_compile_options_to_target(folly_exception_tracer_base) target_link_libraries(folly_exception_tracer_base PUBLIC folly) add_library(folly_exception_tracer ExceptionStackTraceLib.cpp ExceptionTracerLib.cpp) apply_folly_compile_options_to_target(folly_exception_tracer) target_link_libraries(folly_exception_tracer PUBLIC folly_exception_tracer_base) add_library(folly_exception_counter ExceptionCounterLib.cpp) apply_folly_compile_options_to_target(folly_exception_counter) target_link_libraries(folly_exception_counter PUBLIC folly_exception_tracer) install(FILES ExceptionAbi.h ExceptionCounterLib.h ExceptionTracer.h ExceptionTracerLib.h StackTrace.h DESTINATION $
Definition: CMakeLists.txt:1
#define PUSHMI_INLINE_VAR
Definition: concept_def.h:60
PUSHMI_INLINE_VAR constexpr __adl::set_starting_fn set_starting
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
requires requires(detail::apply_impl(std::declval< F >(), std::declval< Tuple >(), detail::tupidxs< Tuple >{}))) const expr decltype(auto) apply(F &&f
PUSHMI_TEMPLATE(class E=std::exception_ptr, class Wrapped)(requires Sender< detail
Definition: executor.h:102
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
static set< string > s
properties_t< receiver<>> properties
Definition: from.h:95
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_receiver_fn make_receiver
char c
void value(std::ptrdiff_t requested)
Definition: from.h:100
uintptr_t end_
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done