STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
__gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp > Class Template Reference

Double-ended queue of bounded size, allowing lock-free atomic access. push_front() and pop_front() must not be called concurrently to each other, while pop_back() can be called concurrently at all times. empty(), size(), and top() are intentionally not provided. Calling them would not make sense in a concurrent setting. More...

#include <parallel/queue.h>

Public Member Functions

 _RestrictedBoundedConcurrentQueue (_SequenceIndex __max_size)
 Constructor. Not to be called concurrent, of course. More...
 
 ~_RestrictedBoundedConcurrentQueue ()
 Destructor. Not to be called concurrent, of course. More...
 
void push_front (const _Tp &__t)
 Pushes one element into the queue at the front end. Must not be called concurrently with pop_front(). More...
 
bool pop_front (_Tp &__t)
 Pops one element from the queue at the front end. Must not be called concurrently with pop_front(). More...
 
bool pop_back (_Tp &__t)
 Pops one element from the queue at the front end. Must not be called concurrently with pop_front(). More...
 

Private Attributes

_Tp * _M_base
 Array of elements, seen as cyclic buffer. More...
 
_SequenceIndex _M_max_size
 Maximal number of elements contained at the same time. More...
 
_GLIBCXX_VOLATILE _CASable _M_borders
 Cyclic __begin and __end pointers contained in one atomically changeable value. More...
 

Detailed Description

template<typename _Tp>
class __gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp >

Double-ended queue of bounded size, allowing lock-free atomic access. push_front() and pop_front() must not be called concurrently to each other, while pop_back() can be called concurrently at all times. empty(), size(), and top() are intentionally not provided. Calling them would not make sense in a concurrent setting.

Parameters
_TpContained element type.

Constructor & Destructor Documentation

Constructor. Not to be called concurrent, of course.

Parameters
__max_sizeMaximal number of elements to be contained.
69  {
70  _M_max_size = __max_size;
71  _M_base = new _Tp[__max_size];
72  _M_borders = __encode2(0, 0);
73 #pragma omp flush
74  }
_CASable __encode2(int __a, int __b)
Encode two integers into one gnu_parallel::_CASable.
Definition: base.h:119
_Tp * _M_base
Array of elements, seen as cyclic buffer.
Definition: queue.h:56
_SequenceIndex _M_max_size
Maximal number of elements contained at the same time.
Definition: queue.h:59
_GLIBCXX_VOLATILE _CASable _M_borders
Cyclic __begin and __end pointers contained in one atomically changeable value.
Definition: queue.h:63

Destructor. Not to be called concurrent, of course.

78  { delete[] _M_base; }
_Tp * _M_base
Array of elements, seen as cyclic buffer.
Definition: queue.h:56

Member Function Documentation

template<typename _Tp>
bool __gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp >::pop_back ( _Tp &  __t)
inline

Pops one element from the queue at the front end. Must not be called concurrently with pop_front().

128  {
129  int __former_front, __former_back;
130 #pragma omp flush
131  __decode2(_M_borders, __former_front, __former_back);
132  while (__former_front > __former_back)
133  {
134  // Chance.
135  _CASable __former_borders = __encode2(__former_front,
136  __former_back);
137  _CASable __new_borders = __encode2(__former_front,
138  __former_back + 1);
139  if (__compare_and_swap(&_M_borders, __former_borders,
140  __new_borders))
141  {
142  __t = *(_M_base + __former_back % _M_max_size);
143  return true;
144  }
145 #pragma omp flush
146  __decode2(_M_borders, __former_front, __former_back);
147  }
148  return false;
149  }
_CASable __encode2(int __a, int __b)
Encode two integers into one gnu_parallel::_CASable.
Definition: base.h:119
_Tp * _M_base
Array of elements, seen as cyclic buffer.
Definition: queue.h:56
_SequenceIndex _M_max_size
Maximal number of elements contained at the same time.
Definition: queue.h:59
void __decode2(_CASable __x, int &__a, int &__b)
Decode two integers from one gnu_parallel::_CASable.
Definition: base.h:133
_GLIBCXX_VOLATILE _CASable _M_borders
Cyclic __begin and __end pointers contained in one atomically changeable value.
Definition: queue.h:63
bool __compare_and_swap(volatile _Tp *__ptr, _Tp __comparand, _Tp __replacement)
Compare-and-swap.
Definition: compatibility.h:108
int64_t _CASable
Longest compare-and-swappable integer type on this platform.
Definition: types.h:127
template<typename _Tp>
bool __gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp >::pop_front ( _Tp &  __t)
inline

Pops one element from the queue at the front end. Must not be called concurrently with pop_front().

101  {
102  int __former_front, __former_back;
103 #pragma omp flush
104  __decode2(_M_borders, __former_front, __former_back);
105  while (__former_front > __former_back)
106  {
107  // Chance.
108  _CASable __former_borders = __encode2(__former_front,
109  __former_back);
110  _CASable __new_borders = __encode2(__former_front - 1,
111  __former_back);
112  if (__compare_and_swap(&_M_borders, __former_borders,
113  __new_borders))
114  {
115  __t = *(_M_base + (__former_front - 1) % _M_max_size);
116  return true;
117  }
118 #pragma omp flush
119  __decode2(_M_borders, __former_front, __former_back);
120  }
121  return false;
122  }
_CASable __encode2(int __a, int __b)
Encode two integers into one gnu_parallel::_CASable.
Definition: base.h:119
_Tp * _M_base
Array of elements, seen as cyclic buffer.
Definition: queue.h:56
_SequenceIndex _M_max_size
Maximal number of elements contained at the same time.
Definition: queue.h:59
void __decode2(_CASable __x, int &__a, int &__b)
Decode two integers from one gnu_parallel::_CASable.
Definition: base.h:133
_GLIBCXX_VOLATILE _CASable _M_borders
Cyclic __begin and __end pointers contained in one atomically changeable value.
Definition: queue.h:63
bool __compare_and_swap(volatile _Tp *__ptr, _Tp __comparand, _Tp __replacement)
Compare-and-swap.
Definition: compatibility.h:108
int64_t _CASable
Longest compare-and-swappable integer type on this platform.
Definition: types.h:127
template<typename _Tp>
void __gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp >::push_front ( const _Tp &  __t)
inline

Pushes one element into the queue at the front end. Must not be called concurrently with pop_front().

84  {
85  _CASable __former_borders = _M_borders;
86  int __former_front, __former_back;
87  __decode2(__former_borders, __former_front, __former_back);
88  *(_M_base + __former_front % _M_max_size) = __t;
89 #if _GLIBCXX_ASSERTIONS
90  // Otherwise: front - back > _M_max_size eventually.
91  _GLIBCXX_PARALLEL_ASSERT(((__former_front + 1) - __former_back)
92  <= _M_max_size);
93 #endif
95  }
_CASable __encode2(int __a, int __b)
Encode two integers into one gnu_parallel::_CASable.
Definition: base.h:119
_Tp __fetch_and_add(volatile _Tp *__ptr, _Tp __addend)
Add a value to a variable, atomically.
Definition: compatibility.h:74
_Tp * _M_base
Array of elements, seen as cyclic buffer.
Definition: queue.h:56
_SequenceIndex _M_max_size
Maximal number of elements contained at the same time.
Definition: queue.h:59
void __decode2(_CASable __x, int &__a, int &__b)
Decode two integers from one gnu_parallel::_CASable.
Definition: base.h:133
#define _GLIBCXX_PARALLEL_ASSERT(_Condition)
Definition: base.h:422
_GLIBCXX_VOLATILE _CASable _M_borders
Cyclic __begin and __end pointers contained in one atomically changeable value.
Definition: queue.h:63
int64_t _CASable
Longest compare-and-swappable integer type on this platform.
Definition: types.h:127

Member Data Documentation

template<typename _Tp>
_Tp* __gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp >::_M_base
private

Array of elements, seen as cyclic buffer.

template<typename _Tp>
_GLIBCXX_VOLATILE _CASable __gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp >::_M_borders
private

Cyclic __begin and __end pointers contained in one atomically changeable value.

template<typename _Tp>
_SequenceIndex __gnu_parallel::_RestrictedBoundedConcurrentQueue< _Tp >::_M_max_size
private

Maximal number of elements contained at the same time.


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