overwrite_node テンプレート・クラス

概要

graph_nodereceiver<Input>sender<Output> のテンプレート・クラス。overwrite_node は、上書き可能な 1 つのアイテムのバッファーを表します。

構文

template < typename T > class overwrite_node;

ヘッダー

#include "tbb/flow_graph.h"

説明

このノードは、T 型の 1 つのアイテムをバッファーに格納します。値は最初は無効です。try_put は、内部バッファーの値を設定して、新しい値をすべてのサクセサーにブロードキャストします。ノードから取得した値は破棄されません。内部バッファーの値が有効な場合、try_gettrue を返し、バッファーの値を出力にコピーします。内部バッファーの値が無効な場合、try_getfalse を返します。

サクセサーがメッセージを拒否した場合、「メッセージ・パッシング・プロトコル」で説明されているプロトコルを使用して処理されます。

T は、コピー構築可能および代入可能でなければなりません。

サンプル

overwrite_node を更新される可能性がある単一の値のストレージとして使用します。データには、直接 try_get() を呼び出してアクセスできます。また、reserving join_node を利用して間接的な pull ベースでデータを取得するため、node reservation プレビュー機能を使用することもできます。

#include "tbb/flow_graph.h"
#include <chrono>
#include <thread>

int main() {
    const int data_limit = 20;
    int count = 0;

    tbb::flow::graph g;
 
    tbb::flow::function_node< int, int > data_set_preparation(g, tbb::flow::unlimited, []( int data ) {
        printf("Prepare large data set and keep it inside node storage\n");
        return data;
    });
 
    tbb::flow::overwrite_node< int > overwrite_storage(g);
 
    tbb::flow::source_node<int> data_generator(g, [&]( int& v ) -> bool {
        if ( count < data_limit ) {
            ++count;
            v = count;
            return true;
        } else {
            return false;
        }
    }, false);
 
    tbb::flow::function_node< int > process(g, tbb::flow::unlimited, [&]( const int& data) {
        int data_from_storage = 0;
        overwrite_storage.try_get(data_from_storage);
        printf("Data from a storage: %d\n", data_from_storage);
        printf("Data to process: %d\n", data);
    });
 
    tbb::flow::make_edge(data_set_preparation, overwrite_storage);
    tbb::flow::make_edge(data_generator, process);
 
    data_set_preparation.try_put(1);
    data_generator.activate();
 
    g.wait_for_all();

    return 0;
}

メンバー

namespace tbb {
namespace flow {

template< typename T >
class overwrite_node :
  public graph_node, public receiver<T>,
  public sender<T> {
public:
    explicit overwrite_node( graph &g );
    overwrite_node( const overwrite_node &src );
    ~overwrite_node();

    // receiver<T>
    typedef T input_type;
    typedef sender<input_type> predecessor_type;
    bool try_put( const input_type &v );
    bool register_predecessor( predecessor_type &p );
    bool remove_predecessor( predecessor_type &p );

    // sender<T>
    typedef T output_type;
    typedef receiver<output_type> successor_type;
    bool register_successor( successor_type &r );
    bool remove_successor( successor_type &r );
    bool try_get( output_type &v );
    bool try_reserve( output_type &v );
    bool try_release( );
    bool try_consume( );

    bool is_valid( );
    void clear( );
};

}
}
次の表は、このテンプレート・クラスのメンバーの詳細な情報を提供します。
メンバー 説明
explicit overwrite_node( graph &g )

無効な内部バッファーアイテムを含む overwrite_node 型のオブジェクトを構築します。

overwrite_node( const overwrite_node &src )

無効な内部バッファーアイテムを含む graph g に属する overwrite_node 型のオブジェクトを構築します。バッファーに格納される値とサクセサーのリストは src からコピーされません。

~overwrite_node( )

overwrite_node を破棄します。

bool try_put( const input_type &v )

内部の 1 アイテムのバッファーに v を格納し、すべてのサクセサーで try_put(v) を呼び出します。

戻り値: true

bool register_predecessor( predecessor_type &p )

値を拒否しないため、プレデセッサーのリストを維持する必要はありません。

戻り値: false

bool remove_predecessor( predecessor_type &p )

値を拒否しないため、プレデセッサーのリストを維持する必要はありません。

戻り値: false

bool register_successor( successor_type &r )

サクセサーのセットに r を追加します。バッファーに有効なアイテム v が格納されている場合、r.try_put(v) を呼び出すタスクがスポーンされます。

戻り値: true
bool remove_successor( successor_type &r )

サクセサーのセットから r を削除します。

戻り値: true

bool try_get( output_type &v )

内部バッファーが有効な場合、値を v に代入します。

戻り値: v が代入された場合は truev が代入されなかった場合は false

bool try_reserve( output_type &v )

予約をサポートしません。

戻り値: false

bool try_release( output_type &v )

予約をサポートしません。

戻り値: false

bool try_consume( output_type &v )

予約をサポートしません。

戻り値: false

bool is_valid( )

戻り値: バッファーが有効な値を保持している場合は true。その他の場合は false

void clear( )

バッファーで保持されている値を無効にします。

関連情報