21 #ifndef __TBB_concurrent_queue_H 22 #define __TBB_concurrent_queue_H 24 #include "internal/_concurrent_queue_impl.h" 28 namespace strict_ppl {
34 template<
typename T,
typename A = cache_aligned_allocator<T> >
36 template<
typename Container,
typename Value>
friend class internal::concurrent_queue_iterator;
39 typedef typename A::template rebind<char>::other page_allocator_type;
40 page_allocator_type my_allocator;
43 virtual void *allocate_block(
size_t n ) {
44 void *b =
reinterpret_cast<void*
>(my_allocator.allocate( n ));
46 internal::throw_exception(internal::eid_bad_alloc);
51 virtual void deallocate_block(
void *b,
size_t n ) {
52 my_allocator.deallocate( reinterpret_cast<char*>(b), n );
55 static void copy_construct_item(T* location,
const void* src){
56 new (location) T(*static_cast<const T*>(src));
59 #if __TBB_CPP11_RVALUE_REF_PRESENT 60 static void move_construct_item(T* location,
const void* src) {
61 new (location) T( std::move(*static_cast<T*>(const_cast<void*>(src))) );
90 template<
typename InputIterator>
94 for( ; begin != end; ++begin )
100 internal::concurrent_queue_base_v3<T>(), my_allocator( a )
102 this->assign( src, copy_construct_item );
105 #if __TBB_CPP11_RVALUE_REF_PRESENT 108 internal::concurrent_queue_base_v3<T>(), my_allocator( std::move(src.my_allocator) )
110 this->internal_swap( src );
114 internal::concurrent_queue_base_v3<T>(), my_allocator( a )
118 if( my_allocator == src.my_allocator) {
119 this->internal_swap( src );
122 this->assign( src, move_construct_item );
133 this->internal_push( &source, copy_construct_item );
136 #if __TBB_CPP11_RVALUE_REF_PRESENT 137 void push( T&& source ) {
138 this->internal_push( &source, move_construct_item );
141 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 142 template<
typename... Arguments>
143 void emplace( Arguments&&... args ) {
144 push( T(std::forward<Arguments>( args )...) );
146 #endif //__TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 153 return this->internal_try_pop( &result );
160 bool empty()
const {
return this->internal_empty();}
168 typedef internal::concurrent_queue_iterator<concurrent_queue,T> iterator;
169 typedef internal::concurrent_queue_iterator<concurrent_queue,const T> const_iterator;
174 iterator unsafe_begin() {
return iterator(*
this);}
175 iterator unsafe_end() {
return iterator();}
176 const_iterator unsafe_begin()
const {
return const_iterator(*
this);}
177 const_iterator unsafe_end()
const {
return const_iterator();}
180 template<
typename T,
class A>
183 this->internal_finish_clear();
186 template<
typename T,
class A>
200 template<
typename T,
class A = cache_aligned_allocator<T> >
202 template<
typename Container,
typename Value>
friend class internal::concurrent_queue_iterator;
205 typedef typename A::template rebind<char>::other page_allocator_type;
206 page_allocator_type my_allocator;
208 typedef typename concurrent_queue_base_v3::padded_page<T> padded_page;
209 typedef typename concurrent_queue_base_v3::copy_specifics copy_specifics;
212 class destroyer: internal::no_copy {
215 destroyer( T& value ) : my_value(value) {}
216 ~destroyer() {my_value.~T();}
219 T& get_ref( page& p,
size_t index ) {
220 __TBB_ASSERT( index<items_per_page, NULL );
221 return (&static_cast<padded_page*>(static_cast<void*>(&p))->last)[index];
224 virtual void copy_item( page& dst,
size_t index,
const void* src ) {
225 new( &get_ref(dst,index) ) T(*static_cast<const T*>(src));
228 #if __TBB_CPP11_RVALUE_REF_PRESENT 229 virtual void move_item( page& dst,
size_t index,
const void* src ) {
230 new( &get_ref(dst,index) ) T( std::move(*static_cast<T*>(const_cast<void*>(src))) );
233 virtual void move_item( page&,
size_t,
const void* ) {
234 __TBB_ASSERT(
false,
"Unreachable code" );
238 virtual void copy_page_item( page& dst,
size_t dindex,
const page& src,
size_t sindex ) {
239 new( &get_ref(dst,dindex) ) T( get_ref( const_cast<page&>(src), sindex ) );
242 #if __TBB_CPP11_RVALUE_REF_PRESENT 243 virtual void move_page_item( page& dst,
size_t dindex,
const page& src,
size_t sindex ) {
244 new( &get_ref(dst,dindex) ) T( std::move(get_ref( const_cast<page&>(src), sindex )) );
247 virtual void move_page_item( page&,
size_t,
const page&,
size_t ) {
248 __TBB_ASSERT(
false,
"Unreachable code" );
252 virtual void assign_and_destroy_item(
void* dst, page& src,
size_t index ) {
253 T& from = get_ref(src,index);
255 *
static_cast<T*
>(dst) = tbb::internal::move( from );
258 virtual page *allocate_page() {
259 size_t n =
sizeof(padded_page) + (items_per_page-1)*
sizeof(T);
260 page *p =
reinterpret_cast<page*
>(my_allocator.allocate( n ));
262 internal::throw_exception(internal::eid_bad_alloc);
266 virtual void deallocate_page( page *p ) {
267 size_t n =
sizeof(padded_page) + (items_per_page-1)*
sizeof(T);
268 my_allocator.deallocate( reinterpret_cast<char*>(p), n );
294 concurrent_queue_base_v8( sizeof(T) ), my_allocator( a )
300 : concurrent_queue_base_v8( sizeof(T) ), my_allocator( a )
305 #if __TBB_CPP11_RVALUE_REF_PRESENT 308 : concurrent_queue_base_v8(
sizeof(T) ), my_allocator( std::move(src.my_allocator) )
310 internal_swap( src );
314 : concurrent_queue_base_v8(
sizeof(T) ), my_allocator( a )
318 if( my_allocator == src.my_allocator) {
319 this->internal_swap( src );
322 this->move_content( src );
329 template<
typename InputIterator>
332 : concurrent_queue_base_v8( sizeof(T) ), my_allocator( a )
334 for( ; begin != end; ++begin )
335 internal_push_if_not_full(&*begin);
343 internal_push( &source );
346 #if __TBB_CPP11_RVALUE_REF_PRESENT 347 void push( T&& source ) {
349 internal_push_move( &source );
352 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 353 template<
typename... Arguments>
354 void emplace( Arguments&&... args ) {
355 push( T(std::forward<Arguments>( args )...) );
362 void pop( T& destination ) {
363 internal_pop( &destination );
366 #if TBB_USE_EXCEPTIONS 377 return internal_push_if_not_full( &source );
380 #if __TBB_CPP11_RVALUE_REF_PRESENT 384 bool try_push( T&& source ) {
385 return internal_push_move_if_not_full( &source );
387 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 388 template<
typename... Arguments>
389 bool try_emplace( Arguments&&... args ) {
390 return try_push( T(std::forward<Arguments>( args )...) );
399 return internal_pop_if_present( &destination );
406 size_type
size()
const {
return internal_size();}
409 bool empty()
const {
return internal_empty();}
420 internal_set_capacity( new_capacity,
sizeof(T) );
429 typedef internal::concurrent_queue_iterator<concurrent_bounded_queue,T> iterator;
430 typedef internal::concurrent_queue_iterator<concurrent_bounded_queue,const T> const_iterator;
435 iterator unsafe_begin() {
return iterator(*
this);}
436 iterator unsafe_end() {
return iterator();}
437 const_iterator unsafe_begin()
const {
return const_iterator(*
this);}
438 const_iterator unsafe_end()
const {
return const_iterator();}
442 template<
typename T,
class A>
445 internal_finish_clear();
448 template<
typename T,
class A>
std::ptrdiff_t size_type
Integral type for representing size of the queue.
Definition: concurrent_queue.h:287
size_type unsafe_size() const
Return the number of items in the queue; thread unsafe.
Definition: concurrent_queue.h:157
T & reference
Reference type.
Definition: concurrent_queue.h:279
concurrent_queue(InputIterator begin, InputIterator end, const allocator_type &a=allocator_type())
[begin,end) constructor
Definition: concurrent_queue.h:91
size_type size() const
Return number of pushes minus number of pops.
Definition: concurrent_queue.h:406
~concurrent_queue()
Destroy queue.
Definition: concurrent_queue.h:181
concurrent_queue(const allocator_type &a=allocator_type())
Construct empty queue.
Definition: concurrent_queue.h:84
concurrent_bounded_queue(InputIterator begin, InputIterator end, const allocator_type &a=allocator_type())
[begin,end) constructor
Definition: concurrent_queue.h:330
void set_capacity(size_type new_capacity)
Set the capacity.
Definition: concurrent_queue.h:419
concurrent_bounded_queue(const concurrent_bounded_queue &src, const allocator_type &a=allocator_type())
Copy constructor.
Definition: concurrent_queue.h:299
void pop(T &destination)
Dequeue item from head of queue.
Definition: concurrent_queue.h:362
T & reference
Reference type.
Definition: concurrent_queue.h:69
std::ptrdiff_t difference_type
Difference type for iterator.
Definition: concurrent_queue.h:290
void push(const T &source)
Enqueue an item at tail of queue.
Definition: concurrent_queue.h:132
concurrent_bounded_queue(const allocator_type &a=allocator_type())
Construct empty queue.
Definition: concurrent_queue.h:293
A allocator_type
Allocator type.
Definition: concurrent_queue.h:81
const T & const_reference
Const reference type.
Definition: concurrent_queue.h:282
T value_type
Element type in the queue.
Definition: concurrent_queue.h:273
const T & const_reference
Const reference type.
Definition: concurrent_queue.h:72
allocator_type get_allocator() const
Return allocator object.
Definition: concurrent_queue.h:166
A allocator_type
Allocator type.
Definition: concurrent_queue.h:276
~concurrent_bounded_queue()
Destroy queue.
Definition: concurrent_queue.h:443
void push(const T &source)
Enqueue an item at tail of queue.
Definition: concurrent_queue.h:342
ptrdiff_t difference_type
Difference type for iterator.
Definition: concurrent_queue.h:78
A high-performance thread-safe non-blocking concurrent queue.
Definition: concurrent_queue.h:35
T value_type
Element type in the queue.
Definition: concurrent_queue.h:66
bool try_pop(T &destination)
Attempt to dequeue an item from head of queue.
Definition: concurrent_queue.h:398
bool empty() const
Equivalent to size()==0.
Definition: concurrent_queue.h:160
void clear()
clear the queue. not thread-safe.
Definition: concurrent_queue.h:449
concurrent_queue(const concurrent_queue &src, const allocator_type &a=allocator_type())
Copy constructor.
Definition: concurrent_queue.h:99
Definition: _flow_graph_async_msg_impl.h:32
bool try_push(const T &source)
Enqueue an item at tail of queue if queue is not already full.
Definition: concurrent_queue.h:376
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
size_type capacity() const
Maximum number of allowed elements.
Definition: concurrent_queue.h:412
A high-performance thread-safe blocking concurrent bounded queue.
Definition: concurrent_queue.h:201
bool empty() const
Equivalent to size()<=0.
Definition: concurrent_queue.h:409
allocator_type get_allocator() const
return allocator object
Definition: concurrent_queue.h:424
size_t size_type
Integral type for representing size of the queue.
Definition: concurrent_queue.h:75
void clear()
Clear the queue. not thread-safe.
Definition: concurrent_queue.h:187
bool try_pop(T &result)
Attempt to dequeue an item from head of queue.
Definition: concurrent_queue.h:152