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

Member Typedef Documentation

◆ item_constructor_t

◆ padded_page

Definition at line 439 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 436 of file _concurrent_queue_impl.h.

Constructor & Destructor Documentation

◆ concurrent_queue_base_v3()

Definition at line 510 of file _concurrent_queue_impl.h.

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

◆ ~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 463 of file _concurrent_queue_impl.h.

463  {
464 #if TBB_USE_ASSERT
465  size_t nq = my_rep->n_queue;
466  for( size_t i=0; i<nq; i++ )
467  __TBB_ASSERT( my_rep->array[i].tail_page==NULL, "pages were not freed properly" );
468 #endif /* TBB_USE_ASSERT */
469  cache_aligned_allocator<concurrent_queue_rep<T> >().deallocate(my_rep,1);
470  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
concurrent_queue_rep< T > * my_rep
Internal representation.

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

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

Definition at line 442 of file _concurrent_queue_impl.h.

442  {
444  size_t n = sizeof(padded_page) + (r.items_per_page-1)*sizeof(T);
445  return reinterpret_cast<page*>(allocate_block ( n ));
446  }
Internal representation of a ConcurrentQueue.
virtual void * allocate_block(size_t n)=0
custom allocator
concurrent_queue_rep< T > * my_rep
Internal representation.

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

595 {
597  r.items_per_page = src.my_rep->items_per_page;
598 
599  // copy concurrent_queue_rep data
603 
604  // copy or move micro_queues
605  for( size_t i = 0; i < r.n_queue; ++i )
606  r.array[i].assign( src.my_rep->array[i], *this, construct_item);
607 
609  "the source concurrent queue should not be concurrently modified." );
610 }
Internal representation of a ConcurrentQueue.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
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.
concurrent_queue_rep * my_rep
Internal representation.
concurrent_queue_rep< T > * my_rep
Internal representation.

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

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

Definition at line 448 of file _concurrent_queue_impl.h.

448  {
450  size_t n = sizeof(padded_page) + (r.items_per_page-1)*sizeof(T);
451  deallocate_block( reinterpret_cast<void*>(p), n );
452  }
Internal representation of a ConcurrentQueue.
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
concurrent_queue_rep< T > * my_rep
Internal representation.

◆ internal_empty()

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

check if the queue is empty; thread safe

Definition at line 569 of file _concurrent_queue_impl.h.

569  {
571  ticket tc = r.tail_counter;
572  ticket hc = r.head_counter;
573  // if tc!=r.tail_counter, the queue was not empty at some point between the two reads.
574  return tc==r.tail_counter && tc==hc+r.n_invalid_entries ;
575 }
Internal representation of a ConcurrentQueue.
concurrent_queue_rep< T > * my_rep
Internal representation.

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

578  {
580  size_t nq = r.n_queue;
581  for( size_t i=0; i<nq; ++i ) {
582  page* tp = r.array[i].tail_page;
583  if( is_valid_page(tp) ) {
584  __TBB_ASSERT( r.array[i].head_page==tp, "at most one page should remain" );
585  deallocate_page( tp );
586  r.array[i].tail_page = NULL;
587  } else
588  __TBB_ASSERT( !is_valid_page(r.array[i].head_page), "head page pointer corrupt?" );
589  }
590 }
Internal representation of a ConcurrentQueue.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
static const size_t n_queue
Must be power of 2.
bool is_valid_page(const concurrent_queue_rep_base::page *p)
virtual void deallocate_page(concurrent_queue_rep_base::page *p) __TBB_override
concurrent_queue_rep< T > * my_rep
Internal representation.

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

473  {
475  ticket k = r.tail_counter++;
476  r.choose(k).push( src, k, *this, construct_item );
477  }
Internal representation of a ConcurrentQueue.
void push(const void *item, ticket k, concurrent_queue_base &base, concurrent_queue_base::copy_specifics op_type)
concurrent_queue_rep< T > * my_rep
Internal representation.

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

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

Definition at line 557 of file _concurrent_queue_impl.h.

557  {
559  __TBB_ASSERT( sizeof(ptrdiff_t)<=sizeof(size_t), NULL );
560  ticket hc = r.head_counter;
561  size_t nie = r.n_invalid_entries;
562  ticket tc = r.tail_counter;
563  __TBB_ASSERT( hc!=tc || !nie, NULL );
564  ptrdiff_t sz = tc-hc-nie;
565  return sz<0 ? 0 : size_t(sz);
566 }
Internal representation of a ConcurrentQueue.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
concurrent_queue_rep< T > * my_rep
Internal representation.

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

503  {
504  std::swap( my_rep, src.my_rep );
505  }
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:539
concurrent_queue_rep * my_rep
Internal representation.
concurrent_queue_rep< T > * my_rep
Internal representation.

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

494  {
496  }
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()

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

528  {
530  ticket k;
531  do {
532  k = r.head_counter;
533  for(;;) {
534  if( (ptrdiff_t)(r.tail_counter-k)<=0 ) {
535  // Queue is empty
536  return false;
537  }
538  // Queue had item with ticket k when we looked. Attempt to get that item.
539  ticket tk=k;
540 #if defined(_MSC_VER) && defined(_Wp64)
541  #pragma warning (push)
542  #pragma warning (disable: 4267)
543 #endif
544  k = r.head_counter.compare_and_swap( tk+1, tk );
545 #if defined(_MSC_VER) && defined(_Wp64)
546  #pragma warning (pop)
547 #endif
548  if( k==tk )
549  break;
550  // Another thread snatched the item, retry.
551  }
552  } while( !r.choose( k ).pop( dst, k, *this ) );
553  return true;
554 }
Internal representation of a ConcurrentQueue.
bool pop(void *dst, ticket k, concurrent_queue_base &base)
value_type compare_and_swap(value_type value, value_type comparand)
Definition: atomic.h:289
concurrent_queue_rep< T > * my_rep
Internal representation.

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

◆ concurrent_queue_rep< T >

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

Definition at line 430 of file _concurrent_queue_impl.h.

◆ micro_queue< T >

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

Definition at line 431 of file _concurrent_queue_impl.h.

Member Data Documentation

◆ my_rep


The documentation for this class was generated from the following file:

Copyright © 2005-2019 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.