Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::parallel_while< Body > Class Template Reference

Parallel iteration over a stream, with optional addition of more work. More...

#include <parallel_while.h>

Inheritance diagram for tbb::parallel_while< Body >:
Collaboration diagram for tbb::parallel_while< Body >:

Public Types

typedef Body::argument_type value_type
 Type of items. More...
 

Public Member Functions

 parallel_while ()
 Construct empty non-running parallel while. More...
 
 ~parallel_while ()
 Destructor cleans up data members before returning. More...
 
template<typename Stream >
void run (Stream &stream, const Body &body)
 Apply body.apply to each item in the stream. More...
 
void add (const value_type &item)
 Add a work item while running. More...
 

Private Attributes

const Body * my_body
 
empty_taskmy_barrier
 

Additional Inherited Members

- Private Member Functions inherited from tbb::internal::no_copy
 no_copy ()
 Allow default construction. More...
 

Detailed Description

template<typename Body>
class tbb::parallel_while< Body >

Parallel iteration over a stream, with optional addition of more work.

The Body b has the requirement:
"b(v)"
"b.argument_type"
where v is an argument_type

Definition at line 30 of file parallel_while.h.

Member Typedef Documentation

◆ value_type

template<typename Body >
typedef Body::argument_type tbb::parallel_while< Body >::value_type

Type of items.

Definition at line 143 of file parallel_while.h.

Constructor & Destructor Documentation

◆ parallel_while()

template<typename Body >
tbb::parallel_while< Body >::parallel_while ( )
inline

Construct empty non-running parallel while.

Definition at line 132 of file parallel_while.h.

132 : my_body(NULL), my_barrier(NULL) {}
empty_task * my_barrier
const Body * my_body

◆ ~parallel_while()

template<typename Body >
tbb::parallel_while< Body >::~parallel_while ( )
inline

Destructor cleans up data members before returning.

Definition at line 135 of file parallel_while.h.

135  {
136  if( my_barrier ) {
137  my_barrier->destroy(*my_barrier);
138  my_barrier = NULL;
139  }
140  }
empty_task * my_barrier

References tbb::parallel_while< Body >::my_barrier.

Member Function Documentation

◆ add()

template<typename Body >
void tbb::parallel_while< Body >::add ( const value_type item)

Add a work item while running.

Should be executed only by body.apply or a thread spawned therefrom.

Definition at line 177 of file parallel_while.h.

177  {
178  __TBB_ASSERT(my_barrier,"attempt to add to parallel_while that is not running");
179  typedef internal::while_iteration_task<Body> iteration_type;
180  iteration_type& i = *new( task::allocate_additional_child_of(*my_barrier) ) iteration_type(item,*my_body);
181  task::self().spawn( i );
182 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static task &__TBB_EXPORTED_FUNC self()
The innermost task being executed or destroyed by the current thread at the moment.
Definition: task.cpp:205
empty_task * my_barrier
const Body * my_body

References __TBB_ASSERT, and tbb::task::self().

Here is the call graph for this function:

◆ run()

template<typename Body >
template<typename Stream >
void tbb::parallel_while< Body >::run ( Stream &  stream,
const Body &  body 
)

Apply body.apply to each item in the stream.

A Stream s has the requirements
"S::value_type"
"s.pop_if_present(value) is convertible to bool

Definition at line 163 of file parallel_while.h.

163  {
164  using namespace internal;
165  empty_task& barrier = *new( task::allocate_root() ) empty_task();
166  my_body = &body;
167  my_barrier = &barrier;
169  while_task<Stream,Body>& w = *new( my_barrier->allocate_child() ) while_task<Stream,Body>( stream, body, barrier );
171  my_barrier->destroy(*my_barrier);
172  my_barrier = NULL;
173  my_body = NULL;
174 }
internal::allocate_child_proxy & allocate_child()
Returns proxy for overloaded new that allocates a child task of *this.
Definition: task.h:654
void spawn_and_wait_for_all(task &child)
Similar to spawn followed by wait_for_all, but more efficient.
Definition: task.h:773
empty_task * my_barrier
const Body * my_body
void set_ref_count(int count)
Set reference count.
Definition: task.h:734
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:636

References tbb::task::allocate_root(), tbb::task::set_ref_count(), and tbb::task::spawn_and_wait_for_all().

Here is the call graph for this function:

Member Data Documentation

◆ my_barrier

template<typename Body >
empty_task* tbb::parallel_while< Body >::my_barrier
private

Definition at line 158 of file parallel_while.h.

Referenced by tbb::parallel_while< Body >::~parallel_while().

◆ my_body

template<typename Body >
const Body* tbb::parallel_while< Body >::my_body
private

Definition at line 157 of file parallel_while.h.


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.