Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::strict_ppl::concurrent_queue< T, A > Class Template Reference

A high-performance thread-safe non-blocking concurrent queue. More...

#include <concurrent_queue.h>

Inheritance diagram for tbb::strict_ppl::concurrent_queue< T, A >:
Collaboration diagram for tbb::strict_ppl::concurrent_queue< T, A >:

Public Types

typedef T value_type
 Element type in the queue. More...
 
typedef T & reference
 Reference type. More...
 
typedef const T & const_reference
 Const reference type. More...
 
typedef size_t size_type
 Integral type for representing size of the queue. More...
 
typedef ptrdiff_t difference_type
 Difference type for iterator. More...
 
typedef A allocator_type
 Allocator type. More...
 
typedef internal::concurrent_queue_iterator< concurrent_queue, T > iterator
 
typedef internal::concurrent_queue_iterator< concurrent_queue, const T > const_iterator
 

Public Member Functions

 concurrent_queue (const allocator_type &a=allocator_type())
 Construct empty queue. More...
 
template<typename InputIterator >
 concurrent_queue (InputIterator begin, InputIterator end, const allocator_type &a=allocator_type())
 [begin,end) constructor More...
 
 concurrent_queue (const concurrent_queue &src, const allocator_type &a=allocator_type())
 Copy constructor. More...
 
 concurrent_queue (concurrent_queue &&src)
 Move constructors. More...
 
 concurrent_queue (concurrent_queue &&src, const allocator_type &a)
 
 ~concurrent_queue ()
 Destroy queue. More...
 
void push (const T &source)
 Enqueue an item at tail of queue. More...
 
void push (T &&source)
 
template<typename... Arguments>
void emplace (Arguments &&... args)
 
bool try_pop (T &result)
 Attempt to dequeue an item from head of queue. More...
 
size_type unsafe_size () const
 Return the number of items in the queue; thread unsafe. More...
 
bool empty () const
 Equivalent to size()==0. More...
 
void clear ()
 Clear the queue. not thread-safe. More...
 
allocator_type get_allocator () const
 Return allocator object. More...
 
iterator unsafe_begin ()
 
iterator unsafe_end ()
 
const_iterator unsafe_begin () const
 
const_iterator unsafe_end () const
 

Private Types

typedef tbb::internal::allocator_rebind< A, char >::type page_allocator_type
 Allocator type. More...
 

Private Member Functions

virtual voidallocate_block (size_t n) __TBB_override
 Allocates a block of size n (bytes) More...
 
virtual void deallocate_block (void *b, size_t n) __TBB_override
 Deallocates block created by allocate_block. More...
 

Static Private Member Functions

static void copy_construct_item (T *location, const void *src)
 
static void move_construct_item (T *location, const void *src)
 

Private Attributes

page_allocator_type my_allocator
 

Friends

template<typename Container , typename Value >
class internal::concurrent_queue_iterator
 

Additional Inherited Members

- Protected Types inherited from tbb::strict_ppl::internal::concurrent_queue_base_v3< T >
typedef concurrent_queue_rep< T >::page page
 
- Protected Member Functions inherited from tbb::strict_ppl::internal::concurrent_queue_base_v3< T >
 concurrent_queue_base_v3 ()
 
virtual ~concurrent_queue_base_v3 ()
 
void internal_push (const void *src, item_constructor_t construct_item)
 Enqueue item at tail of queue. More...
 
bool internal_try_pop (void *dst)
 Attempt to dequeue item from queue. More...
 
size_t internal_size () const
 Get size of queue; result may be invalid if queue is modified concurrently. More...
 
bool internal_empty () const
 check if the queue is empty; thread safe More...
 
void internal_finish_clear ()
 free any remaining pages More...
 
void internal_throw_exception () const
 Obsolete. More...
 
void assign (const concurrent_queue_base_v3 &src, item_constructor_t construct_item)
 copy or move internal representation More...
 
void internal_swap (concurrent_queue_base_v3 &src)
 swap internal representation More...
 
- Protected Member Functions inherited from tbb::strict_ppl::internal::concurrent_queue_page_allocator
virtual ~concurrent_queue_page_allocator ()
 

Detailed Description

template<typename T, typename A = cache_aligned_allocator<T>>
class tbb::strict_ppl::concurrent_queue< T, A >

A high-performance thread-safe non-blocking concurrent queue.

Multiple threads may each push and pop concurrently. Assignment construction is not allowed.

Definition at line 35 of file concurrent_queue.h.

Member Typedef Documentation

◆ allocator_type

template<typename T , typename A = cache_aligned_allocator<T>>
typedef A tbb::strict_ppl::concurrent_queue< T, A >::allocator_type

Allocator type.

Definition at line 81 of file concurrent_queue.h.

◆ const_iterator

template<typename T , typename A = cache_aligned_allocator<T>>
typedef internal::concurrent_queue_iterator<concurrent_queue,const T> tbb::strict_ppl::concurrent_queue< T, A >::const_iterator

Definition at line 169 of file concurrent_queue.h.

◆ const_reference

template<typename T , typename A = cache_aligned_allocator<T>>
typedef const T& tbb::strict_ppl::concurrent_queue< T, A >::const_reference

Const reference type.

Definition at line 72 of file concurrent_queue.h.

◆ difference_type

template<typename T , typename A = cache_aligned_allocator<T>>
typedef ptrdiff_t tbb::strict_ppl::concurrent_queue< T, A >::difference_type

Difference type for iterator.

Definition at line 78 of file concurrent_queue.h.

◆ iterator

template<typename T , typename A = cache_aligned_allocator<T>>
typedef internal::concurrent_queue_iterator<concurrent_queue,T> tbb::strict_ppl::concurrent_queue< T, A >::iterator

Definition at line 168 of file concurrent_queue.h.

◆ page_allocator_type

template<typename T , typename A = cache_aligned_allocator<T>>
typedef tbb::internal::allocator_rebind<A, char>::type tbb::strict_ppl::concurrent_queue< T, A >::page_allocator_type
private

Allocator type.

Definition at line 39 of file concurrent_queue.h.

◆ reference

template<typename T , typename A = cache_aligned_allocator<T>>
typedef T& tbb::strict_ppl::concurrent_queue< T, A >::reference

Reference type.

Definition at line 69 of file concurrent_queue.h.

◆ size_type

template<typename T , typename A = cache_aligned_allocator<T>>
typedef size_t tbb::strict_ppl::concurrent_queue< T, A >::size_type

Integral type for representing size of the queue.

Definition at line 75 of file concurrent_queue.h.

◆ value_type

template<typename T , typename A = cache_aligned_allocator<T>>
typedef T tbb::strict_ppl::concurrent_queue< T, A >::value_type

Element type in the queue.

Definition at line 66 of file concurrent_queue.h.

Constructor & Destructor Documentation

◆ concurrent_queue() [1/5]

template<typename T , typename A = cache_aligned_allocator<T>>
tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue ( const allocator_type a = allocator_type())
inlineexplicit

Construct empty queue.

Definition at line 84 of file concurrent_queue.h.

84  :
85  my_allocator( a )
86  {
87  }

◆ concurrent_queue() [2/5]

template<typename T , typename A = cache_aligned_allocator<T>>
template<typename InputIterator >
tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue ( InputIterator  begin,
InputIterator  end,
const allocator_type a = allocator_type() 
)
inline

[begin,end) constructor

Definition at line 91 of file concurrent_queue.h.

91  :
92  my_allocator( a )
93  {
94  for( ; begin != end; ++begin )
95  this->push(*begin);
96  }
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp begin
void push(const T &source)
Enqueue an item at tail of queue.

References begin, end, and tbb::strict_ppl::concurrent_queue< T, A >::push().

Here is the call graph for this function:

◆ concurrent_queue() [3/5]

template<typename T , typename A = cache_aligned_allocator<T>>
tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue ( const concurrent_queue< T, A > &  src,
const allocator_type a = allocator_type() 
)
inline

Copy constructor.

Definition at line 99 of file concurrent_queue.h.

99  :
100  internal::concurrent_queue_base_v3<T>(), my_allocator( a )
101  {
102  this->assign( src, copy_construct_item );
103  }
static void copy_construct_item(T *location, const void *src)
void assign(const concurrent_queue_base_v3 &src, item_constructor_t construct_item)
copy or move internal representation

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::assign(), and tbb::strict_ppl::concurrent_queue< T, A >::copy_construct_item().

Here is the call graph for this function:

◆ concurrent_queue() [4/5]

template<typename T , typename A = cache_aligned_allocator<T>>
tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue ( concurrent_queue< T, A > &&  src)
inline

Move constructors.

Definition at line 107 of file concurrent_queue.h.

107  :
108  internal::concurrent_queue_base_v3<T>(), my_allocator( std::move(src.my_allocator) )
109  {
110  this->internal_swap( src );
111  }
void internal_swap(concurrent_queue_base_v3 &src)
swap internal representation
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319

◆ concurrent_queue() [5/5]

template<typename T , typename A = cache_aligned_allocator<T>>
tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue ( concurrent_queue< T, A > &&  src,
const allocator_type a 
)
inline

Definition at line 113 of file concurrent_queue.h.

113  :
114  internal::concurrent_queue_base_v3<T>(), my_allocator( a )
115  {
116  // checking that memory allocated by one instance of allocator can be deallocated
117  // with another
118  if( my_allocator == src.my_allocator) {
119  this->internal_swap( src );
120  } else {
121  // allocators are different => performing per-element move
122  this->assign( src, move_construct_item );
123  src.clear();
124  }
125  }
static void move_construct_item(T *location, const void *src)
void internal_swap(concurrent_queue_base_v3 &src)
swap internal representation
void assign(const concurrent_queue_base_v3 &src, item_constructor_t construct_item)
copy or move internal representation

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::assign(), tbb::strict_ppl::concurrent_queue< T, A >::clear(), tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_swap(), tbb::strict_ppl::concurrent_queue< T, A >::move_construct_item(), and tbb::strict_ppl::concurrent_queue< T, A >::my_allocator.

Here is the call graph for this function:

◆ ~concurrent_queue()

template<typename T , class A >
tbb::strict_ppl::concurrent_queue< T, A >::~concurrent_queue ( )

Destroy queue.

Definition at line 190 of file concurrent_queue.h.

190  {
191  clear();
192  this->internal_finish_clear();
193 }
void clear()
Clear the queue. not thread-safe.

Member Function Documentation

◆ allocate_block()

template<typename T , typename A = cache_aligned_allocator<T>>
virtual void* tbb::strict_ppl::concurrent_queue< T, A >::allocate_block ( size_t  n)
inlineprivatevirtual

Allocates a block of size n (bytes)

Implements tbb::strict_ppl::internal::concurrent_queue_base_v3< T >.

Definition at line 43 of file concurrent_queue.h.

43  {
44  void *b = reinterpret_cast<void*>(my_allocator.allocate( n ));
45  if( !b )
47  return b;
48  }
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()

References tbb::internal::eid_bad_alloc, tbb::strict_ppl::concurrent_queue< T, A >::my_allocator, and tbb::internal::throw_exception().

Here is the call graph for this function:

◆ clear()

template<typename T , class A >
void tbb::strict_ppl::concurrent_queue< T, A >::clear ( )

Clear the queue. not thread-safe.

Definition at line 196 of file concurrent_queue.h.

196  {
197  T value;
198  while( !empty() ) try_pop(value);
199 }
bool empty() const
Equivalent to size()==0.
bool try_pop(T &result)
Attempt to dequeue an item from head of queue.
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value

References value.

Referenced by tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue().

Here is the caller graph for this function:

◆ copy_construct_item()

template<typename T , typename A = cache_aligned_allocator<T>>
static void tbb::strict_ppl::concurrent_queue< T, A >::copy_construct_item ( T *  location,
const void src 
)
inlinestaticprivate

Definition at line 55 of file concurrent_queue.h.

55  {
56  new (location) T(*static_cast<const T*>(src));
57  }

Referenced by tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue(), and tbb::strict_ppl::concurrent_queue< T, A >::push().

Here is the caller graph for this function:

◆ deallocate_block()

template<typename T , typename A = cache_aligned_allocator<T>>
virtual void tbb::strict_ppl::concurrent_queue< T, A >::deallocate_block ( void b,
size_t  n 
)
inlineprivatevirtual

Deallocates block created by allocate_block.

Implements tbb::strict_ppl::internal::concurrent_queue_base_v3< T >.

Definition at line 51 of file concurrent_queue.h.

51  {
52  my_allocator.deallocate( reinterpret_cast<char*>(b), n );
53  }

References tbb::strict_ppl::concurrent_queue< T, A >::my_allocator.

◆ emplace()

template<typename T , typename A = cache_aligned_allocator<T>>
template<typename... Arguments>
void tbb::strict_ppl::concurrent_queue< T, A >::emplace ( Arguments &&...  args)
inline

Definition at line 143 of file concurrent_queue.h.

143  {
144  push( T(std::forward<Arguments>( args )...) );
145  }
void push(const T &source)
Enqueue an item at tail of queue.

References tbb::strict_ppl::concurrent_queue< T, A >::push().

Here is the call graph for this function:

◆ empty()

template<typename T , typename A = cache_aligned_allocator<T>>
bool tbb::strict_ppl::concurrent_queue< T, A >::empty ( ) const
inline

Equivalent to size()==0.

Definition at line 160 of file concurrent_queue.h.

160 {return this->internal_empty();}
bool internal_empty() const
check if the queue is empty; thread safe

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_empty().

Here is the call graph for this function:

◆ get_allocator()

template<typename T , typename A = cache_aligned_allocator<T>>
allocator_type tbb::strict_ppl::concurrent_queue< T, A >::get_allocator ( ) const
inline

Return allocator object.

Definition at line 166 of file concurrent_queue.h.

166 { return this->my_allocator; }

References tbb::strict_ppl::concurrent_queue< T, A >::my_allocator.

◆ move_construct_item()

template<typename T , typename A = cache_aligned_allocator<T>>
static void tbb::strict_ppl::concurrent_queue< T, A >::move_construct_item ( T *  location,
const void src 
)
inlinestaticprivate

Definition at line 60 of file concurrent_queue.h.

60  {
61  new (location) T( std::move(*static_cast<T*>(const_cast<void*>(src))) );
62  }
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319

References tbb::move().

Referenced by tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue(), and tbb::strict_ppl::concurrent_queue< T, A >::push().

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

◆ push() [1/2]

template<typename T , typename A = cache_aligned_allocator<T>>
void tbb::strict_ppl::concurrent_queue< T, A >::push ( const T &  source)
inline

Enqueue an item at tail of queue.

Definition at line 132 of file concurrent_queue.h.

132  {
133  this->internal_push( &source, copy_construct_item );
134  }
static void copy_construct_item(T *location, const void *src)
void internal_push(const void *src, item_constructor_t construct_item)
Enqueue item at tail of queue.

References tbb::strict_ppl::concurrent_queue< T, A >::copy_construct_item(), and tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_push().

Referenced by tbb::strict_ppl::concurrent_queue< T, A >::concurrent_queue(), and tbb::strict_ppl::concurrent_queue< T, A >::emplace().

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

◆ push() [2/2]

template<typename T , typename A = cache_aligned_allocator<T>>
void tbb::strict_ppl::concurrent_queue< T, A >::push ( T &&  source)
inline

Definition at line 137 of file concurrent_queue.h.

137  {
138  this->internal_push( &source, move_construct_item );
139  }
static void move_construct_item(T *location, const void *src)
void internal_push(const void *src, item_constructor_t construct_item)
Enqueue item at tail of queue.

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_push(), and tbb::strict_ppl::concurrent_queue< T, A >::move_construct_item().

Here is the call graph for this function:

◆ try_pop()

template<typename T , typename A = cache_aligned_allocator<T>>
bool tbb::strict_ppl::concurrent_queue< T, A >::try_pop ( T &  result)
inline

Attempt to dequeue an item from head of queue.

Does not wait for item to become available. Returns true if successful; false otherwise.

Definition at line 152 of file concurrent_queue.h.

152  {
153  return this->internal_try_pop( &result );
154  }
bool internal_try_pop(void *dst)
Attempt to dequeue item from queue.

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_try_pop().

Here is the call graph for this function:

◆ unsafe_begin() [1/2]

template<typename T , typename A = cache_aligned_allocator<T>>
iterator tbb::strict_ppl::concurrent_queue< T, A >::unsafe_begin ( )
inline

Definition at line 174 of file concurrent_queue.h.

174 {return iterator(*this);}
internal::concurrent_queue_iterator< concurrent_queue, T > iterator

◆ unsafe_begin() [2/2]

template<typename T , typename A = cache_aligned_allocator<T>>
const_iterator tbb::strict_ppl::concurrent_queue< T, A >::unsafe_begin ( ) const
inline

Definition at line 176 of file concurrent_queue.h.

176 {return const_iterator(*this);}
internal::concurrent_queue_iterator< concurrent_queue, const T > const_iterator

◆ unsafe_end() [1/2]

template<typename T , typename A = cache_aligned_allocator<T>>
iterator tbb::strict_ppl::concurrent_queue< T, A >::unsafe_end ( )
inline

Definition at line 175 of file concurrent_queue.h.

175 {return iterator();}
internal::concurrent_queue_iterator< concurrent_queue, T > iterator

◆ unsafe_end() [2/2]

template<typename T , typename A = cache_aligned_allocator<T>>
const_iterator tbb::strict_ppl::concurrent_queue< T, A >::unsafe_end ( ) const
inline

Definition at line 177 of file concurrent_queue.h.

177 {return const_iterator();}
internal::concurrent_queue_iterator< concurrent_queue, const T > const_iterator

◆ unsafe_size()

template<typename T , typename A = cache_aligned_allocator<T>>
size_type tbb::strict_ppl::concurrent_queue< T, A >::unsafe_size ( ) const
inline

Return the number of items in the queue; thread unsafe.

Definition at line 157 of file concurrent_queue.h.

157 {return this->internal_size();}
size_t internal_size() const
Get size of queue; result may be invalid if queue is modified concurrently.

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_size().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ internal::concurrent_queue_iterator

template<typename T , typename A = cache_aligned_allocator<T>>
template<typename Container , typename Value >
friend class internal::concurrent_queue_iterator
friend

Definition at line 36 of file concurrent_queue.h.

Member Data Documentation

◆ my_allocator


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.