並列操作を含む制限付きのデュアルキュー用のテンプレート・クラス。
template<typename T, class Alloc=cache_aligned_allocator<T> >
class concurrent_bounded_queue;
#include "tbb/concurrent_queue.h"
concurrent_bounded_queue は、concurrent_queue に似ていますが、次のような相違点があります。
キューの大きさを指定することができます。デフォルトの大きさは、キューを実際には無制限にします。
push 操作を変更し、キューの大きさを超えずに完了できるようになるまで待機します。
アイテムをポップできるようになるまで待機する pop 操作があります。
size_type を符号付き の型に変更します。
プッシュ操作の数からポップ操作の数を引いた値を返すように、size() 操作を変更します。例えば、空のキューで 3 つのポップ操作が待機している場合、size() は -3 を返します。
比較しやすいように、concurrent_queue と異なる部分を太字で示します。
namespace tbb {
template<typename T, typename A=cache_aligned_allocator<T> >
class concurrent_bounded_queue {
public:
// 型
typedef T value_type;
typedef A allocator_type;
typedef T& reference;
typedef const T& const_reference;
// size_type は符号付きの型
typedef std::ptrdiff_t size_type;
typedef std::ptrdiff_t difference_type;
explicit concurrent_bounded_queue(const allocator_type& a = allocator_type());
concurrent_bounded_queue( const concurrent_bounded_queue& src, const allocator_type& a = allocator_type());
template<typename InputIterator>
concurrent_bounded_queue( InputIterator begin, InputIterator end, const allocator_type& a = allocator_type());
// C++11 仕様
concurrent_bounded_queue( concurrent_bounded_queue&& src );
concurrent_bounded_queue( concurrent_bounded_queue&& src, const allocator_type& a );
~concurrent_bounded_queue();
// キャパシティーを超えないで push できるまで待つ
void push( const T& source );
// *this が空の場合は待つ
void pop( T& destination );
// C++11 仕様
void push( T&& source );
// アイテムが指定された引数で構築される点を除いて push と同じ
template<typename... Arguments>
void emplace(Arguments&&... args);
// キャパシティーを超える場合は push をスキップ
bool try_push( const T& source );
bool try_pop( T& destination );
// C++11 仕様
bool try_push( T&& source );
// アイテムが指定された引数で構築される点を除いて try_push と同じ
template<typename... Arguments>
bool try_emplace(Arguments&&... args);
void abort();
void clear();
// 並列修正中の呼び出しは安全で負のサイズを返す
size_type size() const;
bool empty() const;
size_type capacity() const;
void set_capacity( size_type capacity );
allocator_type get_allocator() const;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
// イテレーター (低速、デバッグ用)
iterator unsafe_begin();
iterator unsafe_end();
const_iterator unsafe_begin() const;
const_iterator unsafe_end() const;
};
}
| メンバー | 説明 |
|---|---|
| void push( const T& source ) |
size()<capacity になるまで待ってから、source のコピーをキューにプッシュします。 |
| void push( T&& source) |
C++11 仕様。size()<capacity になるまで待ってから、source をキューに移動します。 |
| template<typename... Arguments> void emplace(Arguments&&... args); |
C++11 仕様。size()<capacity になるまで待ってから、新しい要素をキューにプッシュします。要素は指定された引数で構築されます。 |
| void pop( T& destination ) |
値が利用可能になるまで待ち、値をキューからポップします。値を destination に代入し、オリジナルの値を破棄します。 |
| void abort() |
push 操作および pop 操作により待機中のスレッドをウェイクアップし、それらのスレッドで tbb::user_abort 例外をスローします。この機能は、TBB_USE_EXCEPTIONS が設定されていない場合、利用できません。 |
| bool try_push( const T& source ) |
size()<capacity の場合、source のコピーをキューにプッシュします。 戻り値: コピーがプッシュされた場合は true、その他の場合は false。 |
| bool try_push( T&& source ) |
C++11 仕様。size()<capacity の場合、source をキューに移動します。 戻り値: アイテムが移動された場合は true、その他の場合は false。 |
| template<typename... Arguments> bool try_emplace(Arguments&&... args); |
C++11 仕様。size()<capacity の場合、指定された引数でアイテムを構築してアイテムをキューに移動します。 戻り値: アイテムが移動された場合は true、その他の場合は false。 |
| bool try_pop( T& destination ) |
値が利用可能な場合、値をキューからポップして、destination に代入し、オリジナルの値を破棄します。その他の場合は、何もしません。 戻り値: 値がポップされた場合は true、その他の場合は false。 |
| size_type size() const |
戻り値: プッシュの数からポップの数を引いた数を返します。対応するプッシュを待っているポップ操作がある場合、結果は負です。キューが一杯で、対応するポップを待っているプッシュ操作がある場合、結果は capacity() を超えることがあります。 |
| bool empty() const |
戻り値: size()<=0 |
| size_type capacity() const |
戻り値: キューが保持できる値の最大数。 |
| void set_capacity( size_type capacity ) |
キューが保持できる値の最大数を設定します。 |