Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
tbb::strict_ppl::internal::concurrent_queue_base_v3< T > Class Template Referenceabstract

base class of concurrent_queue More...

#include <_concurrent_queue_impl.h>

Inheritance diagram for tbb::strict_ppl::internal::concurrent_queue_base_v3< T >:
Collaboration diagram for tbb::strict_ppl::internal::concurrent_queue_base_v3< T >:

Protected Types

typedef concurrent_queue_rep< T >::page page
 

Protected Member Functions

 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 ()
 

Private Types

typedef micro_queue< T >::padded_page padded_page
 
typedef micro_queue< T >::item_constructor_t item_constructor_t
 

Private Member Functions

virtual pageallocate_page () __TBB_override
 
virtual void deallocate_page (concurrent_queue_rep_base::page *p) __TBB_override
 
virtual voidallocate_block (size_t n)=0
 custom allocator More...
 
virtual void deallocate_block (void *p, size_t n)=0
 custom de-allocator More...
 

Private Attributes

concurrent_queue_rep< T > * my_rep
 Internal representation. More...
 

Friends

struct concurrent_queue_rep< T >
 
class micro_queue< T >
 
class concurrent_queue_iterator_rep< T >
 
class concurrent_queue_iterator_base_v3< T >
 

Detailed Description

template<typename T>
class tbb::strict_ppl::internal::concurrent_queue_base_v3< T >

base class of concurrent_queue

The class implements the interface defined by concurrent_queue_page_allocator and has a pointer to an instance of concurrent_queue_rep.

Definition at line 421 of file _concurrent_queue_impl.h.

Member Typedef Documentation

◆ item_constructor_t

template<typename T >
typedef micro_queue<T>::item_constructor_t tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::item_constructor_t
private

Definition at line 436 of file _concurrent_queue_impl.h.

◆ padded_page

template<typename T >
typedef micro_queue<T>::padded_page tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::padded_page
private

Definition at line 435 of file _concurrent_queue_impl.h.

◆ page

template<typename T >
typedef concurrent_queue_rep<T>::page tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::page
protected

Definition at line 432 of file _concurrent_queue_impl.h.

Constructor & Destructor Documentation

◆ concurrent_queue_base_v3()

Definition at line 506 of file _concurrent_queue_impl.h.

506 {
507 const size_t item_size = sizeof(T);
508 my_rep = cache_aligned_allocator<concurrent_queue_rep<T> >().allocate(1);
509 __TBB_ASSERT( (size_t)my_rep % NFS_GetLineSize()==0, "alignment error" );
510 __TBB_ASSERT( (size_t)&my_rep->head_counter % NFS_GetLineSize()==0, "alignment error" );
511 __TBB_ASSERT( (size_t)&my_rep->tail_counter % NFS_GetLineSize()==0, "alignment error" );
512 __TBB_ASSERT( (size_t)&my_rep->array % NFS_GetLineSize()==0, "alignment error" );
513 memset(static_cast<void*>(my_rep),0,sizeof(concurrent_queue_rep<T>));
514 my_rep->item_size = item_size;
515 my_rep->items_per_page = item_size<= 8 ? 32 :
516 item_size<= 16 ? 16 :
517 item_size<= 32 ? 8 :
518 item_size<= 64 ? 4 :
519 item_size<=128 ? 2 :
520 1;
521}
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
size_t __TBB_EXPORTED_FUNC NFS_GetLineSize()
Cache/sector line size.
concurrent_queue_rep< T > * my_rep
Internal representation.
Internal representation of a ConcurrentQueue.

References __TBB_ASSERT, and tbb::internal::NFS_GetLineSize().

Here is the call graph for this function:

◆ ~concurrent_queue_base_v3()

template<typename T >
virtual tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::~concurrent_queue_base_v3 ( )
inlineprotectedvirtual

Definition at line 459 of file _concurrent_queue_impl.h.

459 {
460#if TBB_USE_ASSERT
461 size_t nq = my_rep->n_queue;
462 for( size_t i=0; i<nq; i++ )
463 __TBB_ASSERT( my_rep->array[i].tail_page==NULL, "pages were not freed properly" );
464#endif /* TBB_USE_ASSERT */
465 cache_aligned_allocator<concurrent_queue_rep<T> >().deallocate(my_rep,1);
466 }

References __TBB_ASSERT, and tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::my_rep.

Member Function Documentation

◆ allocate_block()

template<typename T >
virtual void * tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::allocate_block ( size_t  n)
privatepure virtual

custom allocator

Implemented in tbb::strict_ppl::concurrent_queue< T, A >.

Referenced by tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::allocate_page().

Here is the caller graph for this function:

◆ allocate_page()

template<typename T >
virtual page * tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::allocate_page ( )
inlineprivatevirtual

◆ assign()

template<typename T >
void tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::assign ( const concurrent_queue_base_v3< T > &  src,
item_constructor_t  construct_item 
)
protected

copy or move internal representation

Definition at line 589 of file _concurrent_queue_impl.h.

591{
593 r.items_per_page = src.my_rep->items_per_page;
594
595 // copy concurrent_queue_rep data
599
600 // copy or move micro_queues
601 for( size_t i = 0; i < r.n_queue; ++i )
602 r.array[i].assign( src.my_rep->array[i], *this, construct_item);
603
605 "the source concurrent queue should not be concurrently modified." );
606}
concurrent_queue_rep * my_rep
Internal representation.
micro_queue & assign(const micro_queue &src, concurrent_queue_base &base, concurrent_queue_base::copy_specifics op_type)
static const size_t n_queue
Must be power of 2.

References __TBB_ASSERT, tbb::strict_ppl::internal::concurrent_queue_rep< T >::array, tbb::strict_ppl::internal::concurrent_queue_rep_base::head_counter, tbb::strict_ppl::internal::concurrent_queue_rep_base::items_per_page, tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::my_rep, tbb::strict_ppl::internal::concurrent_queue_rep_base::n_invalid_entries, tbb::strict_ppl::internal::concurrent_queue_rep_base::n_queue, and tbb::strict_ppl::internal::concurrent_queue_rep_base::tail_counter.

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

Here is the caller graph for this function:

◆ deallocate_block()

template<typename T >
virtual void tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::deallocate_block ( void p,
size_t  n 
)
privatepure virtual

custom de-allocator

Implemented in tbb::strict_ppl::concurrent_queue< T, A >.

Referenced by tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::deallocate_page().

Here is the caller graph for this function:

◆ deallocate_page()

template<typename T >
virtual void tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::deallocate_page ( concurrent_queue_rep_base::page p)
inlineprivatevirtual

Implements tbb::strict_ppl::internal::concurrent_queue_page_allocator.

Definition at line 444 of file _concurrent_queue_impl.h.

444 {
446 size_t n = sizeof(padded_page) + (r.items_per_page-1)*sizeof(T);
447 deallocate_block( reinterpret_cast<void*>(p), n );
448 }
void const char const char int ITT_FORMAT __itt_group_sync p
virtual void deallocate_block(void *p, size_t n)=0
custom de-allocator

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::deallocate_block(), tbb::strict_ppl::internal::concurrent_queue_rep_base::items_per_page, tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::my_rep, and p.

Here is the call graph for this function:

◆ internal_empty()

template<typename T >
bool tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_empty
protected

check if the queue is empty; thread safe

Definition at line 565 of file _concurrent_queue_impl.h.

565 {
567 ticket tc = r.tail_counter;
568 ticket hc = r.head_counter;
569 // if tc!=r.tail_counter, the queue was not empty at some point between the two reads.
570 return tc==r.tail_counter && tc==hc+r.n_invalid_entries ;
571}

References tbb::strict_ppl::internal::concurrent_queue_rep_base::head_counter, tbb::strict_ppl::internal::concurrent_queue_rep_base::n_invalid_entries, and tbb::strict_ppl::internal::concurrent_queue_rep_base::tail_counter.

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

Here is the caller graph for this function:

◆ internal_finish_clear()

template<typename T >
void tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_finish_clear
protected

free any remaining pages

Definition at line 574 of file _concurrent_queue_impl.h.

574 {
576 size_t nq = r.n_queue;
577 for( size_t i=0; i<nq; ++i ) {
578 page* tp = r.array[i].tail_page;
579 if( is_valid_page(tp) ) {
580 __TBB_ASSERT( r.array[i].head_page==tp, "at most one page should remain" );
581 deallocate_page( tp );
582 r.array[i].tail_page = NULL;
583 } else
584 __TBB_ASSERT( !is_valid_page(r.array[i].head_page), "head page pointer corrupt?" );
585 }
586}
bool is_valid_page(const concurrent_queue_rep_base::page *p)
virtual void deallocate_page(concurrent_queue_rep_base::page *p) __TBB_override

References __TBB_ASSERT, tbb::strict_ppl::internal::concurrent_queue_rep< T >::array, tbb::strict_ppl::internal::is_valid_page(), and tbb::strict_ppl::internal::concurrent_queue_rep_base::n_queue.

Here is the call graph for this function:

◆ internal_push()

template<typename T >
void tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_push ( const void src,
item_constructor_t  construct_item 
)
inlineprotected

Enqueue item at tail of queue.

Definition at line 469 of file _concurrent_queue_impl.h.

469 {
471 ticket k = r.tail_counter++;
472 r.choose(k).push( src, k, *this, construct_item );
473 }
void push(const void *item, ticket k, concurrent_queue_base &base, concurrent_queue_base::copy_specifics op_type)

References tbb::strict_ppl::internal::concurrent_queue_rep< T >::choose(), tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::my_rep, and tbb::strict_ppl::internal::concurrent_queue_rep_base::tail_counter.

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

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

◆ internal_size()

template<typename T >
size_t tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_size
protected

Get size of queue; result may be invalid if queue is modified concurrently.

Definition at line 553 of file _concurrent_queue_impl.h.

553 {
555 __TBB_ASSERT( sizeof(ptrdiff_t)<=sizeof(size_t), NULL );
556 ticket hc = r.head_counter;
557 size_t nie = r.n_invalid_entries;
558 ticket tc = r.tail_counter;
559 __TBB_ASSERT( hc!=tc || !nie, NULL );
560 ptrdiff_t sz = tc-hc-nie;
561 return sz<0 ? 0 : size_t(sz);
562}

References __TBB_ASSERT, tbb::strict_ppl::internal::concurrent_queue_rep_base::head_counter, tbb::strict_ppl::internal::concurrent_queue_rep_base::n_invalid_entries, and tbb::strict_ppl::internal::concurrent_queue_rep_base::tail_counter.

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

Here is the caller graph for this function:

◆ internal_swap()

template<typename T >
void tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_swap ( concurrent_queue_base_v3< T > &  src)
inlineprotected

swap internal representation

Definition at line 499 of file _concurrent_queue_impl.h.

499 {
500 std::swap( my_rep, src.my_rep );
501 }
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:564

References tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::my_rep, and tbb::internal::swap().

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

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

◆ internal_throw_exception()

template<typename T >
void tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_throw_exception ( ) const
inlineprotected

Obsolete.

Definition at line 490 of file _concurrent_queue_impl.h.

490 {
492 }
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()

References tbb::internal::eid_bad_alloc, and tbb::internal::throw_exception().

Here is the call graph for this function:

◆ internal_try_pop()

template<typename T >
bool tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::internal_try_pop ( void dst)
protected

Attempt to dequeue item from queue.

NULL if there was no item to dequeue.

Definition at line 524 of file _concurrent_queue_impl.h.

524 {
526 ticket k;
527 do {
528 k = r.head_counter;
529 for(;;) {
530 if( (ptrdiff_t)(r.tail_counter-k)<=0 ) {
531 // Queue is empty
532 return false;
533 }
534 // Queue had item with ticket k when we looked. Attempt to get that item.
535 ticket tk=k;
536#if defined(_MSC_VER) && defined(_Wp64)
537 #pragma warning (push)
538 #pragma warning (disable: 4267)
539#endif
540 k = r.head_counter.compare_and_swap( tk+1, tk );
541#if defined(_MSC_VER) && defined(_Wp64)
542 #pragma warning (pop)
543#endif
544 if( k==tk )
545 break;
546 // Another thread snatched the item, retry.
547 }
548 } while( !r.choose( k ).pop( dst, k, *this ) );
549 return true;
550}
bool pop(void *dst, ticket k, concurrent_queue_base &base)

References tbb::strict_ppl::internal::concurrent_queue_rep< T >::choose(), tbb::strict_ppl::internal::concurrent_queue_rep_base::head_counter, and tbb::strict_ppl::internal::concurrent_queue_rep_base::tail_counter.

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

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

Friends And Related Function Documentation

◆ concurrent_queue_iterator_base_v3< T >

template<typename T >
friend class concurrent_queue_iterator_base_v3< T >
friend

Definition at line 424 of file _concurrent_queue_impl.h.

◆ concurrent_queue_iterator_rep< T >

template<typename T >
friend class concurrent_queue_iterator_rep< T >
friend

Definition at line 424 of file _concurrent_queue_impl.h.

◆ concurrent_queue_rep< T >

template<typename T >
friend struct concurrent_queue_rep< T >
friend

Definition at line 424 of file _concurrent_queue_impl.h.

◆ micro_queue< T >

template<typename T >
friend class micro_queue< T >
friend

Definition at line 424 of file _concurrent_queue_impl.h.

Member Data Documentation

◆ my_rep


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.