17 #ifndef __TBB_pipeline_H 18 #define __TBB_pipeline_H 20 #define __TBB_pipeline_H_include_area 28 #if __TBB_CPP11_TYPE_PROPERTIES_PRESENT 29 #include <type_traits> 41 #define __TBB_PIPELINE_VERSION(x) ((unsigned char)(x-2)<<1) 52 namespace interface6 {
53 template<
typename T,
typename U>
class filter_t;
70 static const unsigned char filter_is_serial = 0x1;
75 static const unsigned char filter_is_out_of_order = 0x1<<4;
78 static const unsigned char filter_is_bound = 0x1<<5;
81 static const unsigned char filter_may_emit_null = 0x1<<6;
84 static const unsigned char exact_exception_propagation =
85 #if TBB_USE_CAPTURED_EXCEPTION 92 static const unsigned char version_mask = 0x7<<1;
96 parallel = current_version | filter_is_out_of_order,
98 serial_in_order = current_version | filter_is_serial,
100 serial_out_of_order = current_version | filter_is_serial | filter_is_out_of_order,
106 next_filter_in_pipeline(not_in_pipeline()),
107 my_input_buffer(NULL),
108 my_filter_mode(static_cast<unsigned char>((is_serial_ ?
serial : parallel) | exact_exception_propagation)),
109 prev_filter_in_pipeline(not_in_pipeline()),
115 next_filter_in_pipeline(not_in_pipeline()),
116 my_input_buffer(NULL),
117 my_filter_mode(static_cast<unsigned char>(filter_mode | exact_exception_propagation)),
118 prev_filter_in_pipeline(not_in_pipeline()),
129 return bool( my_filter_mode & filter_is_serial );
134 return (my_filter_mode & (filter_is_out_of_order|filter_is_serial))==filter_is_serial;
139 return ( my_filter_mode & filter_is_bound )==filter_is_bound;
144 return ( my_filter_mode & filter_may_emit_null ) == filter_may_emit_null;
149 virtual void* operator()(
void* item ) = 0;
155 #if __TBB_TASK_GROUP_CONTEXT 169 bool has_more_work();
177 friend class pipeline;
230 result_type internal_process_item(
bool is_blocking);
250 #if __TBB_TASK_GROUP_CONTEXT 276 atomic<internal::Token> input_tokens;
279 atomic<internal::Token> token_counter;
285 bool has_thread_bound_filters;
288 void remove_filter(
filter& filter_ );
293 #if __TBB_TASK_GROUP_CONTEXT 294 void clear_filters();
304 namespace interface11 {
305 template<
typename Output>
class input_node;
309 namespace interface6 {
322 void stop() { is_pipeline_stopped =
true; }
329 #if __TBB_CPP11_TYPE_PROPERTIES_PRESENT 349 #if !_MSC_VER || defined(_NATIVE_WCHAR_T_DEFINED) 352 #endif // tbb_trivially_copyable 370 #if __TBB_CPP11_RVALUE_REF_PRESENT 373 static pointer create_token(
const value_type & source)
376 pointer output_t = allocator().allocate(1);
379 static value_type &
token(pointer & t) {
return *t; }
383 allocator().destroy(token);
384 allocator().deallocate(token,1);
394 static pointer
create_token(
const value_type & source) {
return source; }
395 static value_type &
token(pointer & t) {
return t; }
407 } type_to_void_ptr_map;
411 static pointer
create_token(
const value_type & source) {
return source; }
412 static value_type &
token(pointer & t) {
return t; }
414 type_to_void_ptr_map mymap;
415 mymap.void_overlay = NULL;
416 mymap.actual_value = ref;
417 return mymap.void_overlay;
420 type_to_void_ptr_map mymap;
421 mymap.void_overlay = ref;
422 return mymap.actual_value;
428 template<
typename T,
typename U,
typename Body>
437 t_pointer temp_input = t_helper::cast_from_void_ptr(input);
438 u_pointer output_u = u_helper::create_token(my_body(
tbb::internal::move(t_helper::token(temp_input))));
439 t_helper::destroy_token(temp_input);
440 return u_helper::cast_to_void_ptr(output_u);
444 t_pointer temp_input = t_helper::cast_from_void_ptr(input);
445 t_helper::destroy_token(temp_input);
453 template<
typename U,
typename Body>
461 u_pointer output_u = u_helper::create_token(my_body(control));
463 u_helper::destroy_token(output_u);
467 return u_helper::cast_to_void_ptr(output_u);
478 template<
typename T,
typename Body>
485 t_pointer temp_input = t_helper::cast_from_void_ptr(input);
487 t_helper::destroy_token(temp_input);
491 t_pointer temp_input = t_helper::cast_from_void_ptr(input);
492 t_helper::destroy_token(temp_input);
499 template<
typename Body>
520 while(
filter* f = my_pipe.filter_list )
534 #ifdef __TBB_TEST_FILTER_NODE_COUNT 535 ++(__TBB_TEST_FILTER_NODE_COUNT);
540 virtual void add_to( pipeline& ) = 0;
550 #ifdef __TBB_TEST_FILTER_NODE_COUNT 551 --(__TBB_TEST_FILTER_NODE_COUNT);
557 template<
typename T,
typename U,
typename Body>
593 template<
typename T,
typename U,
typename Body>
598 template<
typename T,
typename V,
typename U>
600 __TBB_ASSERT(left.
root,
"cannot use default-constructed filter_t as left argument of '&'");
601 __TBB_ASSERT(right.
root,
"cannot use default-constructed filter_t as right argument of '&'");
606 template<
typename T,
typename U>
614 template<
typename T_,
typename U_,
typename Body>
616 template<
typename T_,
typename V_,
typename U_>
624 template<
typename Body>
626 root( new
internal::filter_node_leaf<T,U,Body>(mode, body) ) {
633 filter_node* old = root;
644 filter_node* old = root;
652 __TBB_ASSERT( filter_chain.
root,
"cannot apply parallel_pipeline to default-constructed filter_t" );
663 pipe->run(max_number_of_live_tokens
664 #
if __TBB_TASK_GROUP_CONTEXT
670 #if __TBB_TASK_GROUP_CONTEXT 675 #endif // __TBB_TASK_GROUP_CONTEXT 687 #undef __TBB_pipeline_H_include_area t_helper::pointer t_pointer
internal::filter_node filter_node
concrete_filter(tbb::filter::mode filter_mode, const Body &body)
The class that represents an object of the pipeline for parallel_pipeline().
concrete_filter(tbb::filter::mode filter_mode, const Body &body)
void parallel_pipeline(size_t max_number_of_live_tokens, const filter_t< void, void > &filter_chain, tbb::task_group_context &context)
#define __TBB_TASK_GROUP_CONTEXT
filter_t(tbb::filter::mode mode, const Body &body)
static void destroy_token(pointer)
filter * next_segment
Pointer to the next "segment" of filters, or NULL if not required.
token_helper< U, use_allocator< U >::value > u_helper
Node in parse tree representing result of make_filter.
void remove_ref()
Decrement reference count and delete if it becomes zero.
static filter * not_in_pipeline()
Value used to mark "not in pipeline".
void finalize(void *input) __TBB_override
Destroys item if pipeline was cancelled.
bool is_ordered() const
True if filter must receive stream in order.
#define __TBB_PIPELINE_VERSION(x)
void * operator()(void *) __TBB_override
Operate on an item from the input stream, and return item for output stream.
static value_type & token(pointer &t)
u_helper::pointer u_pointer
filter_node_join(filter_node &x, filter_node &y)
static pointer cast_from_void_ptr(void *ref)
thread_bound_filter(mode filter_mode)
Base class for types that should not be copied or assigned.
concrete_filter(tbb::filter::mode filter_mode, const Body &body)
filter * prev_filter_in_pipeline
Pointer to previous filter in the pipeline.
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 mode
static void destroy_token(pointer)
virtual void finalize(void *)
Destroys item if pipeline was cancelled.
bool is_serial() const
True if filter is serial.
token_helper< U, use_allocator< U >::value > u_helper
static pointer cast_from_void_ptr(void *ref)
void operator=(const filter_t< T, U > &rhs)
tbb::tbb_allocator< T > allocator
class __TBB_DEPRECATED_MSG("tbb::tbb_hash is deprecated, use std::hash") tbb_hash
internal::input_buffer * my_input_buffer
Buffer for incoming tokens, or NULL if not required.
static value_type & token(pointer &t)
const tbb::filter::mode mode
A stage in a pipeline served by a user thread.
void * operator()(void *input) __TBB_override
Operate on an item from the input stream, and return item for output stream.
static void * cast_to_void_ptr(pointer ref)
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 size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
concrete_filter(filter::mode filter_mode, const Body &body)
Base class for user-defined tasks.
filter * next_filter_in_pipeline
Pointer to next filter in the pipeline.
Abstract base class that represents a node in a parse tree underlying a filter_t. ...
void * operator()(void *) __TBB_override
Operate on an item from the input stream, and return item for output stream.
filter_t(filter_node *root_)
bool object_may_be_null()
true if an input filter can emit null
void add_to(pipeline &p) __TBB_override
Add concrete_filter to pipeline.
void * operator()(void *input) __TBB_override
Operate on an item from the input stream, and return item for output stream.
static void * cast_to_void_ptr(pointer ref)
static void destroy_token(pointer token)
input_filter control to signal end-of-input for parallel_pipeline
void const char const char int ITT_FORMAT __itt_group_sync p
Node in parse tree representing join of two filters.
tbb::atomic< intptr_t > ref_count
An executable node that acts as a source, i.e. it has no predecessors.
token_helper< T, use_allocator< T >::value > t_helper
A buffer of input items for a filter.
static value_type & token(pointer &t)
bool is_bound() const
True if filter is thread-bound.
static const unsigned char filter_is_serial
The lowest bit 0 is for parallel vs. serial.
void parallel_pipeline(size_t max_number_of_live_tokens, const filter_t< void, void > &filter_chain)
virtual void add_to(pipeline &)=0
Add concrete_filter to pipeline.
filter_t(const filter_t< T, U > &rhs)
pipeline * my_pipeline
Pointer to the pipeline.
token_helper< T, use_allocator< T >::value > t_helper
const unsigned char my_filter_mode
Storage for filter mode and dynamically checked implementation version.
filter_t< T, U > make_filter(tbb::filter::mode mode, const Body &body)
Create a filter to participate in parallel_pipeline.
#define __TBB_EXPORTED_METHOD
void finalize(void *input) __TBB_override
Destroys item if pipeline was cancelled.
Used to form groups of tasks.
static pointer create_token(const value_type &source)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
t_helper::pointer t_pointer
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
u_helper::pointer u_pointer
static pointer create_token(const value_type &source)
Class representing a chain of type-safe pipeline filters.
filter_node_leaf(tbb::filter::mode m, const Body &b)
void add_to(pipeline &p) __TBB_override
Add concrete_filter to pipeline.
void add_ref()
Increment reference count.
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
static void * cast_to_void_ptr(pointer ref)
filter_t< T, U > operator &(const filter_t< T, V > &left, const filter_t< V, U > &right)
tbb::pipeline * operator->()
static pointer cast_from_void_ptr(void *ref)
static pointer create_token(value_type &&source)
void move(tbb_thread &t1, tbb_thread &t2)