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 page * | allocate_page () __TBB_override
virtual void | deallocate_page (concurrent_queue_rep_base::page *p) __TBB_override
virtual void * | allocate_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

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

template<typename T >

tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::concurrent_queue_base_v3 | ( |  | ) |

protected

Definition at line 506 of file _concurrent_queue_impl.h.

{
const size_t item_size = sizeof(T);
my_rep = cache_aligned_allocator<concurrent_queue_rep<T> >().allocate(1);
__TBB_ASSERT( (size_t)my_rep % NFS_GetLineSize()==0, "alignment error" );
__TBB_ASSERT( (size_t)&my_rep->head_counter % NFS_GetLineSize()==0, "alignment error" );
__TBB_ASSERT( (size_t)&my_rep->tail_counter % NFS_GetLineSize()==0, "alignment error" );
__TBB_ASSERT( (size_t)&my_rep->array % NFS_GetLineSize()==0, "alignment error" );
memset(static_cast<void*>(my_rep),0,sizeof(concurrent_queue_rep<T>));
my_rep->item_size = item_size;
my_rep->items_per_page = item_size<= 8 ? 32 :
item_size<= 16 ? 16 :
item_size<= 32 ? 8 :
item_size<= 64 ? 4 :
item_size<=128 ? 2 :
1;
}

## ~concurrent_queue_base_v3()

template<typename T>

virtual tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::~concurrent_queue_base_v3 | ( |  | ) |

inline protected virtual

Definition at line 459 of file _concurrent_queue_impl.h.

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

## Member Function Documentation

## allocate_block()

template<typename T>

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

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

inline private virtual

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

Definition at line 438 of file _concurrent_queue_impl.h.

{
concurrent_queue_rep<T>& r = *my_rep;
size_t n = sizeof(padded_page) + (r.items_per_page-1)*sizeof(T);
return reinterpret_cast<page*>(allocate_block ( n ));
}

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

{
concurrent_queue_rep<T>& r = *my_rep;
r.items_per_page = src.my_rep->items_per_page;
// copy concurrent_queue_rep data
r.head_counter = src.my_rep->head_counter;
r.tail_counter = src.my_rep->tail_counter;
r.n_invalid_entries = src.my_rep->n_invalid_entries;
// copy or move micro_queues
for( size_t i = 0; i < r.n_queue; ++i )
r.array[i].assign( src.my_rep->array[i], *this, construct_item);
__TBB_ASSERT( r.head_counter==src.my_rep->head_counter && r.tail_counter==src.my_rep->tail_counter,
"the source concurrent queue should not be concurrently modified." );
}

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

private pure 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 | ) |

inline private virtual

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

Definition at line 444 of file _concurrent_queue_impl.h.

{
concurrent_queue_rep<T>& r = *my_rep;
size_t n = sizeof(padded_page) + (r.items_per_page-1)*sizeof(T);
deallocate_block( reinterpret_cast<void*>(p), n );
}

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

{
concurrent_queue_rep<T>& r = *my_rep;
ticket tc = r.tail_counter;
ticket hc = r.head_counter;
// if tc!=r.tail_counter, the queue was not empty at some point between the two reads.
return tc==r.tail_counter && tc==hc+r.n_invalid_entries ;
}

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.

{
concurrent_queue_rep<T>& r = *my_rep;
size_t nq = r.n_queue;
for( size_t i=0; i<nq; ++i ) {
page* tp = r.array[i].tail_page;
if( is_valid_page(tp) ) {
__TBB_ASSERT( r.array[i].head_page==tp, "at most one page should remain" );
deallocate_page( tp );
r.array[i].tail_page = NULL;
} else
__TBB_ASSERT( !is_valid_page(r.array[i].head_page), "head page pointer corrupt?" );
}
}

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

inline protected

Enqueue item at tail of queue.

Definition at line 469 of file _concurrent_queue_impl.h.

{
concurrent_queue_rep<T>& r = *my_rep;
ticket k = r.tail_counter++;
r.choose(k).push( src, k, *this, construct_item );
}

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

{
concurrent_queue_rep<T>& r = *my_rep;
__TBB_ASSERT( sizeof(ptrdiff_t)<=sizeof(size_t), NULL );
ticket hc = r.head_counter;
size_t nie = r.n_invalid_entries;
ticket tc = r.tail_counter;
__TBB_ASSERT( hc!=tc || !nie, NULL );
ptrdiff_t sz = tc-hc-nie;
return sz<0 ? 0 : size_t(sz);
}

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

inline protected

swap internal representation

Definition at line 499 of file _concurrent_queue_impl.h.

{
std::swap( my_rep, src.my_rep );
}

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

inline protected

Obsolete.

Definition at line 490 of file _concurrent_queue_impl.h.

{
throw_exception( eid_bad_alloc );
}

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

{
concurrent_queue_rep<T>& r = *my_rep;
ticket k;
do {
k = r.head_counter;
for(;;) {
if( (ptrdiff_t)(r.tail_counter-k)<=0 ) {
// Queue is empty
return false;
}
// Queue had item with ticket k when we looked. Attempt to get that item.
ticket tk=k;
#if defined(_MSC_VER) && defined(_Wp64)
#pragma warning (push)
#pragma warning (disable: 4267)
#endif
k = r.head_counter.compare_and_swap( tk+1, tk );
#if defined(_MSC_VER) && defined(_Wp64)
#pragma warning (pop)
#endif
if( k==tk )
break;
// Another thread snatched the item, retry.
}
} while( !r.choose( k ).pop( dst, k, *this ) );
return true;
}

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

template<typename T>

concurrent_queue_rep<T>* tbb::strict_ppl::internal::concurrent_queue_base_v3< T >::my_rep

private

Internal representation.

Definition at line 424 of file _concurrent_queue_impl.h.

Referenced by tbb::strict_ppl::internal::concurrent_queue_iterator_base_v3< tbb_remove_cv< Value >::type >::advance(), tbb::strict_ppl::internal::micro_queue< Value >::assign(), tbb::strict_ppl::internal::concurrent_queue_base_v3< Value >::assign(), tbb::strict_ppl::internal::concurrent_queue_iterator_rep< Value >::concurrent_queue_iterator_rep(), tbb::strict_ppl::internal::micro_queue< Value >::pop(), and tbb::strict_ppl::internal::micro_queue< Value >::push().

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

- _concurrent_queue_impl.h

tbb::strict_ppl::internal::concurrent_queue_base_v3::padded_page
micro_queue< T >::padded_page padded_page
Definition: _concurrent_queue_impl.h:435
tbb::internal::concurrent_queue_base_v3::my_rep
concurrent_queue_rep * my_rep
Internal representation.
Definition: _concurrent_queue_impl.h:829
__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::tail_counter
atomic< ticket > tail_counter
Definition: concurrent_queue.cpp:134
tbb::strict_ppl::internal::concurrent_queue_base_v3::deallocate_block
virtual void deallocate_block(void *p, size_t n)=0
custom de-allocator
tbb::internal::concurrent_queue_rep
Internal representation of a ConcurrentQueue.
Definition: concurrent_queue.cpp:112
tbb::internal::swap
void swap(atomic< T > &lhs, atomic< T > &rhs)
Definition: atomic.h:564
tbb::strict_ppl::internal::concurrent_queue_base_v3::allocate_block
virtual void * allocate_block(size_t n)=0
custom allocator
tbb::internal::concurrent_queue_rep::head_counter
atomic< ticket > head_counter
Definition: concurrent_queue.cpp:129
tbb::internal::micro_queue::tail_page
atomic< page * > tail_page
Definition: concurrent_queue.cpp:55
tbb::internal::concurrent_queue_rep::n_invalid_entries
atomic< size_t > n_invalid_entries
Definition: concurrent_queue.cpp:131
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::my_rep
concurrent_queue_rep< T > * my_rep
Internal representation.
Definition: _concurrent_queue_impl.h:424
tbb::internal::concurrent_queue_rep::array
micro_queue array[n_queue]
Definition: concurrent_queue.cpp:137
tbb::internal::micro_queue::head_page
atomic< page * > head_page
Definition: concurrent_queue.cpp:52
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::eid_bad_alloc
Definition: tbb_exception.h:68
tbb::internal::ticket
size_t ticket
Definition: concurrent_queue.cpp:42
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::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::choose
micro_queue & choose(ticket k)
Definition: concurrent_queue.cpp:139
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
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
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

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.