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 26 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 139 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 128 of file parallel_while.h.

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

◆ ~parallel_while()

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

Destructor cleans up data members before returning.

Definition at line 131 of file parallel_while.h.

131  {
132  if( my_barrier ) {
133  my_barrier->destroy(*my_barrier);
134  my_barrier = NULL;
135  }
136  }
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 173 of file parallel_while.h.

173  {
174  __TBB_ASSERT(my_barrier,"attempt to add to parallel_while that is not running");
175  typedef internal::while_iteration_task<Body> iteration_type;
176  iteration_type& i = *new( task::allocate_additional_child_of(*my_barrier) ) iteration_type(item,*my_body);
177  task::self().spawn( i );
178 }
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
const Body * my_body
empty_task * my_barrier

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

159  {
160  using namespace internal;
161  empty_task& barrier = *new( task::allocate_root() ) empty_task();
162  my_body = &body;
163  my_barrier = &barrier;
165  while_task<Stream,Body>& w = *new( my_barrier->allocate_child() ) while_task<Stream,Body>( stream, body, barrier );
167  my_barrier->destroy(*my_barrier);
168  my_barrier = NULL;
169  my_body = NULL;
170 }
const Body * my_body
empty_task * my_barrier
void spawn_and_wait_for_all(task &child)
Similar to spawn followed by wait_for_all, but more efficient.
Definition: task.h:770
internal::allocate_child_proxy & allocate_child()
Returns proxy for overloaded new that allocates a child task of *this.
Definition: task.h:651
void set_ref_count(int count)
Set reference count.
Definition: task.h:731
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:633

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 154 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 153 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.