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...
 

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 60 of file _concurrent_queue_impl.h.

Member Typedef Documentation

◆ item_constructor_t

◆ padded_page

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 }

◆ ~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  }

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 >.

◆ allocate_page()

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

Definition at line 438 of file _concurrent_queue_impl.h.

438  {
440  size_t n = sizeof(padded_page) + (r.items_per_page-1)*sizeof(T);
441  return reinterpret_cast<page*>(allocate_block ( n ));
442  }

◆ 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 }

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 >.

◆ 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

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  }

◆ 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 }

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 }

◆ 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  }

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

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 }

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  }

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

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  }

◆ 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 }

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

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 429 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 428 of file _concurrent_queue_impl.h.

◆ concurrent_queue_rep< T >

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

Definition at line 426 of file _concurrent_queue_impl.h.

◆ micro_queue< T >

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

Definition at line 427 of file _concurrent_queue_impl.h.

Member Data Documentation

◆ my_rep


The documentation for this class was generated from the following file:
tbb::internal::concurrent_queue_base_v3::my_rep
concurrent_queue_rep * my_rep
Internal representation.
Definition: _concurrent_queue_impl.h:829
tbb::strict_ppl::internal::concurrent_queue_base_v3::padded_page
micro_queue< T >::padded_page padded_page
Definition: _concurrent_queue_impl.h:435
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::strict_ppl::internal::is_valid_page
bool is_valid_page(const concurrent_queue_rep_base::page *p)
Definition: _concurrent_queue_impl.h:102
tbb::internal::throw_exception
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
Definition: tbb_exception.h:105
tbb::internal::concurrent_queue_rep::choose
micro_queue & choose(ticket k)
Definition: concurrent_queue.cpp:139
tbb::internal::swap
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:564
tbb::strict_ppl::internal::concurrent_queue_base_v3::deallocate_page
virtual void deallocate_page(concurrent_queue_rep_base::page *p) __TBB_override
Definition: _concurrent_queue_impl.h:444
tbb::internal::concurrent_queue_rep::n_queue
static const size_t n_queue
Must be power of 2.
Definition: concurrent_queue.cpp:122
tbb::internal::micro_queue::tail_page
atomic< page * > tail_page
Definition: concurrent_queue.cpp:55
tbb::internal::micro_queue::pop
bool pop(void *dst, ticket k, concurrent_queue_base &base)
Definition: concurrent_queue.cpp:230
tbb::internal::micro_queue::assign
micro_queue & assign(const micro_queue &src, concurrent_queue_base &base, concurrent_queue_base::copy_specifics op_type)
Definition: concurrent_queue.cpp:253
tbb::internal::concurrent_queue_rep::head_counter
atomic< ticket > head_counter
Definition: concurrent_queue.cpp:129
tbb::internal::concurrent_queue_rep::n_invalid_entries
atomic< size_t > n_invalid_entries
Definition: concurrent_queue.cpp:131
tbb::internal::concurrent_queue_rep
Internal representation of a ConcurrentQueue.
Definition: concurrent_queue.cpp:112
tbb::internal::concurrent_queue_rep::array
micro_queue array[n_queue]
Definition: concurrent_queue.cpp:137
tbb::internal::eid_bad_alloc
@ eid_bad_alloc
Definition: tbb_exception.h:68
tbb::internal::ticket
size_t ticket
Definition: concurrent_queue.cpp:42
tbb::internal::micro_queue::head_page
atomic< page * > head_page
Definition: concurrent_queue.cpp:52
tbb::internal::NFS_GetLineSize
size_t __TBB_EXPORTED_FUNC NFS_GetLineSize()
Cache/sector line size.
Definition: cache_aligned_allocator.cpp:167
tbb::strict_ppl::internal::concurrent_queue_base_v3::my_rep
concurrent_queue_rep< T > * my_rep
Internal representation.
Definition: _concurrent_queue_impl.h:424
tbb::internal::concurrent_queue_rep::tail_counter
atomic< ticket > tail_counter
Definition: concurrent_queue.cpp:134
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::strict_ppl::internal::concurrent_queue_base_v3::allocate_block
virtual void * allocate_block(size_t n)=0
custom allocator
tbb::internal::micro_queue::push
void push(const void *item, ticket k, concurrent_queue_base &base, concurrent_queue_base::copy_specifics op_type)
Definition: concurrent_queue.cpp:161
tbb::strict_ppl::internal::concurrent_queue_base_v3::page
concurrent_queue_rep< T >::page page
Definition: _concurrent_queue_impl.h:432
tbb::strict_ppl::internal::concurrent_queue_base_v3::deallocate_block
virtual void deallocate_block(void *p, size_t n)=0
custom de-allocator

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.