Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
_flow_graph_body_impl.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2019 Intel Corporation
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 
17 
18 
19 */
20 
21 #ifndef __TBB__flow_graph_body_impl_H
22 #define __TBB__flow_graph_body_impl_H
23 
24 #ifndef __TBB_flow_graph_H
25 #error Do not #include this internal file directly; use public TBB headers instead.
26 #endif
27 
28 // included in namespace tbb::flow::interfaceX (in flow_graph.h)
29 
30 namespace internal {
31 
32 typedef tbb::internal::uint64_t tag_value;
33 
35 
36 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
37 
38 template<typename ... Policies> struct Policy {};
39 
40 template<typename ... Policies> struct has_policy;
41 
42 template<typename ExpectedPolicy, typename FirstPolicy, typename ...Policies>
43 struct has_policy<ExpectedPolicy, FirstPolicy, Policies...> :
44  tbb::internal::bool_constant<has_policy<ExpectedPolicy, FirstPolicy>::value ||
45  has_policy<ExpectedPolicy, Policies...>::value> {};
46 
47 template<typename ExpectedPolicy, typename SinglePolicy>
48 struct has_policy<ExpectedPolicy, SinglePolicy> :
49  tbb::internal::bool_constant<tbb::internal::is_same_type<ExpectedPolicy, SinglePolicy>::value> {};
50 
51 template<typename ExpectedPolicy, typename ...Policies>
52 struct has_policy<ExpectedPolicy, Policy<Policies...> > : has_policy<ExpectedPolicy, Policies...> {};
53 
54 #else
55 
56 template<typename P1, typename P2 = void> struct Policy {};
57 
58 template<typename ExpectedPolicy, typename SinglePolicy>
59 struct has_policy : tbb::internal::bool_constant<tbb::internal::is_same_type<ExpectedPolicy, SinglePolicy>::value> {};
60 
61 template<typename ExpectedPolicy, typename P>
62 struct has_policy<ExpectedPolicy, Policy<P> > : has_policy<ExpectedPolicy, P> {};
63 
64 template<typename ExpectedPolicy, typename P1, typename P2>
65 struct has_policy<ExpectedPolicy, Policy<P1, P2> > :
66  tbb::internal::bool_constant<has_policy<ExpectedPolicy, P1>::value || has_policy<ExpectedPolicy, P2>::value> {};
67 
68 #endif
69 
70 namespace graph_policy_namespace {
71 
72  struct rejecting { };
73  struct reserving { };
74  struct queueing { };
75  struct lightweight { };
76 
77  // K == type of field used for key-matching. Each tag-matching port will be provided
78  // functor that, given an object accepted by the port, will return the
81  struct key_matching {
82  typedef K key_type;
83  typedef typename strip<K>::type base_key_type;
84  typedef KHash hash_compare_type;
85  };
86 
87  // old tag_matching join's new specifier
89 
90  // Aliases for Policy combinations
91  typedef interface10::internal::Policy<queueing, lightweight> queueing_lightweight;
92  typedef interface10::internal::Policy<rejecting, lightweight> rejecting_lightweight;
93 
94 } // namespace graph_policy_namespace
95 
96 // -------------- function_body containers ----------------------
97 
99 template< typename Output >
101 public:
102  virtual ~source_body() {}
103  virtual bool operator()(Output &output) = 0;
104  virtual source_body* clone() = 0;
105 };
106 
108 template< typename Output, typename Body>
109 class source_body_leaf : public source_body<Output> {
110 public:
111  source_body_leaf( const Body &_body ) : body(_body) { }
112  bool operator()(Output &output) __TBB_override { return body( output ); }
115  }
116  Body get_body() { return body; }
117 private:
118  Body body;
119 };
120 
122 template< typename Input, typename Output >
124 public:
125  virtual ~function_body() {}
126  virtual Output operator()(const Input &input) = 0;
127  virtual function_body* clone() = 0;
128 };
129 
131 template <typename Input, typename Output, typename B>
132 class function_body_leaf : public function_body< Input, Output > {
133 public:
134  function_body_leaf( const B &_body ) : body(_body) { }
135  Output operator()(const Input &i) __TBB_override { return body(i); }
136  B get_body() { return body; }
139  }
140 private:
141  B body;
142 };
143 
145 template <typename B>
146 class function_body_leaf< continue_msg, continue_msg, B> : public function_body< continue_msg, continue_msg > {
147 public:
148  function_body_leaf( const B &_body ) : body(_body) { }
149  continue_msg operator()( const continue_msg &i ) __TBB_override {
150  body(i);
151  return i;
152  }
153  B get_body() { return body; }
156  }
157 private:
158  B body;
159 };
160 
162 template <typename Input, typename B>
163 class function_body_leaf< Input, continue_msg, B> : public function_body< Input, continue_msg > {
164 public:
165  function_body_leaf( const B &_body ) : body(_body) { }
166  continue_msg operator()(const Input &i) __TBB_override {
167  body(i);
168  return continue_msg();
169  }
170  B get_body() { return body; }
173  }
174 private:
175  B body;
176 };
177 
179 template <typename Output, typename B>
180 class function_body_leaf< continue_msg, Output, B > : public function_body< continue_msg, Output > {
181 public:
182  function_body_leaf( const B &_body ) : body(_body) { }
183  Output operator()(const continue_msg &i) __TBB_override {
184  return body(i);
185  }
186  B get_body() { return body; }
189  }
190 private:
191  B body;
192 };
193 
195 template<typename Input, typename OutputSet>
197 public:
198  virtual ~multifunction_body () {}
199  virtual void operator()(const Input &/* input*/, OutputSet &/*oset*/) = 0;
200  virtual multifunction_body* clone() = 0;
201  virtual void* get_body_ptr() = 0;
202 };
203 
205 template<typename Input, typename OutputSet, typename B >
206 class multifunction_body_leaf : public multifunction_body<Input, OutputSet> {
207 public:
208  multifunction_body_leaf(const B &_body) : body(_body) { }
209  void operator()(const Input &input, OutputSet &oset) __TBB_override {
210  body(input, oset); // body may explicitly put() to one or more of oset.
211  }
212  void* get_body_ptr() __TBB_override { return &body; }
215  }
216 
217 private:
218  B body;
219 };
220 
221 // ------ function bodies for hash_buffers and key-matching joins.
222 
223 template<typename Input, typename Output>
225  public:
227  virtual Output operator()(const Input &input) = 0; // returns an Output
228  virtual type_to_key_function_body* clone() = 0;
229 };
230 
231 // specialization for ref output
232 template<typename Input, typename Output>
234  public:
236  virtual const Output & operator()(const Input &input) = 0; // returns a const Output&
237  virtual type_to_key_function_body* clone() = 0;
238 };
239 
240 template <typename Input, typename Output, typename B>
242 public:
243  type_to_key_function_body_leaf( const B &_body ) : body(_body) { }
244  Output operator()(const Input &i) __TBB_override { return body(i); }
245  B get_body() { return body; }
248  }
249 private:
250  B body;
251 };
252 
253 template <typename Input, typename Output, typename B>
255 public:
256  type_to_key_function_body_leaf( const B &_body ) : body(_body) { }
257  const Output& operator()(const Input &i) __TBB_override {
258  return body(i);
259  }
260  B get_body() { return body; }
263  }
264 private:
265  B body;
266 };
267 
268 // --------------------------- end of function_body containers ------------------------
269 
270 // --------------------------- node task bodies ---------------------------------------
271 
273 template< typename NodeType >
274 class forward_task_bypass : public graph_task {
275 
276  NodeType &my_node;
277 
278 public:
279 
280  forward_task_bypass( NodeType &n
282  , node_priority_t node_priority = no_priority
283  ) : graph_task(node_priority),
284 #else
285  ) :
286 #endif
287  my_node(n) {}
288 
290  task * new_task = my_node.forward_task();
291  if (new_task == SUCCESSFULLY_ENQUEUED) new_task = NULL;
292  return new_task;
293  }
294 };
295 
297 // return the task* unless it is SUCCESSFULLY_ENQUEUED, in which case return NULL
298 template< typename NodeType, typename Input >
299 class apply_body_task_bypass : public graph_task {
300 
301  NodeType &my_node;
302  Input my_input;
303 
304 public:
305 
306  apply_body_task_bypass( NodeType &n, const Input &i
308  , node_priority_t node_priority = no_priority
309  ) : graph_task(node_priority),
310 #else
311  ) :
312 #endif
313  my_node(n), my_input(i) {}
314 
316  task * next_task = my_node.apply_body_bypass( my_input );
317  if(next_task == SUCCESSFULLY_ENQUEUED) next_task = NULL;
318  return next_task;
319  }
320 };
321 
323 template< typename NodeType >
324 class source_task_bypass : public graph_task {
325 
326  NodeType &my_node;
327 
328 public:
329 
330  source_task_bypass( NodeType &n ) : my_node(n) {}
331 
333  task *new_task = my_node.apply_body_bypass( );
334  if(new_task == SUCCESSFULLY_ENQUEUED) return NULL;
335  return new_task;
336  }
337 };
338 
339 // ------------------------ end of node task bodies -----------------------------------
340 
342 template< typename Input, typename Output >
343 struct empty_body {
344  Output operator()( const Input & ) const { return Output(); }
345 };
346 
347 template<typename T>
348 class decrementer : public continue_receiver, tbb::internal::no_copy {
349 
351 
353  return my_node->decrement_counter();
354  }
355 
356 protected:
357 
359  return my_node->my_graph;
360  }
361 
362 public:
363 
364  typedef continue_msg input_type;
365  typedef continue_msg output_type;
366  decrementer( int number_of_predecessors = 0 )
367  : continue_receiver(
368  __TBB_FLOW_GRAPH_PRIORITY_ARG1(number_of_predecessors, tbb::flow::internal::no_priority)
369  )
370  // Since decrementer does not make use of possibly unconstructed owner inside its
371  // constructor, my_node can be directly initialized with 'this' pointer passed from the
372  // owner, hence making method 'set_owner' needless.
373  , my_node(NULL)
374  {}
375  void set_owner( T *node ) { my_node = node; }
376 };
377 
378 } // namespace internal
379 
380 #endif // __TBB__flow_graph_body_impl_H
381 
function_body_leaf * clone() __TBB_override
An empty functor that takes an Input and returns a default constructed Output.
A functor that takes no input and generates a value of type Output.
static tbb::task *const SUCCESSFULLY_ENQUEUED
#define __TBB_override
Definition: tbb_stddef.h:244
A task that calls a node's forward_task function.
the leaf for function_body specialized for Output of continue_msg
A functor that takes an Input and generates an Output.
key_matching< tag_value > tag_matching
#define __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES
Definition: tbb_config.h:826
type_to_key_function_body_leaf * clone() __TBB_override
virtual source_body * clone()=0
field of type K being used for matching.
Output operator()(const Input &i) __TBB_override
decrementer(int number_of_predecessors=0)
function_body that takes an Input and a set of output ports
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:335
the leaf for function_body specialized for Input and output of continue_msg
bool operator()(Output &output) __TBB_override
apply_body_task_bypass(NodeType &n, const Input &i)
A task that calls a node's apply_body_bypass function with no input.
virtual multifunction_body * clone()=0
virtual type_to_key_function_body * clone()=0
static const node_priority_t no_priority
virtual void operator()(const Input &, OutputSet &)=0
unsigned int node_priority_t
interface10::internal::Policy< queueing, lightweight > queueing_lightweight
virtual Output operator()(const Input &input)=0
Base class for types that should not be assigned.
Definition: tbb_stddef.h:324
A task that calls a node's apply_body_bypass function, passing in an input of type Input.
task * execute() __TBB_override
Output operator()(const continue_msg &i) __TBB_override
virtual bool operator()(Output &output)=0
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task * task
type_to_key_function_body_leaf * clone() __TBB_override
virtual void * get_body_ptr()=0
The graph class.
virtual function_body * clone()=0
#define __TBB_FLOW_GRAPH_PRIORITY_ARG1(arg1, priority)
interface10::internal::Policy< rejecting, lightweight > rejecting_lightweight
multifunction_body_leaf * clone() __TBB_override
task * execute() __TBB_override
graph & graph_reference() __TBB_override
Output operator()(const Input &) const
The leaf for source_body.
Output operator()(const Input &i) __TBB_override
const Output & operator()(const Input &i) __TBB_override
the leaf for function_body specialized for Input of continue_msg
virtual Output operator()(const Input &input)=0
the leaf for function_body
tbb::internal::uint64_t tag_value
Strips its template type argument from cv- and ref-qualifiers.
continue_msg operator()(const Input &i) __TBB_override
void operator()(const Input &input, OutputSet &oset) __TBB_override
leaf for multifunction. OutputSet can be a std::tuple or a vector.
source_body_leaf * clone() __TBB_override
continue_msg operator()(const continue_msg &i) __TBB_override

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.