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 A::template rebind< buffer_item_type >::other 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 44 of file _flow_graph_item_buffer_impl.h.

Member Typedef Documentation

◆ allocator_type

template<typename T, typename A = cache_aligned_allocator<T>>
typedef A::template rebind<buffer_item_type>::other internal::item_buffer< T, A >::allocator_type
protected

Definition at line 51 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 50 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 46 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 49 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 235 of file _flow_graph_item_buffer_impl.h.

235  : my_array(NULL), my_array_size(0),
236  my_head(0), my_tail(0) {
238  }
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 240 of file _flow_graph_item_buffer_impl.h.

240  {
241  clean_up_buffer(/*reset_pointers*/true);
242  }
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 141 of file _flow_graph_item_buffer_impl.h.

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

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

◆ buffer_full()

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

Definition at line 160 of file _flow_graph_item_buffer_impl.h.

160 { 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 157 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 219 of file _flow_graph_item_buffer_impl.h.

219  {
220  if (my_array) {
221  for( size_type i=my_head; i<my_tail; ++i ) {
222  if(my_item_valid(i))
223  destroy_item(i);
224  }
225  allocator_type().deallocate(my_array,my_array_size);
226  }
227  my_array = NULL;
228  if(reset_pointers) {
229  my_head = my_tail = my_array_size = 0;
230  }
231  }
bool my_item_valid(size_type i) const
A::template rebind< buffer_item_type >::other allocator_type

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

◆ 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 127 of file _flow_graph_item_buffer_impl.h.

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

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 93 of file _flow_graph_item_buffer_impl.h.

93  {
94  __TBB_ASSERT(my_item_valid(i), "Trying to fetch an empty slot");
95  o = get_my_item(i); // could have std::move assign semantics
96  destroy_item(i);
97  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
bool my_item_valid(size_type i) const
const item_type & get_my_item(size_t i) const

◆ front()

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

Definition at line 134 of file _flow_graph_item_buffer_impl.h.

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

Referenced by internal::function_input_queue< T, A >::front(), internal::queueing_port< T >::handle_operations(), 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 77 of file _flow_graph_item_buffer_impl.h.

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

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 163 of file _flow_graph_item_buffer_impl.h.

163  {
164  // test that we haven't made the structure inconsistent.
165  __TBB_ASSERT(capacity() >= my_tail - my_head, "total items exceed capacity");
167  while( new_size<minimum_size )
168  new_size*=2;
169 
170  buffer_item_type* new_array = allocator_type().allocate(new_size);
171 
172  // initialize validity to "no"
173  for( size_type i=0; i<new_size; ++i ) { new_array[i].second = no_item; }
174 
175  for( size_type i=my_head; i<my_tail; ++i) {
176  if(my_item_valid(i)) { // sequencer_node may have empty slots
177  // placement-new copy-construct; could be std::move
178  char *new_space = (char *)&(new_array[i&(new_size-1)].first);
179  (void)new(new_space) item_type(get_my_item(i));
180  new_array[i&(new_size-1)].second = item(i).second;
181  }
182  }
183 
184  clean_up_buffer(/*reset_pointers*/false);
185 
186  my_array = new_array;
188  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
bool my_item_valid(size_type i) const
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
A::template rebind< buffer_item_type >::other allocator_type
void clean_up_buffer(bool reset_pointers)
aligned_pair< item_type, buffer_item_state >::type buffer_item_type
const item_type & get_my_item(size_t i) const
static const size_type initial_buffer_size
buffer_item_type & item(size_type i)

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

◆ 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 67 of file _flow_graph_item_buffer_impl.h.

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

◆ 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 102 of file _flow_graph_item_buffer_impl.h.

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

◆ 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

◆ 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 111 of file _flow_graph_item_buffer_impl.h.

111  {
112 #if !TBB_DEPRECATED_SEQUENCER_DUPLICATES
113  if(my_item_valid(here)) return false;
114 #endif
115  set_my_item(here, me);
116  return true;
117  }
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 199 of file _flow_graph_item_buffer_impl.h.

199  {
200  if (!my_item_valid(my_tail-1)) {
201  return false;
202  }
203  v = this->back();
204  destroy_back();
205  return true;
206  }
bool my_item_valid(size_type i) const
const item_type & back() 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 208 of file _flow_graph_item_buffer_impl.h.

208  {
209  if(!my_item_valid(my_head)) {
210  return false;
211  }
212  v = this->front();
213  destroy_front();
214  return true;
215  }
bool my_item_valid(size_type i) const
const item_type & front() 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 190 of file _flow_graph_item_buffer_impl.h.

190  {
191  if(buffer_full()) {
192  grow_my_array(size() + 1);
193  }
194  set_my_item(my_tail, v);
195  ++my_tail;
196  return true;
197  }
void set_my_item(size_t i, const item_type &o)
size_type size(size_t new_tail=0)
void grow_my_array(size_t minimum_size)
Grows the internal array.

Referenced by internal::queueing_port< T >::handle_operations(), and 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 149 of file _flow_graph_item_buffer_impl.h.

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

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 148 of file _flow_graph_item_buffer_impl.h.

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

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

◆ 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

◆ 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 156 of file _flow_graph_item_buffer_impl.h.

156 { 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 120 of file _flow_graph_item_buffer_impl.h.

120  {
121  __TBB_ASSERT(my_item_valid(i) && my_item_valid(j), "attempt to swap invalid item(s)");
122  item_type temp = get_my_item(i);
123  set_my_item(i, get_my_item(j));
124  set_my_item(j, temp);
125  }
void set_my_item(size_t i, const item_type &o)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
bool my_item_valid(size_type i) const
const item_type & get_my_item(size_t i) const

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