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-2020 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#ifndef __TBB__flow_graph_body_impl_H
18#define __TBB__flow_graph_body_impl_H
19
20#ifndef __TBB_flow_graph_H
21#error Do not #include this internal file directly; use public TBB headers instead.
22#endif
23
24// included in namespace tbb::flow::interfaceX (in flow_graph.h)
25
26namespace internal {
27
28typedef tbb::internal::uint64_t tag_value;
29
31
32#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
33
34template<typename ... Policies> struct Policy {};
35
36template<typename ... Policies> struct has_policy;
37
38template<typename ExpectedPolicy, typename FirstPolicy, typename ...Policies>
39struct has_policy<ExpectedPolicy, FirstPolicy, Policies...> :
40 tbb::internal::bool_constant<has_policy<ExpectedPolicy, FirstPolicy>::value ||
41 has_policy<ExpectedPolicy, Policies...>::value> {};
42
43template<typename ExpectedPolicy, typename SinglePolicy>
44struct has_policy<ExpectedPolicy, SinglePolicy> :
45 tbb::internal::bool_constant<tbb::internal::is_same_type<ExpectedPolicy, SinglePolicy>::value> {};
46
47template<typename ExpectedPolicy, typename ...Policies>
48struct has_policy<ExpectedPolicy, Policy<Policies...> > : has_policy<ExpectedPolicy, Policies...> {};
49
50#else
51
52template<typename P1, typename P2 = void> struct Policy {};
53
54template<typename ExpectedPolicy, typename SinglePolicy>
55struct has_policy : tbb::internal::bool_constant<tbb::internal::is_same_type<ExpectedPolicy, SinglePolicy>::value> {};
56
57template<typename ExpectedPolicy, typename P>
58struct has_policy<ExpectedPolicy, Policy<P> > : has_policy<ExpectedPolicy, P> {};
59
60template<typename ExpectedPolicy, typename P1, typename P2>
61struct has_policy<ExpectedPolicy, Policy<P1, P2> > :
62 tbb::internal::bool_constant<has_policy<ExpectedPolicy, P1>::value || has_policy<ExpectedPolicy, P2>::value> {};
63
64#endif
65
66namespace graph_policy_namespace {
67
68 struct rejecting { };
69 struct reserving { };
70 struct queueing { };
71 struct lightweight { };
72
73 // K == type of field used for key-matching. Each tag-matching port will be provided
74 // functor that, given an object accepted by the port, will return the
77 struct key_matching {
78 typedef K key_type;
79 typedef typename strip<K>::type base_key_type;
80 typedef KHash hash_compare_type;
81 };
82
83 // old tag_matching join's new specifier
85
86 // Aliases for Policy combinations
87 typedef interface11::internal::Policy<queueing, lightweight> queueing_lightweight;
88 typedef interface11::internal::Policy<rejecting, lightweight> rejecting_lightweight;
89
90} // namespace graph_policy_namespace
91
92// -------------- function_body containers ----------------------
93
95template< typename Output >
97public:
98 virtual ~source_body() {}
99 virtual bool operator()(Output &output) = 0;
100 virtual source_body* clone() = 0;
101};
102
104template< typename Output, typename Body>
105class source_body_leaf : public source_body<Output> {
106public:
107 source_body_leaf( const Body &_body ) : body(_body) { }
108 bool operator()(Output &output) __TBB_override { return body( output ); }
111 }
112 Body get_body() { return body; }
113private:
114 Body body;
115};
116
118template< typename Input, typename Output >
120public:
121 virtual ~function_body() {}
122 virtual Output operator()(const Input &input) = 0;
123 virtual function_body* clone() = 0;
124};
125
127template <typename Input, typename Output, typename B>
128class function_body_leaf : public function_body< Input, Output > {
129public:
130 function_body_leaf( const B &_body ) : body(_body) { }
131 Output operator()(const Input &i) __TBB_override { return body(i); }
132 B get_body() { return body; }
135 }
136private:
138};
139
141template <typename B>
142class function_body_leaf< continue_msg, continue_msg, B> : public function_body< continue_msg, continue_msg > {
143public:
144 function_body_leaf( const B &_body ) : body(_body) { }
145 continue_msg operator()( const continue_msg &i ) __TBB_override {
146 body(i);
147 return i;
148 }
149 B get_body() { return body; }
152 }
153private:
155};
156
158template <typename Input, typename B>
159class function_body_leaf< Input, continue_msg, B> : public function_body< Input, continue_msg > {
160public:
161 function_body_leaf( const B &_body ) : body(_body) { }
162 continue_msg operator()(const Input &i) __TBB_override {
163 body(i);
164 return continue_msg();
165 }
166 B get_body() { return body; }
169 }
170private:
172};
173
175template <typename Output, typename B>
176class function_body_leaf< continue_msg, Output, B > : public function_body< continue_msg, Output > {
177public:
178 function_body_leaf( const B &_body ) : body(_body) { }
179 Output operator()(const continue_msg &i) __TBB_override {
180 return body(i);
181 }
182 B get_body() { return body; }
185 }
186private:
188};
189
191template<typename Input, typename OutputSet>
193public:
195 virtual void operator()(const Input &/* input*/, OutputSet &/*oset*/) = 0;
196 virtual multifunction_body* clone() = 0;
197 virtual void* get_body_ptr() = 0;
198};
199
201template<typename Input, typename OutputSet, typename B >
202class multifunction_body_leaf : public multifunction_body<Input, OutputSet> {
203public:
204 multifunction_body_leaf(const B &_body) : body(_body) { }
205 void operator()(const Input &input, OutputSet &oset) __TBB_override {
206 body(input, oset); // body may explicitly put() to one or more of oset.
207 }
208 void* get_body_ptr() __TBB_override { return &body; }
211 }
212
213private:
215};
216
217// ------ function bodies for hash_buffers and key-matching joins.
218
219template<typename Input, typename Output>
221 public:
223 virtual Output operator()(const Input &input) = 0; // returns an Output
225};
226
227// specialization for ref output
228template<typename Input, typename Output>
230 public:
232 virtual const Output & operator()(const Input &input) = 0; // returns a const Output&
234};
235
236template <typename Input, typename Output, typename B>
238public:
239 type_to_key_function_body_leaf( const B &_body ) : body(_body) { }
240 Output operator()(const Input &i) __TBB_override { return body(i); }
241 B get_body() { return body; }
244 }
245private:
247};
248
249template <typename Input, typename Output, typename B>
251public:
252 type_to_key_function_body_leaf( const B &_body ) : body(_body) { }
253 const Output& operator()(const Input &i) __TBB_override {
254 return body(i);
255 }
256 B get_body() { return body; }
259 }
260private:
262};
263
264// --------------------------- end of function_body containers ------------------------
265
266// --------------------------- node task bodies ---------------------------------------
267
269template< typename NodeType >
270class forward_task_bypass : public graph_task {
271
272 NodeType &my_node;
273
274public:
275
278 , node_priority_t node_priority = no_priority
279 ) : graph_task(node_priority),
280#else
281 ) :
282#endif
283 my_node(n) {}
284
286 task * new_task = my_node.forward_task();
287 if (new_task == SUCCESSFULLY_ENQUEUED) new_task = NULL;
288 return new_task;
289 }
290};
291
293// return the task* unless it is SUCCESSFULLY_ENQUEUED, in which case return NULL
294template< typename NodeType, typename Input >
295class apply_body_task_bypass : public graph_task {
296
297 NodeType &my_node;
298 Input my_input;
299
300public:
301
302 apply_body_task_bypass( NodeType &n, const Input &i
304 , node_priority_t node_priority = no_priority
305 ) : graph_task(node_priority),
306#else
307 ) :
308#endif
309 my_node(n), my_input(i) {}
310
312 task * next_task = my_node.apply_body_bypass( my_input );
313 if(next_task == SUCCESSFULLY_ENQUEUED) next_task = NULL;
314 return next_task;
315 }
316};
317
319template< typename NodeType >
320class source_task_bypass : public graph_task {
321
322 NodeType &my_node;
323
324public:
325
326 source_task_bypass( NodeType &n ) : my_node(n) {}
327
329 task *new_task = my_node.apply_body_bypass( );
330 if(new_task == SUCCESSFULLY_ENQUEUED) return NULL;
331 return new_task;
332 }
333};
334
335// ------------------------ end of node task bodies -----------------------------------
336
338template< typename Input, typename Output >
340 Output operator()( const Input & ) const { return Output(); }
341};
342
343template<typename T, typename DecrementType, typename DummyType = void>
345
346template<typename T, typename DecrementType>
347class decrementer<T, DecrementType,
348 typename tbb::internal::enable_if<
349 tbb::internal::is_integral<DecrementType>::value, void>::type
350 > : public receiver<DecrementType>, tbb::internal::no_copy {
352protected:
353
354 task* try_put_task( const DecrementType& value ) __TBB_override {
355 task* result = my_node->decrement_counter( value );
356 if( !result )
357 result = SUCCESSFULLY_ENQUEUED;
358 return result;
359 }
360
362 return my_node->my_graph;
363 }
364
365 template<typename U, typename V> friend class tbb::flow::interface11::limiter_node;
367#if TBB_DEPRECATED_FLOW_NODE_EXTRACTION
368 if (f & rf_clear_edges)
369 my_built_predecessors.clear();
370#else
372#endif
373 }
374
375public:
376 // Since decrementer does not make use of possibly unconstructed owner inside its
377 // constructor, my_node can be directly initialized with 'this' pointer passed from the
378 // owner, hence making method 'set_owner' needless.
379 decrementer() : my_node(NULL) {}
380 void set_owner( T *node ) { my_node = node; }
381
382#if TBB_DEPRECATED_FLOW_NODE_EXTRACTION
383 spin_mutex my_mutex;
386
387 typedef internal::edge_container<predecessor_type> built_predecessors_type;
388 typedef typename built_predecessors_type::edge_list_type predecessor_list_type;
389 built_predecessors_type &built_predecessors() __TBB_override { return my_built_predecessors; }
390
391 void internal_add_built_predecessor( predecessor_type &s) __TBB_override {
393 my_built_predecessors.add_edge( s );
394 }
395
396 void internal_delete_built_predecessor( predecessor_type &s) __TBB_override {
398 my_built_predecessors.delete_edge(s);
399 }
400
401 void copy_predecessors( predecessor_list_type &v) __TBB_override {
403 my_built_predecessors.copy_edges(v);
404 }
405
406 size_t predecessor_count() __TBB_override {
408 return my_built_predecessors.edge_count();
409 }
410protected:
411 built_predecessors_type my_built_predecessors;
412#endif /* TBB_DEPRECATED_FLOW_NODE_EXTRACTION */
413};
414
415template<typename T>
416class decrementer<T, continue_msg, void> : public continue_receiver, tbb::internal::no_copy {
417
419
421 return my_node->decrement_counter( 1 );
422 }
423
424protected:
425
427 return my_node->my_graph;
428 }
429
430public:
431
432 typedef continue_msg input_type;
433 typedef continue_msg output_type;
434 decrementer( int number_of_predecessors = 0 )
435 : continue_receiver(
436 __TBB_FLOW_GRAPH_PRIORITY_ARG1(number_of_predecessors, tbb::flow::internal::no_priority)
437 )
438 // Since decrementer does not make use of possibly unconstructed owner inside its
439 // constructor, my_node can be directly initialized with 'this' pointer passed from the
440 // owner, hence making method 'set_owner' needless.
441 , my_node(NULL)
442 {}
443 void set_owner( T *node ) { my_node = node; }
444};
445
446} // namespace internal
447
448#endif // __TBB__flow_graph_body_impl_H
449
#define __TBB_FLOW_GRAPH_PRIORITY_ARG1(arg1, priority)
#define __TBB_override
Definition: tbb_stddef.h:240
#define __TBB_PREVIEW_FLOW_GRAPH_PRIORITIES
Definition: tbb_config.h:857
void const char const char int ITT_FORMAT __itt_group_sync s
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
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 value
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_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
The graph class.
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
tbb::internal::uint64_t tag_value
key_matching< tag_value > tag_matching
interface11::internal::Policy< rejecting, lightweight > rejecting_lightweight
interface11::internal::Policy< queueing, lightweight > queueing_lightweight
static const node_priority_t no_priority
unsigned int node_priority_t
static tbb::task *const SUCCESSFULLY_ENQUEUED
Forwards messages only if the threshold has not been reached.
Definition: flow_graph.h:2977
receiver< input_type >::predecessor_type predecessor_type
Definition: flow_graph.h:2981
untyped_sender predecessor_type
The predecessor type for this node.
Definition: flow_graph.h:369
field of type K being used for matching.
A functor that takes no input and generates a value of type Output.
virtual source_body * clone()=0
virtual bool operator()(Output &output)=0
The leaf for source_body.
bool operator()(Output &output) __TBB_override
source_body_leaf * clone() __TBB_override
A functor that takes an Input and generates an Output.
virtual function_body * clone()=0
virtual Output operator()(const Input &input)=0
the leaf for function_body
Output operator()(const Input &i) __TBB_override
function_body_leaf * clone() __TBB_override
the leaf for function_body specialized for Input and output of continue_msg
continue_msg operator()(const continue_msg &i) __TBB_override
the leaf for function_body specialized for Output of continue_msg
continue_msg operator()(const Input &i) __TBB_override
the leaf for function_body specialized for Input of continue_msg
Output operator()(const continue_msg &i) __TBB_override
function_body that takes an Input and a set of output ports
virtual void * get_body_ptr()=0
virtual multifunction_body * clone()=0
virtual void operator()(const Input &, OutputSet &)=0
leaf for multifunction. OutputSet can be a std::tuple or a vector.
void operator()(const Input &input, OutputSet &oset) __TBB_override
multifunction_body_leaf * clone() __TBB_override
virtual type_to_key_function_body * clone()=0
virtual Output operator()(const Input &input)=0
virtual type_to_key_function_body * clone()=0
virtual const Output & operator()(const Input &input)=0
Output operator()(const Input &i) __TBB_override
type_to_key_function_body_leaf * clone() __TBB_override
const Output & operator()(const Input &i) __TBB_override
type_to_key_function_body_leaf * clone() __TBB_override
A task that calls a node's forward_task function.
A task that calls a node's apply_body_bypass function, passing in an input of type Input.
apply_body_task_bypass(NodeType &n, const Input &i)
A task that calls a node's apply_body_bypass function with no input.
task * execute() __TBB_override
An empty functor that takes an Input and returns a default constructed Output.
Output operator()(const Input &) const
Strips its template type argument from cv- and ref-qualifiers.
friend class scoped_lock
Definition: spin_mutex.h:179
Base class for types that should not be assigned.
Definition: tbb_stddef.h:322
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:330

Copyright © 2005-2020 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.