STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax > Class Template Reference

The concurrent_priority_queue class is a container that allows multiple threads to concurrently push and pop items. Items are popped in priority order where priority is determined by a functor supplied as a template argument. More...

#include <concurrent_priority_queue.h>

Classes

class  _Cpq_operation
 
class  _My_functor_type
 

Public Types

typedef _Ty value_type
 A type that represents the data type stored in a concurrent priority queue. More...
 
typedef _Ty & reference
 A type that represents a reference to an element of the type stored in a concurrent priority queue. More...
 
typedef const _Ty & const_reference
 A type that represents a const reference to an element of the type stored in a concurrent priority queue. More...
 
typedef size_t size_type
 A type that counts the number of elements in a concurrent priority queue. More...
 
typedef _Ax allocator_type
 A type that represents the allocator class for the concurrent priority queue. More...
 

Public Member Functions

 concurrent_priority_queue (const allocator_type &_Al=allocator_type())
 Constructs a concurrent priority queue. More...
 
 concurrent_priority_queue (size_type _Init_capacity, const allocator_type &_Al=allocator_type())
 Constructs a concurrent priority queue. More...
 
template<typename _InputIterator >
 concurrent_priority_queue (_InputIterator _Begin, _InputIterator _End, const allocator_type &_Al=allocator_type())
 Constructs a concurrent priority queue. More...
 
 concurrent_priority_queue (const concurrent_priority_queue &_Src)
 Constructs a concurrent priority queue. More...
 
 concurrent_priority_queue (const concurrent_priority_queue &_Src, const allocator_type &_Al)
 Constructs a concurrent priority queue. More...
 
 concurrent_priority_queue (concurrent_priority_queue &&_Src)
 Constructs a concurrent priority queue. More...
 
 concurrent_priority_queue (concurrent_priority_queue &&_Src, const allocator_type &_Al)
 Constructs a concurrent priority queue. More...
 
concurrent_priority_queueoperator= (const concurrent_priority_queue &_Src)
 Assigns the contents of another concurrent_priority_queue object to this one. This method is not concurrency-safe. More...
 
concurrent_priority_queueoperator= (concurrent_priority_queue &&_Src)
 Assigns the contents of another concurrent_priority_queue object to this one. This method is not concurrency-safe. More...
 
bool empty () const
 Tests if the concurrent priority queue is empty at the time this method is called. This method is concurrency-safe. More...
 
size_type size () const
 Returns the number of elements in the concurrent priority queue. This method is concurrency-safe. More...
 
void push (const value_type &_Elem)
 Adds an element to the concurrent priority queue. This method is concurrency-safe. More...
 
void push (value_type &&_Elem)
 Adds an element to the concurrent priority queue. This method is concurrency-safe. More...
 
bool try_pop (reference _Elem)
 Removes and returns the highest priority element from the queue if the queue is non-empty. This method is concurrency-safe. More...
 
void clear ()
 Erases all elements in the concurrent priority. This method is not concurrency-safe. More...
 
void swap (concurrent_priority_queue &_Queue)
 Swaps the contents of two concurrent priority queues. This method is not concurrency-safe. More...
 
allocator_type get_allocator () const
 Returns a copy of the allocator used to construct the concurrent priority queue. This method is concurrency-safe. More...
 

Private Types

enum  _Operation_type { _INVALID_OP, _PUSH_OP_COPY, _PUSH_OP_MOVE, _POP_OP }
 
enum  _Operation_status { _WAIT =0, _SUCCEEDED, _FAILED }
 

Private Member Functions

void _M_handle_operations (_Cpq_operation *_POp_list)
 Handle a batch of operations pending on the concurrent priority queue. Only one thread can execute this routine at a time. More...
 
void _Heapify ()
 Merge unsorted elements into heap. More...
 
void _Reheap ()
 Re-_Heapify by pushing last element down the heap from the root. More...
 

Private Attributes

::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type_M_my_aggregator
 
char _M_padding1 [64-sizeof(::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type >)]
 
size_type _M_mark
 
volatile size_type _M_size
 
_Compare _M_compare
 
char _M_padding2 [64-sizeof(size_type)-sizeof(_Compare)]
 
std::vector< value_type, allocator_type_M_data
 

Detailed Description

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
class Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >

The concurrent_priority_queue class is a container that allows multiple threads to concurrently push and pop items. Items are popped in priority order where priority is determined by a functor supplied as a template argument.

Template Parameters
_TyThe data type of the elements to be stored in the priority queue.
_CompareThe type of the function object that can compare two element values as sort keys to determine their relative order in the priority queue. This argument is optional and the binary predicate less<_Ty > is the default value.
_AxThe type that represents the stored allocator object that encapsulates details about the allocation and deallocation of memory for the concurrent priority queue. This argument is optional and the default value is allocator<_Ty >.

For detailed information on the concurrent_priority_queue class, see Parallel Containers and Objects.

See also
Parallel Containers and Objects

Member Typedef Documentation

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
typedef _Ax Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::allocator_type

A type that represents the allocator class for the concurrent priority queue.

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
typedef const _Ty& Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::const_reference

A type that represents a const reference to an element of the type stored in a concurrent priority queue.

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
typedef _Ty& Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::reference

A type that represents a reference to an element of the type stored in a concurrent priority queue.

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
typedef size_t Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::size_type

A type that counts the number of elements in a concurrent priority queue.

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
typedef _Ty Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::value_type

A type that represents the data type stored in a concurrent priority queue.

Member Enumeration Documentation

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
enum Concurrency::concurrent_priority_queue::_Operation_status
private
Enumerator
_WAIT 
_SUCCEEDED 
_FAILED 
576 { _WAIT=0, _SUCCEEDED, _FAILED };
Definition: concurrent_priority_queue.h:576
Definition: concurrent_priority_queue.h:576
Definition: concurrent_priority_queue.h:576
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
enum Concurrency::concurrent_priority_queue::_Operation_type
private
Enumerator
_INVALID_OP 
_PUSH_OP_COPY 
_PUSH_OP_MOVE 
_POP_OP 
Definition: concurrent_priority_queue.h:575
Definition: concurrent_priority_queue.h:575
Definition: concurrent_priority_queue.h:575
Definition: concurrent_priority_queue.h:575

Constructor & Destructor Documentation

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::concurrent_priority_queue ( const allocator_type _Al = allocator_type())
inlineexplicit

Constructs a concurrent priority queue.

Parameters
_AlThe allocator class to use with this object.

All constructors store an allocator object _Al and initialize the priority queue.

The first constructor specifies an empty initial priority queue and optionally specifies an allocator.

The second constructor specifies a priority queue with an initial capacity _Init_capacity and optionally specifies an allocator.

The third constructor specifies values supplied by the iterator range [_Begin , _End ) and optionally specifies an allocator.

The fourth and fifth constructors specify a copy of the priority queue _Src .

The sixth and seventh constructors specify a move of the priority queue _Src .

239  : _M_mark(0), _M_size(0), _M_data(_Al)
240  {
241  _M_my_aggregator._Initialize_handler(_My_functor_type(this));
242  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::concurrent_priority_queue ( size_type  _Init_capacity,
const allocator_type _Al = allocator_type() 
)
inlineexplicit

Constructs a concurrent priority queue.

Parameters
_Init_capacityThe initial capacity of the concurrent_priority_queue object.
_AlThe allocator class to use with this object.

All constructors store an allocator object _Al and initialize the priority queue.

The first constructor specifies an empty initial priority queue and optionally specifies an allocator.

The second constructor specifies a priority queue with an initial capacity _Init_capacity and optionally specifies an allocator.

The third constructor specifies values supplied by the iterator range [_Begin , _End ) and optionally specifies an allocator.

The fourth and fifth constructors specify a copy of the priority queue _Src .

The sixth and seventh constructors specify a move of the priority queue _Src .

264  : _M_mark(0), _M_size(0), _M_data(_Al)
265  {
266  _M_data.reserve(_Init_capacity);
267  _M_my_aggregator._Initialize_handler(_My_functor_type(this));
268  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
template<typename _InputIterator >
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::concurrent_priority_queue ( _InputIterator  _Begin,
_InputIterator  _End,
const allocator_type _Al = allocator_type() 
)
inline

Constructs a concurrent priority queue.

Template Parameters
_InputIteratorThe type of the input iterator.
Parameters
_BeginThe position of the first element in the range of elements to be copied.
_EndThe position of the first element beyond the range of elements to be copied.
_AlThe allocator class to use with this object.

All constructors store an allocator object _Al and initialize the priority queue.

The first constructor specifies an empty initial priority queue and optionally specifies an allocator.

The second constructor specifies a priority queue with an initial capacity _Init_capacity and optionally specifies an allocator.

The third constructor specifies values supplied by the iterator range [_Begin , _End ) and optionally specifies an allocator.

The fourth and fifth constructors specify a copy of the priority queue _Src .

The sixth and seventh constructors specify a move of the priority queue _Src .

297  : _M_data(_Begin, _End, _Al)
298  {
299  // Set the mark to 0 to indicate that nothing is sorted.
300  _M_mark = 0;
301  _M_size = _M_data.size();
302  _M_my_aggregator._Initialize_handler(_My_functor_type(this));
303  _Heapify();
304  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
void _Heapify()
Merge unsorted elements into heap.
Definition: concurrent_priority_queue.h:755
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::concurrent_priority_queue ( const concurrent_priority_queue< _Ty, _Compare, _Ax > &  _Src)
inline

Constructs a concurrent priority queue.

Parameters
_SrcThe source concurrent_priority_queue object to copy or move elements from.

All constructors store an allocator object _Al and initialize the priority queue.

The first constructor specifies an empty initial priority queue and optionally specifies an allocator.

The second constructor specifies a priority queue with an initial capacity _Init_capacity and optionally specifies an allocator.

The third constructor specifies values supplied by the iterator range [_Begin , _End ) and optionally specifies an allocator.

The fourth and fifth constructors specify a copy of the priority queue _Src .

The sixth and seventh constructors specify a move of the priority queue _Src .

323  : _M_mark(_Src._M_mark), _M_size(_Src._M_size), _M_data(_Src._M_data)
324  {
325  _M_my_aggregator._Initialize_handler(_My_functor_type(this));
326  _Heapify();
327  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
void _Heapify()
Merge unsorted elements into heap.
Definition: concurrent_priority_queue.h:755
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::concurrent_priority_queue ( const concurrent_priority_queue< _Ty, _Compare, _Ax > &  _Src,
const allocator_type _Al 
)
inline

Constructs a concurrent priority queue.

Parameters
_SrcThe source concurrent_priority_queue object to copy or move elements from.
_AlThe allocator class to use with this object.

All constructors store an allocator object _Al and initialize the priority queue.

The first constructor specifies an empty initial priority queue and optionally specifies an allocator.

The second constructor specifies a priority queue with an initial capacity _Init_capacity and optionally specifies an allocator.

The third constructor specifies values supplied by the iterator range [_Begin , _End ) and optionally specifies an allocator.

The fourth and fifth constructors specify a copy of the priority queue _Src .

The sixth and seventh constructors specify a move of the priority queue _Src .

349  : _M_mark(_Src._M_mark), _M_data(_Src._M_data.begin(), _Src._M_data.end(), _Al)
350  {
351  _M_size = _M_data.size();
352  _M_my_aggregator._Initialize_handler(_My_functor_type(this));
353  _Heapify();
354  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
void _Heapify()
Merge unsorted elements into heap.
Definition: concurrent_priority_queue.h:755
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::concurrent_priority_queue ( concurrent_priority_queue< _Ty, _Compare, _Ax > &&  _Src)
inline

Constructs a concurrent priority queue.

Parameters
_SrcThe source concurrent_priority_queue object to copy or move elements from.

All constructors store an allocator object _Al and initialize the priority queue.

The first constructor specifies an empty initial priority queue and optionally specifies an allocator.

The second constructor specifies a priority queue with an initial capacity _Init_capacity and optionally specifies an allocator.

The third constructor specifies values supplied by the iterator range [_Begin , _End ) and optionally specifies an allocator.

The fourth and fifth constructors specify a copy of the priority queue _Src .

The sixth and seventh constructors specify a move of the priority queue _Src .

373  : _M_mark(_Src._M_mark), _M_size(_Src._M_size), _M_data(std::move(_Src._M_data))
374  {
375  // Set _M_mark and _M_size for the argument to 0 because its data has been moved over to this priority queue.
376  _Src._M_mark = 0;
377  _Src._M_size = 0;
378  _M_my_aggregator._Initialize_handler(_My_functor_type(this));
379  _Heapify();
380  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
void _Heapify()
Merge unsorted elements into heap.
Definition: concurrent_priority_queue.h:755
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::concurrent_priority_queue ( concurrent_priority_queue< _Ty, _Compare, _Ax > &&  _Src,
const allocator_type _Al 
)
inline

Constructs a concurrent priority queue.

Parameters
_SrcThe source concurrent_priority_queue object to copy or move elements from.
_AlThe allocator class to use with this object.

All constructors store an allocator object _Al and initialize the priority queue.

The first constructor specifies an empty initial priority queue and optionally specifies an allocator.

The second constructor specifies a priority queue with an initial capacity _Init_capacity and optionally specifies an allocator.

The third constructor specifies values supplied by the iterator range [_Begin , _End ) and optionally specifies an allocator.

The fourth and fifth constructors specify a copy of the priority queue _Src .

The sixth and seventh constructors specify a move of the priority queue _Src .

402  : _M_mark(_Src._M_mark), _M_size(_Src._M_size), _M_data(std::move(_Src._M_data), _Al)
403  {
404  // Set _M_mark and _M_size for the argument to 0 because its data has been moved over to this priority queue.
405  _Src._M_mark = 0;
406  _Src._M_size = 0;
407  _M_my_aggregator._Initialize_handler(_My_functor_type(this));
408  _Heapify();
409  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
void _Heapify()
Merge unsorted elements into heap.
Definition: concurrent_priority_queue.h:755
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290

Member Function Documentation

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
void Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_Heapify ( )
inlineprivate

Merge unsorted elements into heap.

756  {
757  if (_M_mark == 0 && _M_size > 0)
758  {
759  _M_mark = 1;
760  }
761 
762  for (; _M_mark < _M_size; ++_M_mark)
763  {
764  // for each unheapified element under size
765  size_type _Cur_pos = _M_mark;
766  value_type _To_place = std::move(_M_data[_M_mark]);
767  do
768  { // push _To_place up the heap
769  size_type _Parent = (_Cur_pos - 1) >> 1;
770  if (!_M_compare(_M_data[_Parent], _To_place))
771  {
772  break;
773  }
774  _M_data[_Cur_pos] = std::move(_M_data[_Parent]);
775  _Cur_pos = _Parent;
776 
777  } while( _Cur_pos != 0 );
778 
779  _M_data[_Cur_pos] = std::move(_To_place);
780  }
781  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
size_t size_type
A type that counts the number of elements in a concurrent priority queue.
Definition: concurrent_priority_queue.h:214
_Ty value_type
A type that represents the data type stored in a concurrent priority queue.
Definition: concurrent_priority_queue.h:196
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
_Compare _M_compare
Definition: concurrent_priority_queue.h:621
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
void Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_handle_operations ( _Cpq_operation _POp_list)
inlineprivate

Handle a batch of operations pending on the concurrent priority queue. Only one thread can execute this routine at a time.

647  {
648  _Cpq_operation *_PTmp, *_PPop_list=NULL;
649 
650  _CONCRT_ASSERT(_M_mark == _M_data.size());
651 
652  // First pass processes all constant time operations: pushes, some pops.
653  while (_POp_list != NULL)
654  {
655  _CONCRT_ASSERT(_POp_list->_M_type != _INVALID_OP);
656  _PTmp = _POp_list;
657  _POp_list = _POp_list->_M_pNext;
658  if (_PTmp->_M_type == _PUSH_OP_COPY)
659  {
660  try
661  {
662  _M_data.push_back(*(_PTmp->_M_elem));
663  ++_M_size;
664  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _SUCCEEDED);
665  }
666  catch (...)
667  {
668  _PTmp->_M_exception_ptr = std::current_exception();
669  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _FAILED);
670  }
671  }
672  else if (_PTmp->_M_type == _PUSH_OP_MOVE)
673  {
674  try
675  {
676  _M_data.push_back(std::move(*(_PTmp->_M_elem)));
677  ++_M_size;
678  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _SUCCEEDED);
679  }
680  catch (...)
681  {
682  _PTmp->_M_exception_ptr = std::current_exception();
683  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _FAILED);
684  }
685  }
686  else
687  {
688  _CONCRT_ASSERT(_PTmp->_M_type == _POP_OP);
689  if (_M_mark < _M_size && _M_compare(_M_data[0], _M_data[_M_size - 1]))
690  {
691  // There are newly pushed elems and the last one is higher than top
692  // Because we're going to pop the last element, we can move the _M_data instead of copying it.
693  *(_PTmp->_M_elem) = std::move(_M_data[_M_size - 1]);
694  --_M_size;
695  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _SUCCEEDED);
696  _M_data.pop_back();
697 
699  }
700  else
701  {
702  // No convenient item to pop; postpone
703  _PTmp->_M_pNext = _PPop_list;
704  _PPop_list = _PTmp;
705  }
706  }
707  }
708 
709  // Second pass processes pop operations.
710  while (_PPop_list != NULL)
711  {
712  _PTmp = _PPop_list;
713  _PPop_list = _PPop_list->_M_pNext;
714  _CONCRT_ASSERT(_PTmp->_M_type == _POP_OP);
715 
716  if (_M_size == 0)
717  {
718  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _FAILED);
719  }
720  else
721  {
723 
724  if (_M_mark < _M_size && _M_compare(_M_data[0], _M_data[_M_size - 1]))
725  {
726  // There are newly pushed elems and the last one is higher than top.
727  // Because we're going to pop the last element, we can move the _M_data instead of copying it.
728  *(_PTmp->_M_elem) = std::move(_M_data[_M_size - 1]); // copy the _M_data
729  --_M_size;
730  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _SUCCEEDED);
731  _M_data.pop_back();
732  }
733  else
734  {
735  // Extract top and push last element down heap.
736  *(_PTmp->_M_elem) = std::move(_M_data[0]); // copy the _M_data
737  --_M_size;
738  _InterlockedExchange((volatile long *) &_PTmp->_M_status, _SUCCEEDED);
739  _Reheap();
740  }
741  }
742  }
743  _CONCRT_ASSERT(_M_size == _M_data.size());
744  // _Heapify any leftover pushed elements before doing the next batch of operations.
745  if (_M_mark < _M_size)
746  {
747  _Heapify();
748  }
750  }
Definition: concurrent_priority_queue.h:575
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
Definition: concurrent_priority_queue.h:576
Definition: concurrent_priority_queue.h:575
Definition: concurrent_priority_queue.h:576
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
Definition: concurrent_priority_queue.h:575
void _Heapify()
Merge unsorted elements into heap.
Definition: concurrent_priority_queue.h:755
void _Reheap()
Re-_Heapify by pushing last element down the heap from the root.
Definition: concurrent_priority_queue.h:786
Definition: concurrent_priority_queue.h:575
_Compare _M_compare
Definition: concurrent_priority_queue.h:621
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
exception_ptr current_exception() _NOEXCEPT
Definition: exception:359
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
void Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_Reheap ( )
inlineprivate

Re-_Heapify by pushing last element down the heap from the root.

787  {
788  size_type _Cur_pos=0, _Child=1;
789  // Use _M_data.size() instead of _M_size throughout this function, because _M_size has already
790  // been decremented to account for the pop right before Reheap was invoked.
791  while (_Child < _M_mark)
792  {
793  size_type _Target = _Child;
794  if (_Child + 1 < _M_mark && _M_compare(_M_data[_Child], _M_data[_Child + 1]))
795  {
796  ++_Target;
797  }
798  // _Target now has the higher priority _Child.
799  if (_M_compare(_M_data[_Target], _M_data[_M_data.size() - 1]))
800  {
801  break;
802  }
803 
804  _M_data[_Cur_pos] = std::move(_M_data[_Target]);
805  _Cur_pos = _Target;
806  _Child = (_Cur_pos << 1) + 1;
807  }
808 
809  _M_data[_Cur_pos] = std::move(_M_data[_M_data.size() - 1]);
810  _M_data.pop_back();
811 
812  if (_M_mark > _M_data.size())
813  {
814  _M_mark = _M_data.size();
815  }
816  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
size_t size_type
A type that counts the number of elements in a concurrent priority queue.
Definition: concurrent_priority_queue.h:214
const void * _Target(const _XSTD2 type_info &_Info) const _NOEXCEPT
Definition: functional:413
size_type _M_mark
Definition: concurrent_priority_queue.h:614
_Compare _M_compare
Definition: concurrent_priority_queue.h:621
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
void Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::clear ( )
inline

Erases all elements in the concurrent priority. This method is not concurrency-safe.

clear is not concurrency-safe. You must ensure that no other threads are invoking methods on the concurrent priority queue when you call this method. clear does not free memory.

545  {
546  _M_data.clear();
547  _M_mark = 0;
548  _M_size = 0;
549  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
bool Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::empty ( ) const
inline

Tests if the concurrent priority queue is empty at the time this method is called. This method is concurrency-safe.

Returns
true if the priority queue was empty at the moment the function was called, false otherwise.
464  {
465  return (_M_size == 0);
466  }
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
allocator_type Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::get_allocator ( ) const
inline

Returns a copy of the allocator used to construct the concurrent priority queue. This method is concurrency-safe.

Returns
A copy of the allocator used to construct the concurrent_priority_queue object.
572 { return _M_data.get_allocator(); }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
concurrent_priority_queue& Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::operator= ( const concurrent_priority_queue< _Ty, _Compare, _Ax > &  _Src)
inline

Assigns the contents of another concurrent_priority_queue object to this one. This method is not concurrency-safe.

Parameters
_SrcThe source concurrent_priority_queue object.
Returns
A reference to this concurrent_priority_queue object.
422  {
423  if (this != &_Src)
424  {
425  std::vector<value_type, allocator_type>(_Src._M_data.begin(), _Src._M_data.end(), _Src._M_data.get_allocator()).swap(_M_data);
426  _M_mark = _Src._M_mark;
427  _M_size = _Src._M_size;
428  }
429  return *this;
430  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
void swap(concurrent_priority_queue &_Queue)
Swaps the contents of two concurrent priority queues. This method is not concurrency-safe.
Definition: concurrent_priority_queue.h:558
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
concurrent_priority_queue& Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::operator= ( concurrent_priority_queue< _Ty, _Compare, _Ax > &&  _Src)
inline

Assigns the contents of another concurrent_priority_queue object to this one. This method is not concurrency-safe.

Parameters
_SrcThe source concurrent_priority_queue object.
Returns
A reference to this concurrent_priority_queue object.
443  {
444  if (this != &_Src)
445  {
446  _M_data = std::move(_Src._M_data);
447  _M_mark = _Src._M_mark;
448  _M_size = _Src._M_size;
449  // Set _M_mark and _M_size for the arguement to 0 because its data has been moved over to this priority queue.
450  _Src._M_mark = 0;
451  _Src._M_size = 0;
452  }
453  return *this;
454  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
void Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::push ( const value_type _Elem)
inline

Adds an element to the concurrent priority queue. This method is concurrency-safe.

Parameters
_ElemThe element to be added to the concurrent priority queue.
491  {
492  _Cpq_operation _Op_data(_Elem, _PUSH_OP_COPY);
493  _M_my_aggregator._Execute(&_Op_data);
494  if (_Op_data._M_status == _FAILED)
495  {
496  // Rethrow the saved exception.
497  std::rethrow_exception(_Op_data._M_exception_ptr);
498  }
499  }
Definition: concurrent_priority_queue.h:576
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
Definition: concurrent_priority_queue.h:575
void rethrow_exception(_In_ exception_ptr _Ptr)
Definition: exception:364
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
void Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::push ( value_type &&  _Elem)
inline

Adds an element to the concurrent priority queue. This method is concurrency-safe.

Parameters
_ElemThe element to be added to the concurrent priority queue.
508  {
509  _Cpq_operation _Op_data(_Elem, _PUSH_OP_MOVE);
510  _M_my_aggregator._Execute(&_Op_data);
511  if (_Op_data._M_status == _FAILED)
512  {
513  // Rethrow the saved exception
514  std::rethrow_exception(_Op_data._M_exception_ptr);
515  }
516  }
Definition: concurrent_priority_queue.h:576
Definition: concurrent_priority_queue.h:575
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608
void rethrow_exception(_In_ exception_ptr _Ptr)
Definition: exception:364
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
size_type Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::size ( ) const
inline

Returns the number of elements in the concurrent priority queue. This method is concurrency-safe.

Returns
The number of elements in this concurrent_priority_queue object.

The returned size is guaranteed to include all elements added by calls to the function push. However, it may not reflect results of pending concurrent operations.

480  {
481  return _M_size;
482  }
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
void Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::swap ( concurrent_priority_queue< _Ty, _Compare, _Ax > &  _Queue)
inline

Swaps the contents of two concurrent priority queues. This method is not concurrency-safe.

Parameters
_QueueThe concurrent_priority_queue object to swap contents with.
559  {
560  _M_data.swap(_Queue._M_data);
561  std::swap(_M_mark, _Queue._M_mark);
562  std::swap(_M_size, _Queue._M_size);
563  }
std::vector< value_type, allocator_type > _M_data
Definition: concurrent_priority_queue.h:641
void swap(array< _Ty, _Size > &_Left, array< _Ty, _Size > &_Right) _NOEXCEPT_OP(_NOEXCEPT_OP(_Left.swap(_Right)))
Definition: array:433
volatile size_type _M_size
Definition: concurrent_priority_queue.h:618
size_type _M_mark
Definition: concurrent_priority_queue.h:614
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
bool Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::try_pop ( reference  _Elem)
inline

Removes and returns the highest priority element from the queue if the queue is non-empty. This method is concurrency-safe.

Parameters
_ElemA reference to a variable that will be populated with the highest priority element, if the queue is non-empty.
Returns
true if a value was popped, false otherwise.
529  {
530  _Cpq_operation _Op_data(_POP_OP);
531  _Op_data._M_elem = &_Elem;
532  _M_my_aggregator._Execute(&_Op_data);
533  return (_Op_data._M_status == _SUCCEEDED);
534  }
Definition: concurrent_priority_queue.h:575
Definition: concurrent_priority_queue.h:576
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > _M_my_aggregator
Definition: concurrent_priority_queue.h:608

Member Data Documentation

template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
_Compare Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_compare
private
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
std::vector<value_type, allocator_type> Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_data
private
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
size_type Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_mark
private
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type > Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_my_aggregator
private
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
char Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_padding1[64-sizeof(::Concurrency::details::_Aggregator< _Cpq_operation, _My_functor_type >)]
private
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
char Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_padding2[64-sizeof(size_type)-sizeof(_Compare)]
private
template<typename _Ty, typename _Compare = std::less<_Ty>, typename _Ax = std::allocator<_Ty>>
volatile size_type Concurrency::concurrent_priority_queue< _Ty, _Compare, _Ax >::_M_size
private

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