Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::flow::interface10::source_node< Output > Class Template Reference

An executable node that acts as a source, i.e. it has no predecessors. More...

#include <flow_graph.h>

Inheritance diagram for tbb::flow::interface10::source_node< Output >:
Collaboration diagram for tbb::flow::interface10::source_node< Output >:

Public Types

typedef Output output_type
 The type of the output message, which is complete. More...
 
typedef sender< output_type >::successor_type successor_type
 The type of successors of this node. More...
 
typedef null_type input_type
 
- Public Types inherited from tbb::flow::interface10::sender< Output >
typedef Output output_type
 The output type of this sender. More...
 
typedef internal::async_helpers< Output >::filtered_type filtered_type
 
- Public Types inherited from tbb::flow::interface10::internal::untyped_sender
typedef untyped_receiver successor_type
 The successor type for this node. More...
 

Public Member Functions

template<typename Body >
 source_node (graph &g, Body body, bool is_active=true)
 Constructor for a node with a successor. More...
 
 source_node (const source_node &src)
 Copy constructor. More...
 
 ~source_node ()
 The destructor. More...
 
bool register_successor (successor_type &r) __TBB_override
 Add a new successor to this node. More...
 
bool remove_successor (successor_type &r) __TBB_override
 Removes a successor from this node. More...
 
bool try_get (output_type &v) __TBB_override
 Request an item from the node. More...
 
bool try_reserve (output_type &v) __TBB_override
 Reserves an item. More...
 
bool try_release () __TBB_override
 Release a reserved item. More...
 
bool try_consume () __TBB_override
 Consumes a reserved item. More...
 
void activate ()
 Activates a node that was created in the inactive state. More...
 
template<typename Body >
Body copy_function_object ()
 
- Public Member Functions inherited from tbb::flow::interface10::graph_node
 graph_node (graph &g)
 
virtual ~graph_node ()
 
- Public Member Functions inherited from tbb::flow::interface10::internal::untyped_sender
virtual ~untyped_sender ()
 

Protected Member Functions

void reset_node (reset_flags f) __TBB_override
 resets the source_node to its initial state More...
 
- Protected Member Functions inherited from tbb::flow::interface10::sender< Output >
virtual bool try_get_wrapper (void *p, bool is_async) __TBB_override
 
virtual bool try_reserve_wrapper (void *p, bool is_async) __TBB_override
 
- Protected Member Functions inherited from tbb::flow::interface10::internal::untyped_sender
template<typename X >
bool try_get (X &t)
 Request an item from the sender. More...
 
template<typename X >
bool try_reserve (X &t)
 Reserves an item in the sender. More...
 

Private Member Functions

bool try_reserve_apply_body (output_type &v)
 
taskcreate_put_task ()
 
void spawn_put ()
 Spawns a task that applies the body. More...
 
taskapply_body_bypass ()
 Applies the body. Returning SUCCESSFULLY_ENQUEUED okay; forward_task_bypass will handle it. More...
 

Private Attributes

spin_mutex my_mutex
 
bool my_active
 
bool init_my_active
 
internal::source_body< output_type > * my_body
 
internal::source_body< output_type > * my_init_body
 
internal::broadcast_cache< output_typemy_successors
 
bool my_reserved
 
bool my_has_cached_item
 
output_type my_cached_item
 

Friends

class internal::source_task_bypass< source_node< output_type > >
 

Additional Inherited Members

- Protected Attributes inherited from tbb::flow::interface10::graph_node
graphmy_graph
 
graph_nodenext
 
graph_nodeprev
 

Detailed Description

template<typename Output>
class tbb::flow::interface10::source_node< Output >

An executable node that acts as a source, i.e. it has no predecessors.

Definition at line 861 of file flow_graph.h.

Member Typedef Documentation

◆ input_type

template<typename Output >
typedef null_type tbb::flow::interface10::source_node< Output >::input_type

Definition at line 870 of file flow_graph.h.

◆ output_type

template<typename Output >
typedef Output tbb::flow::interface10::source_node< Output >::output_type

The type of the output message, which is complete.

Definition at line 864 of file flow_graph.h.

◆ successor_type

template<typename Output >
typedef sender<output_type>::successor_type tbb::flow::interface10::source_node< Output >::successor_type

The type of successors of this node.

Definition at line 867 of file flow_graph.h.

Constructor & Destructor Documentation

◆ source_node() [1/2]

template<typename Output >
template<typename Body >
tbb::flow::interface10::source_node< Output >::source_node ( graph g,
Body  body,
bool  is_active = true 
)
inline

Constructor for a node with a successor.

Definition at line 879 of file flow_graph.h.

880  : graph_node(g), my_active(is_active), init_my_active(is_active),
883  my_reserved(false), my_has_cached_item(false)
884  {
885  my_successors.set_owner(this);
886  tbb::internal::fgt_node_with_body( tbb::internal::FLOW_SOURCE_NODE, &this->my_graph,
887  static_cast<sender<output_type> *>(this), this->my_body );
888  }
The leaf for source_body.
static void fgt_node_with_body(string_index, void *, void *, void *)
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
internal::source_body< output_type > * my_body
Definition: flow_graph.h:1054
internal::source_body< output_type > * my_init_body
Definition: flow_graph.h:1055

◆ source_node() [2/2]

template<typename Output >
tbb::flow::interface10::source_node< Output >::source_node ( const source_node< Output > &  src)
inline

Copy constructor.

Definition at line 891 of file flow_graph.h.

891  :
892  graph_node(src.my_graph), sender<Output>(),
893  my_active(src.init_my_active),
894  init_my_active(src.init_my_active), my_body( src.my_init_body->clone() ), my_init_body(src.my_init_body->clone() ),
895  my_reserved(false), my_has_cached_item(false)
896  {
897  my_successors.set_owner(this);
898  tbb::internal::fgt_node_with_body( tbb::internal::FLOW_SOURCE_NODE, &this->my_graph,
899  static_cast<sender<output_type> *>(this), this->my_body );
900  }
static void fgt_node_with_body(string_index, void *, void *, void *)
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
internal::source_body< output_type > * my_body
Definition: flow_graph.h:1054
internal::source_body< output_type > * my_init_body
Definition: flow_graph.h:1055

◆ ~source_node()

template<typename Output >
tbb::flow::interface10::source_node< Output >::~source_node ( )
inline

The destructor.

Definition at line 903 of file flow_graph.h.

903 { delete my_body; delete my_init_body; }
internal::source_body< output_type > * my_body
Definition: flow_graph.h:1054
internal::source_body< output_type > * my_init_body
Definition: flow_graph.h:1055

References tbb::flow::interface10::source_node< Output >::my_body, and tbb::flow::interface10::source_node< Output >::my_init_body.

Member Function Documentation

◆ activate()

template<typename Output >
void tbb::flow::interface10::source_node< Output >::activate ( )
inline

Activates a node that was created in the inactive state.

Definition at line 1009 of file flow_graph.h.

1009  {
1011  my_active = true;
1012  if (!my_successors.empty())
1013  spawn_put();
1014  }
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
void spawn_put()
Spawns a task that applies the body.
Definition: flow_graph.h:1094
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

◆ apply_body_bypass()

template<typename Output >
task* tbb::flow::interface10::source_node< Output >::apply_body_bypass ( )
inlineprivate

Applies the body. Returning SUCCESSFULLY_ENQUEUED okay; forward_task_bypass will handle it.

Definition at line 1102 of file flow_graph.h.

1102  {
1103  output_type v;
1104  if ( !try_reserve_apply_body(v) )
1105  return NULL;
1106 
1107  task *last_task = my_successors.try_put_task(v);
1108  if ( last_task )
1109  try_consume();
1110  else
1111  try_release();
1112  return last_task;
1113  }
bool try_release() __TBB_override
Release a reserved item.
Definition: flow_graph.h:987
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 * task
Output output_type
The type of the output message, which is complete.
Definition: flow_graph.h:864
bool try_consume() __TBB_override
Consumes a reserved item.
Definition: flow_graph.h:997
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
bool try_reserve_apply_body(output_type &v)
Definition: flow_graph.h:1062

References tbb::flow::interface10::source_node< Output >::my_successors, tbb::flow::interface10::source_node< Output >::try_consume(), tbb::flow::interface10::internal::broadcast_cache< T, M >::try_put_task(), tbb::flow::interface10::source_node< Output >::try_release(), and tbb::flow::interface10::source_node< Output >::try_reserve_apply_body().

Here is the call graph for this function:

◆ copy_function_object()

template<typename Output >
template<typename Body >
Body tbb::flow::interface10::source_node< Output >::copy_function_object ( )
inline

Definition at line 1017 of file flow_graph.h.

1017  {
1018  internal::source_body<output_type> &body_ref = *this->my_body;
1019  return dynamic_cast< internal::source_body_leaf<output_type, Body> & >(body_ref).get_body();
1020  }
The leaf for source_body.
internal::source_body< output_type > * my_body
Definition: flow_graph.h:1054
A functor that takes no input and generates a value of type Output.

◆ create_put_task()

template<typename Output >
task* tbb::flow::interface10::source_node< Output >::create_put_task ( )
inlineprivate

Definition at line 1088 of file flow_graph.h.

1088  {
1089  return ( new ( task::allocate_additional_child_of( *(this->my_graph.root_task()) ) )
1090  internal:: source_task_bypass < source_node< output_type > >( *this ) );
1091  }
tbb::task * root_task()
Returns the root task of the graph.

References tbb::flow::interface10::graph_node::my_graph, and tbb::flow::interface10::graph::root_task().

Referenced by tbb::flow::interface10::source_node< Output >::spawn_put().

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

◆ register_successor()

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::register_successor ( successor_type r)
inlinevirtual

Add a new successor to this node.

Implements tbb::flow::interface10::internal::untyped_sender.

Definition at line 912 of file flow_graph.h.

912  {
915  if ( my_active )
916  spawn_put();
917  return true;
918  }
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
void spawn_put()
Spawns a task that applies the body.
Definition: flow_graph.h:1094
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

References lock, tbb::flow::interface10::source_node< Output >::my_active, tbb::flow::interface10::source_node< Output >::my_mutex, tbb::flow::interface10::source_node< Output >::my_successors, tbb::flow::interface10::internal::successor_cache< T, M >::register_successor(), and tbb::flow::interface10::source_node< Output >::spawn_put().

Here is the call graph for this function:

◆ remove_successor()

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::remove_successor ( successor_type r)
inlinevirtual

Removes a successor from this node.

Implements tbb::flow::interface10::internal::untyped_sender.

Definition at line 921 of file flow_graph.h.

921  {
924  return true;
925  }
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

References lock, tbb::flow::interface10::source_node< Output >::my_mutex, tbb::flow::interface10::source_node< Output >::my_successors, and tbb::flow::interface10::internal::successor_cache< T, M >::remove_successor().

Here is the call graph for this function:

◆ reset_node()

template<typename Output >
void tbb::flow::interface10::source_node< Output >::reset_node ( reset_flags  f)
inlineprotectedvirtual

resets the source_node to its initial state

Implements tbb::flow::interface10::graph_node.

Definition at line 1034 of file flow_graph.h.

1034  {
1036  my_reserved =false;
1037  if(my_has_cached_item) {
1038  my_has_cached_item = false;
1039  }
1041  if(f & rf_reset_bodies) {
1043  delete my_body;
1044  my_body = tmp;
1045  }
1046  if(my_active)
1048  }
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
void add_task_to_graph_reset_list(graph &g, tbb::task *tp)
internal::source_body< output_type > * my_body
Definition: flow_graph.h:1054
A functor that takes no input and generates a value of type Output.
internal::source_body< output_type > * my_init_body
Definition: flow_graph.h:1055

References tbb::flow::interface10::internal::successor_cache< T, M >::clear(), tbb::flow::interface10::source_node< Output >::init_my_active, tbb::flow::interface10::source_node< Output >::my_active, tbb::flow::interface10::source_node< Output >::my_has_cached_item, tbb::flow::interface10::source_node< Output >::my_reserved, tbb::flow::interface10::source_node< Output >::my_successors, and tbb::flow::interface10::rf_clear_edges.

Here is the call graph for this function:

◆ spawn_put()

◆ try_consume()

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::try_consume ( )
inlinevirtual

Consumes a reserved item.

Reimplemented from tbb::flow::interface10::internal::untyped_sender.

Definition at line 997 of file flow_graph.h.

997  {
999  __TBB_ASSERT( my_reserved && my_has_cached_item, "consuming non-existent reservation" );
1000  my_reserved = false;
1001  my_has_cached_item = false;
1002  if ( !my_successors.empty() ) {
1003  spawn_put();
1004  }
1005  return true;
1006  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
void spawn_put()
Spawns a task that applies the body.
Definition: flow_graph.h:1094
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

References __TBB_ASSERT, tbb::flow::interface10::internal::successor_cache< T, M >::empty(), lock, tbb::flow::interface10::source_node< Output >::my_has_cached_item, tbb::flow::interface10::source_node< Output >::my_mutex, tbb::flow::interface10::source_node< Output >::my_reserved, tbb::flow::interface10::source_node< Output >::my_successors, and tbb::flow::interface10::source_node< Output >::spawn_put().

Referenced by tbb::flow::interface10::source_node< Output >::apply_body_bypass().

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

◆ try_get()

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::try_get ( output_type v)
inlinevirtual

Request an item from the node.

Reimplemented from tbb::flow::interface10::sender< Output >.

Definition at line 953 of file flow_graph.h.

953  {
955  if ( my_reserved )
956  return false;
957 
958  if ( my_has_cached_item ) {
959  v = my_cached_item;
960  my_has_cached_item = false;
961  return true;
962  }
963  // we've been asked to provide an item, but we have none. enqueue a task to
964  // provide one.
965  spawn_put();
966  return false;
967  }
void spawn_put()
Spawns a task that applies the body.
Definition: flow_graph.h:1094
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

References lock, and tbb::flow::interface10::source_node< Output >::my_mutex.

◆ try_release()

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::try_release ( )
inlinevirtual

Release a reserved item.

true = item has been released and so remains in sender, dest must request or reserve future items

Reimplemented from tbb::flow::interface10::internal::untyped_sender.

Definition at line 987 of file flow_graph.h.

987  {
989  __TBB_ASSERT( my_reserved && my_has_cached_item, "releasing non-existent reservation" );
990  my_reserved = false;
991  if(!my_successors.empty())
992  spawn_put();
993  return true;
994  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
internal::broadcast_cache< output_type > my_successors
Definition: flow_graph.h:1056
void spawn_put()
Spawns a task that applies the body.
Definition: flow_graph.h:1094
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

Referenced by tbb::flow::interface10::source_node< Output >::apply_body_bypass().

Here is the caller graph for this function:

◆ try_reserve()

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::try_reserve ( output_type v)
inlinevirtual

Reserves an item.

Reimplemented from tbb::flow::interface10::sender< Output >.

Definition at line 970 of file flow_graph.h.

970  {
972  if ( my_reserved ) {
973  return false;
974  }
975 
976  if ( my_has_cached_item ) {
977  v = my_cached_item;
978  my_reserved = true;
979  return true;
980  } else {
981  return false;
982  }
983  }
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

References lock, tbb::flow::interface10::source_node< Output >::my_mutex, and tbb::flow::interface10::source_node< Output >::my_reserved.

◆ try_reserve_apply_body()

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::try_reserve_apply_body ( output_type v)
inlineprivate

Definition at line 1062 of file flow_graph.h.

1062  {
1064  if ( my_reserved ) {
1065  return false;
1066  }
1067  if ( !my_has_cached_item ) {
1069  bool r = (*my_body)(my_cached_item);
1071  if (r) {
1072  my_has_cached_item = true;
1073  }
1074  }
1075  if ( my_has_cached_item ) {
1076  v = my_cached_item;
1077  my_reserved = true;
1078  return true;
1079  } else {
1080  return false;
1081  }
1082  }
static void fgt_end_body(void *)
internal::source_body< output_type > * my_body
Definition: flow_graph.h:1054
static void fgt_begin_body(void *)
friend class scoped_lock
Definition: spin_mutex.h:176
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 * lock

References lock, tbb::flow::interface10::source_node< Output >::my_mutex, and tbb::flow::interface10::source_node< Output >::my_reserved.

Referenced by tbb::flow::interface10::source_node< Output >::apply_body_bypass().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ internal::source_task_bypass< source_node< output_type > >

template<typename Output >
friend class internal::source_task_bypass< source_node< output_type > >
friend

Definition at line 1100 of file flow_graph.h.

Member Data Documentation

◆ init_my_active

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::init_my_active
private

◆ my_active

◆ my_body

◆ my_cached_item

template<typename Output >
output_type tbb::flow::interface10::source_node< Output >::my_cached_item
private

◆ my_has_cached_item

template<typename Output >
bool tbb::flow::interface10::source_node< Output >::my_has_cached_item
private

◆ my_init_body

template<typename Output >
internal::source_body<output_type>* tbb::flow::interface10::source_node< Output >::my_init_body
private

◆ my_mutex

◆ my_reserved

◆ my_successors


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.