Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
Loading...
Searching...
No Matches
tbb::flow::interface11::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::interface11::source_node< Output >:
Collaboration diagram for tbb::flow::interface11::source_node< Output >:

Public Types

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

Public Member Functions

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

Protected Member Functions

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

Private Member Functions

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

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

- Public Attributes inherited from tbb::flow::interface11::sender< Output >
__TBB_DEPRECATED typedef Output output_type
 The output type of this sender.
 
__TBB_DEPRECATED typedef internal::async_helpers< Output >::filtered_type filtered_type
 
- Protected Attributes inherited from tbb::flow::interface11::graph_node
graphmy_graph
 
graph_nodenext
 
graph_nodeprev
 

Detailed Description

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

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

Definition at line 1187 of file flow_graph.h.

Member Typedef Documentation

◆ input_type

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

Definition at line 1198 of file flow_graph.h.

◆ output_type

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

The type of the output message, which is complete.

Definition at line 1192 of file flow_graph.h.

◆ successor_type

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

The type of successors of this node.

Definition at line 1195 of file flow_graph.h.

Constructor & Destructor Documentation

◆ source_node() [1/2]

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

Constructor for a node with a successor.

Definition at line 1207 of file flow_graph.h.

1208 : graph_node(g), my_active(is_active), init_my_active(is_active),
1211 my_reserved(false), my_has_cached_item(false)
1212 {
1213 my_successors.set_owner(this);
1214 tbb::internal::fgt_node_with_body( CODEPTR(), tbb::internal::FLOW_SOURCE_NODE, &this->my_graph,
1215 static_cast<sender<output_type> *>(this), this->my_body );
1216 }
#define CODEPTR()
static void fgt_node_with_body(void *, string_index, void *, void *, void *)
internal::source_body< output_type > * my_init_body
internal::source_body< output_type > * my_body
internal::broadcast_cache< output_type > my_successors
The leaf for source_body.

References CODEPTR, and tbb::internal::fgt_node_with_body().

Here is the call graph for this function:

◆ source_node() [2/2]

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

Copy constructor.

Definition at line 1227 of file flow_graph.h.

1227 :
1228 graph_node(src.my_graph), sender<Output>(),
1229 my_active(src.init_my_active),
1230 init_my_active(src.init_my_active), my_body( src.my_init_body->clone() ), my_init_body(src.my_init_body->clone() ),
1231 my_reserved(false), my_has_cached_item(false)
1232 {
1233 my_successors.set_owner(this);
1234 tbb::internal::fgt_node_with_body(CODEPTR(), tbb::internal::FLOW_SOURCE_NODE, &this->my_graph,
1235 static_cast<sender<output_type> *>(this), this->my_body );
1236 }

References CODEPTR, and tbb::internal::fgt_node_with_body().

Here is the call graph for this function:

◆ ~source_node()

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

The destructor.

Definition at line 1239 of file flow_graph.h.

1239{ delete my_body; delete my_init_body; }

Member Function Documentation

◆ activate()

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

Activates a node that was created in the inactive state.

Definition at line 1345 of file flow_graph.h.

1345 {
1346 spin_mutex::scoped_lock lock(my_mutex);
1347 my_active = true;
1348 if (!my_successors.empty())
1349 spawn_put();
1350 }
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
void spawn_put()
Spawns a task that applies the body.

References lock.

◆ apply_body_bypass()

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

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

Definition at line 1438 of file flow_graph.h.

1438 {
1439 output_type v;
1440 if ( !try_reserve_apply_body(v) )
1441 return NULL;
1442
1443 task *last_task = my_successors.try_put_task(v);
1444 if ( last_task )
1445 try_consume();
1446 else
1447 try_release();
1448 return last_task;
1449 }
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
bool try_consume() __TBB_override
Consumes a reserved item.
bool try_reserve_apply_body(output_type &v)
Output output_type
The type of the output message, which is complete.
bool try_release() __TBB_override
Release a reserved item.

◆ copy_function_object()

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

Definition at line 1353 of file flow_graph.h.

1353 {
1355 return dynamic_cast< internal::source_body_leaf<output_type, Body> & >(body_ref).get_body();
1356 }

◆ create_put_task()

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

Definition at line 1424 of file flow_graph.h.

1424 {
1425 return ( new ( task::allocate_additional_child_of( *(this->my_graph.root_task()) ) )
1426 internal:: source_task_bypass < source_node< output_type > >( *this ) );
1427 }
__TBB_DEPRECATED tbb::task * root_task()
Returns the root task of the graph.

◆ register_successor()

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

Add a new successor to this node.

Implements tbb::flow::interface11::internal::untyped_sender.

Definition at line 1248 of file flow_graph.h.

1248 {
1249 spin_mutex::scoped_lock lock(my_mutex);
1250 my_successors.register_successor(r);
1251 if ( my_active )
1252 spawn_put();
1253 return true;
1254 }

References lock.

◆ remove_successor()

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

Removes a successor from this node.

Implements tbb::flow::interface11::internal::untyped_sender.

Definition at line 1257 of file flow_graph.h.

1257 {
1258 spin_mutex::scoped_lock lock(my_mutex);
1259 my_successors.remove_successor(r);
1260 return true;
1261 }

References lock.

◆ reset_node()

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

resets the source_node to its initial state

Implements tbb::flow::interface11::graph_node.

Definition at line 1370 of file flow_graph.h.

1370 {
1372 my_reserved =false;
1373 if(my_has_cached_item) {
1374 my_has_cached_item = false;
1375 }
1376 if(f & rf_clear_edges) my_successors.clear();
1377 if(f & rf_reset_bodies) {
1379 delete my_body;
1380 my_body = tmp;
1381 }
1382 if(my_active)
1384 }
void add_task_to_graph_reset_list(tbb::flow::interface10::graph &g, tbb::task *tp)
virtual source_body * clone()=0

References tbb::flow::interface11::internal::add_task_to_graph_reset_list(), internal::source_body< Output >::clone(), tbb::flow::interface11::rf_clear_edges, and tbb::flow::interface11::rf_reset_bodies.

Here is the call graph for this function:

◆ spawn_put()

template<typename Output >
void tbb::flow::interface11::source_node< Output >::spawn_put ( )
inlineprivate

Spawns a task that applies the body.

Definition at line 1430 of file flow_graph.h.

1430 {
1433 }
1434 }
void spawn_in_graph_arena(tbb::flow::interface10::graph &g, tbb::task &arena_task)
Spawns a task inside graph arena.
bool is_graph_active(tbb::flow::interface10::graph &g)

◆ try_consume()

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

Consumes a reserved item.

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

Definition at line 1333 of file flow_graph.h.

1333 {
1334 spin_mutex::scoped_lock lock(my_mutex);
1335 __TBB_ASSERT( my_reserved && my_has_cached_item, "consuming non-existent reservation" );
1336 my_reserved = false;
1337 my_has_cached_item = false;
1338 if ( !my_successors.empty() ) {
1339 spawn_put();
1340 }
1341 return true;
1342 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition tbb_stddef.h:165

References __TBB_ASSERT, and lock.

◆ try_get()

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

Request an item from the node.

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

Definition at line 1289 of file flow_graph.h.

1289 {
1290 spin_mutex::scoped_lock lock(my_mutex);
1291 if ( my_reserved )
1292 return false;
1293
1294 if ( my_has_cached_item ) {
1295 v = my_cached_item;
1296 my_has_cached_item = false;
1297 return true;
1298 }
1299 // we've been asked to provide an item, but we have none. enqueue a task to
1300 // provide one.
1301 spawn_put();
1302 return false;
1303 }

References lock.

◆ try_release()

template<typename Output >
bool tbb::flow::interface11::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::interface11::internal::untyped_sender.

Definition at line 1323 of file flow_graph.h.

1323 {
1324 spin_mutex::scoped_lock lock(my_mutex);
1325 __TBB_ASSERT( my_reserved && my_has_cached_item, "releasing non-existent reservation" );
1326 my_reserved = false;
1327 if(!my_successors.empty())
1328 spawn_put();
1329 return true;
1330 }

References __TBB_ASSERT, and lock.

◆ try_reserve()

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

Reserves an item.

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

Definition at line 1306 of file flow_graph.h.

1306 {
1307 spin_mutex::scoped_lock lock(my_mutex);
1308 if ( my_reserved ) {
1309 return false;
1310 }
1311
1312 if ( my_has_cached_item ) {
1313 v = my_cached_item;
1314 my_reserved = true;
1315 return true;
1316 } else {
1317 return false;
1318 }
1319 }

References lock.

◆ try_reserve_apply_body()

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

Definition at line 1398 of file flow_graph.h.

1398 {
1399 spin_mutex::scoped_lock lock(my_mutex);
1400 if ( my_reserved ) {
1401 return false;
1402 }
1403 if ( !my_has_cached_item ) {
1405 bool r = (*my_body)(my_cached_item);
1407 if (r) {
1408 my_has_cached_item = true;
1409 }
1410 }
1411 if ( my_has_cached_item ) {
1412 v = my_cached_item;
1413 my_reserved = true;
1414 return true;
1415 } else {
1416 return false;
1417 }
1418 }
static void fgt_begin_body(void *)
static void fgt_end_body(void *)

References tbb::internal::fgt_begin_body(), tbb::internal::fgt_end_body(), and lock.

Here is the call graph for this function:

Friends And Related Symbol 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 1430 of file flow_graph.h.

Member Data Documentation

◆ init_my_active

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

Definition at line 1389 of file flow_graph.h.

◆ my_active

template<typename Output >
bool tbb::flow::interface11::source_node< Output >::my_active
private

Definition at line 1388 of file flow_graph.h.

◆ my_body

template<typename Output >
internal::source_body<output_type>* tbb::flow::interface11::source_node< Output >::my_body
private

Definition at line 1390 of file flow_graph.h.

◆ my_cached_item

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

Definition at line 1395 of file flow_graph.h.

◆ my_has_cached_item

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

Definition at line 1394 of file flow_graph.h.

◆ my_init_body

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

Definition at line 1391 of file flow_graph.h.

◆ my_mutex

template<typename Output >
spin_mutex tbb::flow::interface11::source_node< Output >::my_mutex
private

Definition at line 1387 of file flow_graph.h.

◆ my_reserved

template<typename Output >
bool tbb::flow::interface11::source_node< Output >::my_reserved
private

Definition at line 1393 of file flow_graph.h.

◆ my_successors

template<typename Output >
internal::broadcast_cache< output_type > tbb::flow::interface11::source_node< Output >::my_successors
private

Definition at line 1392 of file flow_graph.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.