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 40 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 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
Enumerator
no_item 
has_item 
reserved_item 

Definition at line 43 of file _flow_graph_item_buffer_impl.h.

43 { no_item=0, has_item=1, reserved_item=2 };

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

231  : my_array(NULL), my_array_size(0),
232  my_head(0), my_tail(0) {
234  }

◆ ~item_buffer()

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

Definition at line 236 of file _flow_graph_item_buffer_impl.h.

236  {
237  clean_up_buffer(/*reset_pointers*/true);
238  }

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

138  {
139  __TBB_ASSERT(my_item_valid(my_tail - 1), "attempt to fetch head non-item");
140  return get_my_item(my_tail - 1);
141  }

Referenced by internal::item_buffer< OutputTuple >::pop_back(), and tbb::flow::interface11::buffer_node< T, A >::try_put_and_add_task().

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

55 { return my_head == my_tail; }

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

156 { return size() >= capacity(); }

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

153 { return my_array_size; }

Referenced by internal::item_buffer< OutputTuple >::buffer_full(), internal::item_buffer< OutputTuple >::grow_my_array(), and tbb::flow::interface11::sequencer_node< T, A >::internal_push().

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

215  {
216  if (my_array) {
217  for( size_type i=my_head; i<my_tail; ++i ) {
218  if(my_item_valid(i))
219  destroy_item(i);
220  }
221  allocator_type().deallocate(my_array,my_array_size);
222  }
223  my_array = NULL;
224  if(reset_pointers) {
225  my_head = my_tail = my_array_size = 0;
226  }
227  }

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

148 { destroy_item(my_tail-1); --my_tail; }

Referenced by internal::item_buffer< OutputTuple >::pop_back(), and tbb::flow::interface11::buffer_node< T, A >::try_put_and_add_task().

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 147 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(), internal::item_buffer< OutputTuple >::pop_front(), and tbb::flow::interface11::queue_node< T, A >::try_put_and_add_task().

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

123  {
124  __TBB_ASSERT(my_item_valid(i), "destruction of invalid item");
125  (tbb::internal::punned_cast<item_type *>(&(item(i).first)))->~item_type();
126  item(i).second = no_item;
127  }

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(), tbb::flow::interface11::priority_queue_node< T, Compare, A >::prio_pop(), 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 89 of file _flow_graph_item_buffer_impl.h.

89  {
90  __TBB_ASSERT(my_item_valid(i), "Trying to fetch an empty slot");
91  o = get_my_item(i); // could have std::move assign semantics
92  destroy_item(i);
93  }

Referenced by tbb::flow::interface11::priority_queue_node< T, Compare, A >::heapify().

Here is the caller graph for this function:

◆ front()

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

Definition at line 130 of file _flow_graph_item_buffer_impl.h.

131  {
132  __TBB_ASSERT(my_item_valid(my_head), "attempt to fetch head non-item");
133  return get_my_item(my_head);
134  }

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

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

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

159  {
160  // test that we haven't made the structure inconsistent.
161  __TBB_ASSERT(capacity() >= my_tail - my_head, "total items exceed capacity");
163  while( new_size<minimum_size )
164  new_size*=2;
165 
166  buffer_item_type* new_array = allocator_type().allocate(new_size);
167 
168  // initialize validity to "no"
169  for( size_type i=0; i<new_size; ++i ) { new_array[i].second = no_item; }
170 
171  for( size_type i=my_head; i<my_tail; ++i) {
172  if(my_item_valid(i)) { // sequencer_node may have empty slots
173  // placement-new copy-construct; could be std::move
174  char *new_space = (char *)&(new_array[i&(new_size-1)].first);
175  (void)new(new_space) item_type(get_my_item(i));
176  new_array[i&(new_size-1)].second = item(i).second;
177  }
178  }
179 
180  clean_up_buffer(/*reset_pointers*/false);
181 
182  my_array = new_array;
184  }

Referenced by tbb::flow::interface11::sequencer_node< T, A >::internal_push(), internal::item_buffer< OutputTuple >::item_buffer(), tbb::flow::interface11::priority_queue_node< T, Compare, A >::prio_push(), internal::item_buffer< OutputTuple >::push_back(), and internal::item_buffer< OutputTuple >::reset().

Here is the caller graph for this function:

◆ item() [1/2]

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

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

98  {
99  __TBB_ASSERT(!my_item_valid(to), "Trying to move to a non-empty slot");
100  __TBB_ASSERT(my_item_valid(from), "Trying to move from an empty slot");
101  set_my_item(to, get_my_item(from)); // could have std::move semantics
102  destroy_item(from);
103 
104  }

Referenced by tbb::flow::interface11::priority_queue_node< T, Compare, A >::heapify(), and tbb::flow::interface11::priority_queue_node< T, Compare, A >::prio_pop().

Here is the caller graph for this function:

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

70 { return item(i).second == reserved_item; }

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

107  {
108 #if !TBB_DEPRECATED_SEQUENCER_DUPLICATES
109  if(my_item_valid(here)) return false;
110 #endif
111  set_my_item(here, me);
112  return true;
113  }

Referenced by tbb::flow::interface11::priority_queue_node< T, Compare, A >::heapify(), tbb::flow::interface11::sequencer_node< T, A >::internal_push(), and tbb::flow::interface11::priority_queue_node< T, Compare, A >::prio_push().

Here is the caller graph for this function:

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

195  {
196  if (!my_item_valid(my_tail-1)) {
197  return false;
198  }
199  v = this->back();
200  destroy_back();
201  return true;
202  }

Referenced by tbb::flow::interface11::buffer_node< T, A >::internal_pop().

Here is the caller graph for this function:

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

204  {
205  if(!my_item_valid(my_head)) {
206  return false;
207  }
208  v = this->front();
209  destroy_front();
210  return true;
211  }

Referenced by tbb::flow::interface11::queue_node< T, A >::internal_pop(), and 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 186 of file _flow_graph_item_buffer_impl.h.

186  {
187  if(buffer_full()) {
188  grow_my_array(size() + 1);
189  }
190  set_my_item(my_tail, v);
191  ++my_tail;
192  return true;
193  }

Referenced by tbb::flow::interface11::buffer_node< T, A >::internal_push(), 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 145 of file _flow_graph_item_buffer_impl.h.

145 { __TBB_ASSERT(my_item_reserved(i), "item is not reserved"); item(i).second = has_item; }

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

144 { __TBB_ASSERT(my_item_valid(i) && !my_item_reserved(i), "item cannot be reserved"); item(i).second = reserved_item; }

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

Definition at line 80 of file _flow_graph_item_buffer_impl.h.

80  {
81  if(item(i).second != no_item) {
82  destroy_item(i);
83  }
84  new(&(item(i).first)) item_type(o);
85  item(i).second = has_item;
86  }

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

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

Referenced by internal::item_buffer< OutputTuple >::buffer_full(), tbb::flow::interface11::sequencer_node< T, A >::internal_push(), 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 116 of file _flow_graph_item_buffer_impl.h.

116  {
117  __TBB_ASSERT(my_item_valid(i) && my_item_valid(j), "attempt to swap invalid item(s)");
118  item_type temp = get_my_item(i);
119  set_my_item(i, get_my_item(j));
120  set_my_item(j, temp);
121  }

Referenced by tbb::flow::interface11::priority_queue_node< T, Compare, A >::reheap().

Here is the caller graph for this function:

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:
internal::item_buffer::destroy_item
void destroy_item(size_type i)
Definition: _flow_graph_item_buffer_impl.h:123
internal::type_plus_align::first
char first[sizeof(T1)]
Definition: _flow_graph_types_impl.h:392
internal::item_buffer::reserved_item
Definition: _flow_graph_item_buffer_impl.h:43
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
internal::item_buffer::my_head
size_type my_head
Definition: _flow_graph_item_buffer_impl.h:52
tbb::internal::first
auto first(Container &c) -> decltype(begin(c))
Definition: _range_iterator.h:34
internal::item_buffer::front
const item_type & front() const
Definition: _flow_graph_item_buffer_impl.h:130
internal::item_buffer::item_type
T item_type
Definition: _flow_graph_item_buffer_impl.h:42
void
void
Definition: ittnotify_static.h:76
internal::item_buffer::my_array
buffer_item_type * my_array
Definition: _flow_graph_item_buffer_impl.h:49
internal::item_buffer::grow_my_array
void grow_my_array(size_t minimum_size)
Grows the internal array.
Definition: _flow_graph_item_buffer_impl.h:159
new_size
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
Definition: ittnotify_static.h:148
internal::type_plus_align::second
T2 second
Definition: _flow_graph_types_impl.h:393
internal::item_buffer::destroy_front
void destroy_front()
Definition: _flow_graph_item_buffer_impl.h:147
internal::item_buffer::back
const item_type & back() const
Definition: _flow_graph_item_buffer_impl.h:137
internal::alignment_of
Definition: _flow_graph_types_impl.h:403
internal::item_buffer::buffer_item_type
aligned_pair< item_type, buffer_item_state >::type buffer_item_type
Definition: _flow_graph_item_buffer_impl.h:46
internal::item_buffer::my_tail
size_type my_tail
Definition: _flow_graph_item_buffer_impl.h:53
internal::item_buffer::initial_buffer_size
static const size_type initial_buffer_size
Definition: _flow_graph_item_buffer_impl.h:51
internal::item_buffer::buffer_full
bool buffer_full()
Definition: _flow_graph_item_buffer_impl.h:156
internal::item_buffer::my_array_size
size_type my_array_size
Definition: _flow_graph_item_buffer_impl.h:50
internal::item_buffer::set_my_item
void set_my_item(size_t i, const item_type &o)
Definition: _flow_graph_item_buffer_impl.h:80
internal::item_buffer::clean_up_buffer
void clean_up_buffer(bool reset_pointers)
Definition: _flow_graph_item_buffer_impl.h:215
internal::item_buffer::get_my_item
const item_type & get_my_item(size_t i) const
Definition: _flow_graph_item_buffer_impl.h:73
internal::item_buffer::my_item_valid
bool my_item_valid(size_type i) const
Definition: _flow_graph_item_buffer_impl.h:69
internal::item_buffer::size_type
size_t size_type
Definition: _flow_graph_item_buffer_impl.h:45
internal::item_buffer::destroy_back
void destroy_back()
Definition: _flow_graph_item_buffer_impl.h:148
internal::item_buffer::no_item
Definition: _flow_graph_item_buffer_impl.h:43
internal::item_buffer::capacity
size_type capacity()
Definition: _flow_graph_item_buffer_impl.h:153
internal::item_buffer::my_item_reserved
bool my_item_reserved(size_type i) const
Definition: _flow_graph_item_buffer_impl.h:70
internal::item_buffer::item
buffer_item_type & item(size_type i)
Definition: _flow_graph_item_buffer_impl.h:57
internal::item_buffer::has_item
Definition: _flow_graph_item_buffer_impl.h:43
internal::item_buffer::allocator_type
A::template rebind< buffer_item_type >::other allocator_type
Definition: _flow_graph_item_buffer_impl.h:47
internal::item_buffer::size
size_type size(size_t new_tail=0)
Definition: _flow_graph_item_buffer_impl.h:152

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.