Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::stage_task Class Reference
Inheritance diagram for tbb::internal::stage_task:
Collaboration diagram for tbb::internal::stage_task:

Public Member Functions

 stage_task (pipeline &pipeline)
 Construct stage_task for first stage in a pipeline. More...
 
 stage_task (pipeline &pipeline, filter *filter_, const task_info &info)
 Construct stage_task for a subsequent stage in a pipeline. More...
 
void reset ()
 Roughly equivalent to the constructor of input stage task. More...
 
taskexecute () __TBB_override
 The virtual task execution method. More...
 
void spawn_stage_task (const task_info &info)
 Creates and spawns stage_task from task_info. More...
 
- Public Member Functions inherited from tbb::task
virtual ~task ()
 Destructor. More...
 
internal::allocate_continuation_proxy & allocate_continuation ()
 Returns proxy for overloaded new that allocates a continuation task of *this. More...
 
internal::allocate_child_proxy & allocate_child ()
 Returns proxy for overloaded new that allocates a child task of *this. More...
 
void recycle_as_continuation ()
 Change this to be a continuation of its former self. More...
 
void recycle_as_safe_continuation ()
 Recommended to use, safe variant of recycle_as_continuation. More...
 
void recycle_as_child_of (task &new_parent)
 Change this to be a child of new_parent. More...
 
void recycle_to_reexecute ()
 Schedule this for reexecution after current execute() returns. More...
 
void set_ref_count (int count)
 Set reference count. More...
 
void increment_ref_count ()
 Atomically increment reference count. More...
 
int add_ref_count (int count)
 Atomically adds to reference count and returns its new value. More...
 
int decrement_ref_count ()
 Atomically decrement reference count and returns its new value. More...
 
void spawn_and_wait_for_all (task &child)
 Similar to spawn followed by wait_for_all, but more efficient. More...
 
void __TBB_EXPORTED_METHOD spawn_and_wait_for_all (task_list &list)
 Similar to spawn followed by wait_for_all, but more efficient. More...
 
void wait_for_all ()
 Wait for reference count to become one, and set reference count to zero. More...
 
taskparent () const
 task on whose behalf this task is working, or NULL if this is a root. More...
 
void set_parent (task *p)
 sets parent task pointer to specified value More...
 
task_group_contextcontext ()
 This method is deprecated and will be removed in the future. More...
 
task_group_contextgroup ()
 Pointer to the task group descriptor. More...
 
bool is_stolen_task () const
 True if task was stolen from the task pool of another thread. More...
 
state_type state () const
 Current execution state. More...
 
int ref_count () const
 The internal reference count. More...
 
bool __TBB_EXPORTED_METHOD is_owned_by_current_thread () const
 Obsolete, and only retained for the sake of backward compatibility. Always returns true. More...
 
void set_affinity (affinity_id id)
 Set affinity for this task. More...
 
affinity_id affinity () const
 Current affinity of this task. More...
 
virtual void __TBB_EXPORTED_METHOD note_affinity (affinity_id id)
 Invoked by scheduler to notify task that it ran on unexpected thread. More...
 
void __TBB_EXPORTED_METHOD change_group (task_group_context &ctx)
 Moves this task from its current group into another one. More...
 
bool cancel_group_execution ()
 Initiates cancellation of all tasks in this cancellation group and its subordinate groups. More...
 
bool is_cancelled () const
 Returns true if the context has received cancellation request. More...
 
void set_group_priority (priority_t p)
 Changes priority of the task group this task belongs to. More...
 
priority_t group_priority () const
 Retrieves current priority of the task group this task belongs to. More...
 
- Public Member Functions inherited from tbb::internal::task_info
void reset ()
 Set to initial state (no object, no token) More...
 

Private Attributes

pipelinemy_pipeline
 
filtermy_filter
 
bool my_at_start
 True if this task has not yet read the input. More...
 

Friends

class tbb::pipeline
 

Additional Inherited Members

- Public Types inherited from tbb::task
enum  state_type {
  executing, reexecute, ready, allocated,
  freed, recycle
}
 Enumeration of task states that the scheduler considers. More...
 
typedef internal::affinity_id affinity_id
 An id as used for specifying affinity. More...
 
- Static Public Member Functions inherited from tbb::task
static internal::allocate_root_proxy allocate_root ()
 Returns proxy for overloaded new that allocates a root task. More...
 
static internal::allocate_root_with_context_proxy allocate_root (task_group_context &ctx)
 Returns proxy for overloaded new that allocates a root task associated with user supplied context. More...
 
static void spawn_root_and_wait (task &root)
 Spawn task allocated by allocate_root, wait for it to complete, and deallocate it. More...
 
static void spawn_root_and_wait (task_list &root_list)
 Spawn root tasks on list and wait for all of them to finish. More...
 
static void enqueue (task &t)
 Enqueue task for starvation-resistant execution. More...
 
static void enqueue (task &t, priority_t p)
 Enqueue task for starvation-resistant execution on the specified priority level. More...
 
static task &__TBB_EXPORTED_FUNC self ()
 The innermost task being executed or destroyed by the current thread at the moment. More...
 
- Public Attributes inherited from tbb::internal::task_info
voidmy_object
 
Token my_token
 Invalid unless a task went through an ordered stage. More...
 
bool my_token_ready
 False until my_token is set. More...
 
bool is_valid
 True if my_object is valid. More...
 
- Protected Member Functions inherited from tbb::task
 task ()
 Default constructor. More...
 

Detailed Description

Definition at line 253 of file pipeline.cpp.

Constructor & Destructor Documentation

◆ stage_task() [1/2]

tbb::internal::stage_task::stage_task ( pipeline pipeline)
inline

Construct stage_task for first stage in a pipeline.

Such a stage has not read any input yet.

Definition at line 264 of file pipeline.cpp.

264  :
265  my_pipeline(pipeline),
266  my_filter(pipeline.filter_list),
267  my_at_start(true)
268  {
270  }
bool my_at_start
True if this task has not yet read the input.
Definition: pipeline.cpp:259
void reset()
Set to initial state (no object, no token)
Definition: pipeline.cpp:43

References tbb::internal::task_info::reset().

Referenced by execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stage_task() [2/2]

tbb::internal::stage_task::stage_task ( pipeline pipeline,
filter filter_,
const task_info info 
)
inline

Construct stage_task for a subsequent stage in a pipeline.

Definition at line 272 of file pipeline.cpp.

272  :
273  task_info(info),
274  my_pipeline(pipeline),
275  my_filter(filter_),
276  my_at_start(false)
277  {}
bool my_at_start
True if this task has not yet read the input.
Definition: pipeline.cpp:259

Member Function Documentation

◆ execute()

task * tbb::internal::stage_task::execute ( )
virtual

The virtual task execution method.

Implements tbb::task.

Definition at line 305 of file pipeline.cpp.

305  {
306  __TBB_ASSERT( !my_at_start || !my_object, NULL );
307  __TBB_ASSERT( !my_filter->is_bound(), NULL );
308  if( my_at_start ) {
309  if( my_filter->is_serial() ) {
310  my_object = (*my_filter)(my_object);
312  {
313  if( my_filter->is_ordered() ) {
314  my_token = my_pipeline.token_counter++; // ideally, with relaxed semantics
315  my_token_ready = true;
318  my_pipeline.token_counter++; // ideally, with relaxed semantics
319  }
320  if( !my_filter->next_filter_in_pipeline ) { // we're only filter in pipeline
321  reset();
322  goto process_another_stage;
323  } else {
325  if( --my_pipeline.input_tokens>0 )
326  spawn( *new( allocate_additional_child_of(*parent()) ) stage_task( my_pipeline ) );
327  }
328  } else {
329  my_pipeline.end_of_input = true;
330  return NULL;
331  }
332  } else /*not is_serial*/ {
334  return NULL;
338  }
340  if( --my_pipeline.input_tokens>0 )
341  spawn( *new( allocate_additional_child_of(*parent()) ) stage_task( my_pipeline ) );
342  my_object = (*my_filter)(my_object);
343  if( !my_object && (!my_filter->object_may_be_null() || my_filter->my_input_buffer->my_tls_end_of_input()) )
344  {
345  my_pipeline.end_of_input = true;
348  my_pipeline.token_counter--; // fix token_counter
349  }
350  return NULL;
351  }
352  }
353  my_at_start = false;
354  } else {
355  my_object = (*my_filter)(my_object);
356  if( my_filter->is_serial() )
357  my_filter->my_input_buffer->note_done(my_token, *this);
358  }
360  if( my_filter ) {
361  // There is another filter to execute.
362  if( my_filter->is_serial() ) {
363  // The next filter must execute tokens in order
364  if( my_filter->my_input_buffer->put_token(*this) ){
365  // Can't proceed with the same item
366  if( my_filter->is_bound() ) {
367  // Find the next non-thread-bound filter
368  do {
370  } while( my_filter && my_filter->is_bound() );
371  // Check if there is an item ready to process
372  if( my_filter && my_filter->my_input_buffer->return_item(*this, !my_filter->is_serial()))
373  goto process_another_stage;
374  }
375  my_filter = NULL; // To prevent deleting my_object twice if exception occurs
376  return NULL;
377  }
378  }
379  } else {
380  // Reached end of the pipe.
381  size_t ntokens_avail = ++my_pipeline.input_tokens;
383  if(ntokens_avail == 1) {
385  }
386  return NULL;
387  }
388  if( ntokens_avail>1 // Only recycle if there is one available token
390  return NULL; // No need to recycle for new input
391  }
392  ITT_NOTIFY( sync_acquired, &my_pipeline.input_tokens );
393  // Recycle as an input stage task.
394  reset();
395  }
396 process_another_stage:
397  /* A semi-hackish way to reexecute the same task object immediately without spawning.
398  recycle_as_continuation marks the task for future execution,
399  and then 'this' pointer is returned to bypass spawning. */
401  return this;
402 }
bool is_serial() const
True if filter is serial.
Definition: pipeline.h:129
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
const unsigned char my_filter_mode
Storage for filter mode and dynamically checked implementation version.
Definition: pipeline.h:182
filter * next_filter_in_pipeline
Pointer to next filter in the pipeline.
Definition: pipeline.h:160
bool my_at_start
True if this task has not yet read the input.
Definition: pipeline.cpp:259
void reset()
Roughly equivalent to the constructor of input stage task.
Definition: pipeline.cpp:279
filter * filter_list
Pointer to first filter in the pipeline.
Definition: pipeline.h:268
bool has_thread_bound_filters
True if the pipeline contains a thread-bound filter; false otherwise.
Definition: pipeline.h:286
bool is_ordered() const
True if filter must receive stream in order.
Definition: pipeline.h:134
task * parent() const
task on whose behalf this task is working, or NULL if this is a root.
Definition: task.h:830
Token my_token
Invalid unless a task went through an ordered stage.
Definition: pipeline.cpp:37
bool object_may_be_null()
true if an input filter can emit null
Definition: pipeline.h:144
bool my_token_ready
False until my_token is set.
Definition: pipeline.cpp:39
#define __TBB_PIPELINE_VERSION(x)
Definition: pipeline.h:42
atomic< internal::Token > input_tokens
Number of idle tokens waiting for input stage.
Definition: pipeline.h:277
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 sync_releasing
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:120
atomic< internal::Token > token_counter
Global counter of tokens.
Definition: pipeline.h:280
stage_task(pipeline &pipeline)
Construct stage_task for first stage in a pipeline.
Definition: pipeline.cpp:264
void recycle_as_continuation()
Change this to be a continuation of its former self.
Definition: task.h:684
bool is_bound() const
True if filter is thread-bound.
Definition: pipeline.h:139
static const unsigned char version_mask
Definition: pipeline.h:93
internal::input_buffer * my_input_buffer
Buffer for incoming tokens, or NULL if not required.
Definition: pipeline.h:174
bool end_of_input
False until fetch_input returns NULL.
Definition: pipeline.h:283

References __TBB_ASSERT, __TBB_PIPELINE_VERSION, tbb::pipeline::end_of_input, tbb::pipeline::filter_list, tbb::pipeline::has_thread_bound_filters, tbb::pipeline::input_tokens, tbb::filter::is_bound(), tbb::filter::is_ordered(), tbb::filter::is_serial(), ITT_NOTIFY, my_at_start, my_filter, tbb::filter::my_filter_mode, tbb::filter::my_input_buffer, tbb::internal::task_info::my_object, my_pipeline, tbb::internal::task_info::my_token, tbb::internal::task_info::my_token_ready, tbb::filter::next_filter_in_pipeline, tbb::filter::object_may_be_null(), tbb::task::parent(), tbb::task::recycle_as_continuation(), reset(), stage_task(), sync_releasing, tbb::pipeline::token_counter, and tbb::filter::version_mask.

Here is the call graph for this function:

◆ reset()

void tbb::internal::stage_task::reset ( )
inline

Roughly equivalent to the constructor of input stage task.

Definition at line 279 of file pipeline.cpp.

279  {
282  my_at_start = true;
283  }
bool my_at_start
True if this task has not yet read the input.
Definition: pipeline.cpp:259
void reset()
Set to initial state (no object, no token)
Definition: pipeline.cpp:43
filter * filter_list
Pointer to first filter in the pipeline.
Definition: pipeline.h:268

References tbb::pipeline::filter_list, my_at_start, my_filter, my_pipeline, and tbb::internal::task_info::reset().

Referenced by execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spawn_stage_task()

void tbb::internal::stage_task::spawn_stage_task ( const task_info info)
inline

Creates and spawns stage_task from task_info.

Definition at line 297 of file pipeline.cpp.

298  {
299  stage_task* clone = new (allocate_additional_child_of(*parent()))
300  stage_task( my_pipeline, my_filter, info );
301  spawn(*clone);
302  }
task * parent() const
task on whose behalf this task is working, or NULL if this is a root.
Definition: task.h:830
stage_task(pipeline &pipeline)
Construct stage_task for first stage in a pipeline.
Definition: pipeline.cpp:264

Friends And Related Function Documentation

◆ tbb::pipeline

friend class tbb::pipeline
friend

Definition at line 255 of file pipeline.cpp.

Member Data Documentation

◆ my_at_start

bool tbb::internal::stage_task::my_at_start
private

True if this task has not yet read the input.

Definition at line 259 of file pipeline.cpp.

Referenced by execute(), and reset().

◆ my_filter

filter* tbb::internal::stage_task::my_filter
private

Definition at line 257 of file pipeline.cpp.

Referenced by execute(), and reset().

◆ my_pipeline

pipeline& tbb::internal::stage_task::my_pipeline
private

Definition at line 256 of file pipeline.cpp.

Referenced by execute(), and reset().


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

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.