Home ⌂Doc Index ◂Up ▴
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 (const no_copy &)=delete
 
 no_copy ()=default
 

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 29 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 142 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 131 of file parallel_while.h.

131 : 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 134 of file parallel_while.h.

134  {
135  if( my_barrier ) {
136  my_barrier->destroy(*my_barrier);
137  my_barrier = NULL;
138  }
139  }
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 176 of file parallel_while.h.

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

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 162 of file parallel_while.h.

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

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 157 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 156 of file parallel_while.h.


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

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.