HTGS  v2.0
The Hybrid Task Graph Scheduler
htgs::Connector< T > Class Template Reference

Manages the input/output of IData between Tasks. More...

#include <htgs/core/graph/Connector.hpp>

Inheritance diagram for htgs::Connector< T >:
Inheritance graph
Collaboration diagram for htgs::Connector< T >:
Collaboration graph

Public Member Functions

 Connector ()
 Initializes the Connector with no producer tasks.
 
 ~Connector ()
 Destructor.
 
bool isInputTerminated () override
 Checks whether the producer for this Connector has finished pushing data onto its queue. More...
 
Connector< T > * copy () override
 Creates a copy of the BaseConnector. More...
 
void wakeupConsumer () override
 Awakens all Tasks that are consuming data from this connector. More...
 
void profileProduce (size_t numThreads) override
 Provide profile output for the produce operation. More...
 
void profileConsume (size_t numThreads, bool showQueueSize) override
 Provides profile output for the consume operation. More...
 
size_t getQueueSize () override
 Gets the size of the queue that this connector has in its data queue. More...
 
size_t getMaxQueueSize () override
 Gets the maximum queue size that this connector has in its data queue. More...
 
void resetMaxQueueSize () override
 Resets the max queue size profile.
 
void produceAnyData (std::shared_ptr< IData > data) override
 Produces any data into the queue. More...
 
std::shared_ptr< T > pollConsumeData (size_t timeout)
 Polls for data for a consumer given a timeout. More...
 
std::shared_ptr< T > consumeData ()
 Consumes data from the queue. More...
 
void produceData (std::shared_ptr< T > data)
 Produces data into the queue. More...
 
void produceData (std::list< std::shared_ptr< T >> *data)
 Produces a list of data adding each element into the queue. More...
 
std::string typeName () override
 Gets the demangled type name of the connector. More...
 
- Public Member Functions inherited from htgs::AnyConnector
 AnyConnector ()
 Constructor initializing the producer task count to 0.
 
virtual ~AnyConnector ()
 Virtual destructor.
 
void producerFinished ()
 Indicates to the Connector that the producer has finished producing data for the Connector. More...
 
size_t getProducerCount ()
 Gets the number of producers producing data for the connector. More...
 
void incrementInputTaskCount ()
 Increments the number of tasks producing data for the Connector. More...
 
std::string getDotId ()
 Gets the id used for dot graphs for GraphViz. More...
 
std::string genDot (int flags)
 Generates the dot representation for this connector. More...
 

Private Attributes

BlockingQueue< std::shared_ptr< T > > queue
 The blocking queue associated with the connector (thread safe) (can be switched to a priority queue using the USE_PRIORITY_QUEUE directive)
 

Detailed Description

template<class T>
class htgs::Connector< T >

Manages the input/output of IData between Tasks.

Each IData that is produced for the Connector is inserted based on the priority specified by the IData (lowest order value first by default IData::getOrder()).

Priority queue is enabled by defining the USE_PRIORITY_QUEUE directive during compilation.

The Connector manages how many Tasks are producing and consuming data for a particular Connector. For a given ITask, if that ITask has more than one thread associated with it, then each thread acts as a separate producer for the Connector. The Connector will not indicate it has finished producing data until all producers have indicated that they have finished.

If a data stream is producing data outside of a TaskGraphConf, then that stream must indicate it is an InputTask otherwise the ITask associated with this Connector may terminate prior to processing data. By incrementing the input task count, will ensure the Connector stays open for an ITask until the stream producing data indicates it has finished. To increment the input Task count use incrementInputTaskCount() and to indicate the input has finished producing data use producerFinished().

Template Parameters
Tthe input/output data type for the Connector, T must derive from IData.
Note
This class should only be called by the HTGS API
Enable priority queue by adding the USE_PRIORITY_QUEUE directive.

Member Function Documentation

◆ consumeData()

template<class T>
std::shared_ptr<T> htgs::Connector< T >::consumeData ( )
inline

Consumes data from the queue.

Returns
the data
Note
This function will block until data is available.

◆ copy()

template<class T>
Connector<T>* htgs::Connector< T >::copy ( )
inlineoverridevirtual

Creates a copy of the BaseConnector.

Returns
a copy of the BaseConnector
Note
This function should only be called by the HTGS API

Implements htgs::AnyConnector.

◆ getMaxQueueSize()

template<class T>
size_t htgs::Connector< T >::getMaxQueueSize ( )
inlineoverridevirtual

Gets the maximum queue size that this connector has in its data queue.

Returns
the maximum queue size for the connector

Implements htgs::AnyConnector.

◆ getQueueSize()

template<class T>
size_t htgs::Connector< T >::getQueueSize ( )
inlineoverridevirtual

Gets the size of the queue that this connector has in its data queue.

Returns
the size of the queue for the connector

Implements htgs::AnyConnector.

◆ isInputTerminated()

template<class T>
bool htgs::Connector< T >::isInputTerminated ( )
inlineoverridevirtual

Checks whether the producer for this Connector has finished pushing data onto its queue.

Returns
whether the input has terminated or not
Return values
TRUEif the input has terminated and no more data is in the queue.
FALSEif there is still data to be processed.

Implements htgs::AnyConnector.

◆ pollConsumeData()

template<class T>
std::shared_ptr<T> htgs::Connector< T >::pollConsumeData ( size_t  timeout)
inline

Polls for data for a consumer given a timeout.

Parameters
timeoutthe timeout time in microseconds
Returns
the data or nullptr
Return values
DATAthe next data that is on the queue
nullptrif the timeout time expires
Note
This function will block until data is available or the timeout time has expired.

◆ produceAnyData()

template<class T>
void htgs::Connector< T >::produceAnyData ( std::shared_ptr< IData data)
inlineoverridevirtual

Produces any data into the queue.

This function should be used with care as the data will be dynamically cast to the type of Connector.

Parameters
datathe data that will be added to the Connector's queue.

Implements htgs::AnyConnector.

◆ produceData() [1/2]

template<class T>
void htgs::Connector< T >::produceData ( std::shared_ptr< T >  data)
inline

Produces data into the queue.

Parameters
datathe data to be added

◆ produceData() [2/2]

template<class T>
void htgs::Connector< T >::produceData ( std::list< std::shared_ptr< T >> *  data)
inline

Produces a list of data adding each element into the queue.

Parameters
datathe list of data t obe added

◆ profileConsume()

template<class T>
void htgs::Connector< T >::profileConsume ( size_t  numThreads,
bool  showQueueSize 
)
inlineoverridevirtual

Provides profile output for the consume operation.

Parameters
numThreadsthe number of threads associated with consuming data
showQueueSizewhether to show the max queue size or not
Note
#define PROFILE to enable profiling

Implements htgs::AnyConnector.

◆ profileProduce()

template<class T>
void htgs::Connector< T >::profileProduce ( size_t  numThreads)
inlineoverridevirtual

Provide profile output for the produce operation.

Parameters
numThreadsthe number of threads associated with producing data
Note
#define PROFILE to enable profiling

Implements htgs::AnyConnector.

◆ typeName()

template<class T>
std::string htgs::Connector< T >::typeName ( )
inlineoverridevirtual

Gets the demangled type name of the connector.

Returns
the demangled type name

Implements htgs::AnyConnector.

◆ wakeupConsumer()

template<class T>
void htgs::Connector< T >::wakeupConsumer ( )
inlineoverridevirtual

Awakens all Tasks that are consuming data from this connector.

This function passes nullptr to each consumer to check whether that consumer is ready to be terminated.

Note
This function should only be called by the HTGS API

Implements htgs::AnyConnector.


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