Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
internal::item_buffer< T, A > Class Template Reference

#include <_flow_graph_item_buffer_impl.h>

Inheritance diagram for internal::item_buffer< T, A >:
Collaboration diagram for internal::item_buffer< T, A >:

Public Types

enum  buffer_item_state { no_item =0, has_item =1, reserved_item =2 }
 
typedef T item_type
 

Public Member Functions

 item_buffer ()
 Constructor. More...
 
 ~item_buffer ()
 
void reset ()
 

Protected Types

typedef size_t size_type
 
typedef aligned_pair< item_type, buffer_item_state >::type buffer_item_type
 
typedef tbb::internal::allocator_rebind< A, buffer_item_type >::type allocator_type
 

Protected Member Functions

bool buffer_empty () const
 
buffer_item_typeitem (size_type i)
 
const buffer_item_typeitem (size_type i) const
 
bool my_item_valid (size_type i) const
 
bool my_item_reserved (size_type i) const
 
const item_typeget_my_item (size_t i) const
 
void set_my_item (size_t i, const item_type &o)
 
void fetch_item (size_t i, item_type &o)
 
void move_item (size_t to, size_t from)
 
bool place_item (size_t here, const item_type &me)
 
void swap_items (size_t i, size_t j)
 
void destroy_item (size_type i)
 
const item_typefront () const
 
const item_typeback () const
 
void reserve_item (size_type i)
 
void release_item (size_type i)
 
void destroy_front ()
 
void destroy_back ()
 
size_type size (size_t new_tail=0)
 
size_type capacity ()
 
bool buffer_full ()
 
void grow_my_array (size_t minimum_size)
 Grows the internal array. More...
 
bool push_back (item_type &v)
 
bool pop_back (item_type &v)
 
bool pop_front (item_type &v)
 
void clean_up_buffer (bool reset_pointers)
 

Protected Attributes

buffer_item_typemy_array
 
size_type my_array_size
 
size_type my_head
 
size_type my_tail
 

Static Protected Attributes

static const size_type initial_buffer_size = 4
 

Detailed Description

template<typename T, typename A = cache_aligned_allocator<T>>
class internal::item_buffer< T, A >

Definition at line 40 of file _flow_graph_item_buffer_impl.h.

Member Typedef Documentation

◆ allocator_type

template<typename T, typename A = cache_aligned_allocator<T>>
typedef tbb::internal::allocator_rebind<A, buffer_item_type>::type internal::item_buffer< T, A >::allocator_type
protected

Definition at line 47 of file _flow_graph_item_buffer_impl.h.

◆ buffer_item_type

template<typename T, typename A = cache_aligned_allocator<T>>
typedef aligned_pair<item_type, buffer_item_state>::type internal::item_buffer< T, A >::buffer_item_type
protected

Definition at line 46 of file _flow_graph_item_buffer_impl.h.

◆ item_type

template<typename T, typename A = cache_aligned_allocator<T>>
typedef T internal::item_buffer< T, A >::item_type

Definition at line 42 of file _flow_graph_item_buffer_impl.h.

◆ size_type

template<typename T, typename A = cache_aligned_allocator<T>>
typedef size_t internal::item_buffer< T, A >::size_type
protected

Definition at line 45 of file _flow_graph_item_buffer_impl.h.

Member Enumeration Documentation

◆ buffer_item_state

template<typename T, typename A = cache_aligned_allocator<T>>
enum internal::item_buffer::buffer_item_state

Constructor & Destructor Documentation

◆ item_buffer()

template<typename T, typename A = cache_aligned_allocator<T>>
internal::item_buffer< T, A >::item_buffer ( )
inline

Constructor.

Definition at line 230 of file _flow_graph_item_buffer_impl.h.

230  : my_array(NULL), my_array_size(0),
231  my_head(0), my_tail(0) {
233  }
void grow_my_array(size_t minimum_size)
Grows the internal array.
static const size_type initial_buffer_size

◆ ~item_buffer()

template<typename T, typename A = cache_aligned_allocator<T>>
internal::item_buffer< T, A >::~item_buffer ( )
inline

Definition at line 235 of file _flow_graph_item_buffer_impl.h.

235  {
236  clean_up_buffer(/*reset_pointers*/true);
237  }
void clean_up_buffer(bool reset_pointers)

Member Function Documentation

◆ back()

template<typename T, typename A = cache_aligned_allocator<T>>
const item_type& internal::item_buffer< T, A >::back ( ) const
inlineprotected

Definition at line 136 of file _flow_graph_item_buffer_impl.h.

137  {
138  __TBB_ASSERT(my_item_valid(my_tail - 1), "attempt to fetch head non-item");
139  return get_my_item(my_tail - 1);
140  }
const item_type & get_my_item(size_t i) const
bool my_item_valid(size_type i) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Referenced by internal::item_buffer< OutputTuple >::pop_back().

Here is the caller graph for this function:

◆ buffer_empty()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::buffer_empty ( ) const
inlineprotected

Definition at line 54 of file _flow_graph_item_buffer_impl.h.

Referenced by internal::function_input_queue< T, A >::empty().

Here is the caller graph for this function:

◆ buffer_full()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::buffer_full ( )
inlineprotected

Definition at line 155 of file _flow_graph_item_buffer_impl.h.

155 { return size() >= capacity(); }
size_type size(size_t new_tail=0)

Referenced by internal::item_buffer< OutputTuple >::push_back().

Here is the caller graph for this function:

◆ capacity()

template<typename T, typename A = cache_aligned_allocator<T>>
size_type internal::item_buffer< T, A >::capacity ( )
inlineprotected

Definition at line 152 of file _flow_graph_item_buffer_impl.h.

Referenced by internal::item_buffer< OutputTuple >::buffer_full(), and internal::item_buffer< OutputTuple >::grow_my_array().

Here is the caller graph for this function:

◆ clean_up_buffer()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::clean_up_buffer ( bool  reset_pointers)
inlineprotected

Definition at line 214 of file _flow_graph_item_buffer_impl.h.

214  {
215  if (my_array) {
216  for( size_type i=my_head; i<my_tail; ++i ) {
217  if(my_item_valid(i))
218  destroy_item(i);
219  }
220  allocator_type().deallocate(my_array,my_array_size);
221  }
222  my_array = NULL;
223  if(reset_pointers) {
224  my_head = my_tail = my_array_size = 0;
225  }
226  }
tbb::internal::allocator_rebind< A, buffer_item_type >::type allocator_type
bool my_item_valid(size_type i) const

Referenced by internal::item_buffer< OutputTuple >::grow_my_array(), internal::item_buffer< OutputTuple >::reset(), and internal::item_buffer< OutputTuple >::~item_buffer().

Here is the caller graph for this function:

◆ destroy_back()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::destroy_back ( )
inlineprotected

Definition at line 147 of file _flow_graph_item_buffer_impl.h.

Referenced by internal::item_buffer< OutputTuple >::pop_back().

Here is the caller graph for this function:

◆ destroy_front()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::destroy_front ( )
inlineprotected

Definition at line 146 of file _flow_graph_item_buffer_impl.h.

Referenced by internal::reservable_item_buffer< T, A >::consume_front(), internal::function_input_queue< T, A >::pop(), and internal::item_buffer< OutputTuple >::pop_front().

Here is the caller graph for this function:

◆ destroy_item()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::destroy_item ( size_type  i)
inlineprotected

Definition at line 122 of file _flow_graph_item_buffer_impl.h.

122  {
123  __TBB_ASSERT(my_item_valid(i), "destruction of invalid item");
124  (tbb::internal::punned_cast<item_type *>(&(item(i).first)))->~item_type();
125  item(i).second = no_item;
126  }
buffer_item_type & item(size_type i)
bool my_item_valid(size_type i) const
auto first(Container &c) -> decltype(begin(c))
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Referenced by internal::item_buffer< OutputTuple >::clean_up_buffer(), internal::item_buffer< OutputTuple >::destroy_back(), internal::item_buffer< OutputTuple >::destroy_front(), internal::item_buffer< OutputTuple >::fetch_item(), internal::item_buffer< OutputTuple >::move_item(), and internal::item_buffer< OutputTuple >::set_my_item().

Here is the caller graph for this function:

◆ fetch_item()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::fetch_item ( size_t  i,
item_type o 
)
inlineprotected

Definition at line 88 of file _flow_graph_item_buffer_impl.h.

88  {
89  __TBB_ASSERT(my_item_valid(i), "Trying to fetch an empty slot");
90  o = get_my_item(i); // could have std::move assign semantics
91  destroy_item(i);
92  }
const item_type & get_my_item(size_t i) const
bool my_item_valid(size_type i) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

◆ front()

template<typename T, typename A = cache_aligned_allocator<T>>
const item_type& internal::item_buffer< T, A >::front ( ) const
inlineprotected

Definition at line 129 of file _flow_graph_item_buffer_impl.h.

130  {
131  __TBB_ASSERT(my_item_valid(my_head), "attempt to fetch head non-item");
132  return get_my_item(my_head);
133  }
const item_type & get_my_item(size_t i) const
bool my_item_valid(size_type i) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Referenced by internal::function_input_queue< T, A >::front(), internal::item_buffer< OutputTuple >::pop_front(), and internal::reservable_item_buffer< T, A >::reserve_front().

Here is the caller graph for this function:

◆ get_my_item()

template<typename T, typename A = cache_aligned_allocator<T>>
const item_type& internal::item_buffer< T, A >::get_my_item ( size_t  i) const
inlineprotected

Definition at line 72 of file _flow_graph_item_buffer_impl.h.

72  {
73  __TBB_ASSERT(my_item_valid(i),"attempt to get invalid item");
74  item_type *itm = (tbb::internal::punned_cast<item_type *>(&(item(i).first)));
75  return *(const item_type *)itm;
76  }
buffer_item_type & item(size_type i)
bool my_item_valid(size_type i) const
auto first(Container &c) -> decltype(begin(c))
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Referenced by internal::item_buffer< OutputTuple >::back(), internal::item_buffer< OutputTuple >::fetch_item(), internal::item_buffer< OutputTuple >::front(), internal::item_buffer< OutputTuple >::grow_my_array(), internal::item_buffer< OutputTuple >::move_item(), and internal::item_buffer< OutputTuple >::swap_items().

Here is the caller graph for this function:

◆ grow_my_array()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::grow_my_array ( size_t  minimum_size)
inlineprotected

Grows the internal array.

Definition at line 158 of file _flow_graph_item_buffer_impl.h.

158  {
159  // test that we haven't made the structure inconsistent.
160  __TBB_ASSERT(capacity() >= my_tail - my_head, "total items exceed capacity");
162  while( new_size<minimum_size )
163  new_size*=2;
164 
165  buffer_item_type* new_array = allocator_type().allocate(new_size);
166 
167  // initialize validity to "no"
168  for( size_type i=0; i<new_size; ++i ) { new_array[i].second = no_item; }
169 
170  for( size_type i=my_head; i<my_tail; ++i) {
171  if(my_item_valid(i)) { // sequencer_node may have empty slots
172  // placement-new copy-construct; could be std::move
173  char *new_space = (char *)&(new_array[i&(new_size-1)].first);
174  (void)new(new_space) item_type(get_my_item(i));
175  new_array[i&(new_size-1)].second = item(i).second;
176  }
177  }
178 
179  clean_up_buffer(/*reset_pointers*/false);
180 
181  my_array = new_array;
183  }
const item_type & get_my_item(size_t i) const
aligned_pair< item_type, buffer_item_state >::type buffer_item_type
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t new_size
static const size_type initial_buffer_size
buffer_item_type & item(size_type i)
tbb::internal::allocator_rebind< A, buffer_item_type >::type allocator_type
bool my_item_valid(size_type i) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void clean_up_buffer(bool reset_pointers)

Referenced by internal::item_buffer< OutputTuple >::item_buffer(), internal::item_buffer< OutputTuple >::push_back(), and internal::item_buffer< OutputTuple >::reset().

Here is the caller graph for this function:

◆ item() [1/2]

template<typename T, typename A = cache_aligned_allocator<T>>
buffer_item_type& internal::item_buffer< T, A >::item ( size_type  i)
inlineprotected

Definition at line 56 of file _flow_graph_item_buffer_impl.h.

56  {
59  return my_array[i & (my_array_size - 1) ];
60  }
auto first(Container &c) -> decltype(begin(c))
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Referenced by internal::item_buffer< OutputTuple >::destroy_item(), internal::item_buffer< OutputTuple >::get_my_item(), internal::item_buffer< OutputTuple >::grow_my_array(), internal::item_buffer< OutputTuple >::my_item_reserved(), internal::item_buffer< OutputTuple >::my_item_valid(), internal::item_buffer< OutputTuple >::release_item(), internal::item_buffer< OutputTuple >::reserve_item(), and internal::item_buffer< OutputTuple >::set_my_item().

Here is the caller graph for this function:

◆ item() [2/2]

template<typename T, typename A = cache_aligned_allocator<T>>
const buffer_item_type& internal::item_buffer< T, A >::item ( size_type  i) const
inlineprotected

Definition at line 62 of file _flow_graph_item_buffer_impl.h.

62  {
65  return my_array[i & (my_array_size-1)];
66  }
auto first(Container &c) -> decltype(begin(c))
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

◆ move_item()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::move_item ( size_t  to,
size_t  from 
)
inlineprotected

Definition at line 97 of file _flow_graph_item_buffer_impl.h.

97  {
98  __TBB_ASSERT(!my_item_valid(to), "Trying to move to a non-empty slot");
99  __TBB_ASSERT(my_item_valid(from), "Trying to move from an empty slot");
100  set_my_item(to, get_my_item(from)); // could have std::move semantics
101  destroy_item(from);
102 
103  }
const item_type & get_my_item(size_t i) const
void set_my_item(size_t i, const item_type &o)
bool my_item_valid(size_type i) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

◆ my_item_reserved()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::my_item_reserved ( size_type  i) const
inlineprotected

Definition at line 69 of file _flow_graph_item_buffer_impl.h.

Referenced by internal::item_buffer< OutputTuple >::release_item(), and internal::item_buffer< OutputTuple >::reserve_item().

Here is the caller graph for this function:

◆ my_item_valid()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::my_item_valid ( size_type  i) const
inlineprotected

◆ place_item()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::place_item ( size_t  here,
const item_type me 
)
inlineprotected

Definition at line 106 of file _flow_graph_item_buffer_impl.h.

106  {
107 #if !TBB_DEPRECATED_SEQUENCER_DUPLICATES
108  if(my_item_valid(here)) return false;
109 #endif
110  set_my_item(here, me);
111  return true;
112  }
void set_my_item(size_t i, const item_type &o)
bool my_item_valid(size_type i) const

◆ pop_back()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::pop_back ( item_type v)
inlineprotected

Definition at line 194 of file _flow_graph_item_buffer_impl.h.

194  {
195  if (!my_item_valid(my_tail-1)) {
196  return false;
197  }
198  v = this->back();
199  destroy_back();
200  return true;
201  }
const item_type & back() const
bool my_item_valid(size_type i) const

◆ pop_front()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::pop_front ( item_type v)
inlineprotected

Definition at line 203 of file _flow_graph_item_buffer_impl.h.

203  {
204  if(!my_item_valid(my_head)) {
205  return false;
206  }
207  v = this->front();
208  destroy_front();
209  return true;
210  }
const item_type & front() const
bool my_item_valid(size_type i) const

Referenced by internal::function_input_queue< T, A >::pop().

Here is the caller graph for this function:

◆ push_back()

template<typename T, typename A = cache_aligned_allocator<T>>
bool internal::item_buffer< T, A >::push_back ( item_type v)
inlineprotected

Definition at line 185 of file _flow_graph_item_buffer_impl.h.

185  {
186  if(buffer_full()) {
187  grow_my_array(size() + 1);
188  }
189  set_my_item(my_tail, v);
190  ++my_tail;
191  return true;
192  }
size_type size(size_t new_tail=0)
void grow_my_array(size_t minimum_size)
Grows the internal array.
void set_my_item(size_t i, const item_type &o)

Referenced by internal::function_input_queue< T, A >::push().

Here is the caller graph for this function:

◆ release_item()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::release_item ( size_type  i)
inlineprotected

Definition at line 144 of file _flow_graph_item_buffer_impl.h.

144 { __TBB_ASSERT(my_item_reserved(i), "item is not reserved"); item(i).second = has_item; }
bool my_item_reserved(size_type i) const
buffer_item_type & item(size_type i)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Referenced by internal::reservable_item_buffer< T, A >::release_front().

Here is the caller graph for this function:

◆ reserve_item()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::reserve_item ( size_type  i)
inlineprotected

Definition at line 143 of file _flow_graph_item_buffer_impl.h.

143 { __TBB_ASSERT(my_item_valid(i) && !my_item_reserved(i), "item cannot be reserved"); item(i).second = reserved_item; }
bool my_item_reserved(size_type i) const
buffer_item_type & item(size_type i)
bool my_item_valid(size_type i) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Referenced by internal::reservable_item_buffer< T, A >::reserve_front().

Here is the caller graph for this function:

◆ reset()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::reset ( )
inline

Definition at line 239 of file _flow_graph_item_buffer_impl.h.

239 { clean_up_buffer(/*reset_pointers*/true); grow_my_array(initial_buffer_size); }
void grow_my_array(size_t minimum_size)
Grows the internal array.
static const size_type initial_buffer_size
void clean_up_buffer(bool reset_pointers)

Referenced by internal::reservable_item_buffer< T, A >::reset(), internal::function_input_base< Input, Policy, A, multifunction_input< Input, OutputPortSet, Policy, A > >::reset_function_input_base(), and internal::queueing_port< T >::reset_receiver().

Here is the caller graph for this function:

◆ set_my_item()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::set_my_item ( size_t  i,
const item_type o 
)
inlineprotected

Definition at line 79 of file _flow_graph_item_buffer_impl.h.

Referenced by internal::item_buffer< OutputTuple >::move_item(), internal::item_buffer< OutputTuple >::place_item(), internal::item_buffer< OutputTuple >::push_back(), and internal::item_buffer< OutputTuple >::swap_items().

Here is the caller graph for this function:

◆ size()

template<typename T, typename A = cache_aligned_allocator<T>>
size_type internal::item_buffer< T, A >::size ( size_t  new_tail = 0)
inlineprotected

Definition at line 151 of file _flow_graph_item_buffer_impl.h.

151 { return (new_tail ? new_tail : my_tail) - my_head; }

Referenced by internal::item_buffer< OutputTuple >::buffer_full(), and internal::item_buffer< OutputTuple >::push_back().

Here is the caller graph for this function:

◆ swap_items()

template<typename T, typename A = cache_aligned_allocator<T>>
void internal::item_buffer< T, A >::swap_items ( size_t  i,
size_t  j 
)
inlineprotected

Definition at line 115 of file _flow_graph_item_buffer_impl.h.

115  {
116  __TBB_ASSERT(my_item_valid(i) && my_item_valid(j), "attempt to swap invalid item(s)");
117  item_type temp = get_my_item(i);
118  set_my_item(i, get_my_item(j));
119  set_my_item(j, temp);
120  }
const item_type & get_my_item(size_t i) const
void set_my_item(size_t i, const item_type &o)
bool my_item_valid(size_type i) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

Member Data Documentation

◆ initial_buffer_size

template<typename T, typename A = cache_aligned_allocator<T>>
const size_type internal::item_buffer< T, A >::initial_buffer_size = 4
staticprotected

◆ my_array

template<typename T, typename A = cache_aligned_allocator<T>>
buffer_item_type* internal::item_buffer< T, A >::my_array
protected

◆ my_array_size

◆ my_head

◆ my_tail


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.