STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Concurrency::details::_Aggregator< _Operation_type, _Handler_type > Class Template Reference

An aggregator for collecting operations coming from multiple sources and executing them serially on a single thread. _Operation_type must be derived from _Aggregated_operation. The parameter _Handler_type is a functor that will be passed the list of operations and is expected to handle each operation appropriately, setting the status of each operation to non-zero. More...

#include <concurrent_priority_queue.h>

Public Member Functions

 _Aggregator ()
 
 ~_Aggregator ()
 
void _Initialize_handler (_Handler_type _Handler)
 
void _Execute (_Operation_type *_Op)
 Place operation in list and either handle list or wait for operation to complete. More...
 

Private Member Functions

void _Start_handle_operations ()
 

Private Attributes

_Operation_type *volatile _M_pPending_operations
 
volatile long _M_handler_busy
 
_Handler_type _M_handle_operations
 

Detailed Description

template<typename _Operation_type, typename _Handler_type>
class Concurrency::details::_Aggregator< _Operation_type, _Handler_type >

An aggregator for collecting operations coming from multiple sources and executing them serially on a single thread. _Operation_type must be derived from _Aggregated_operation. The parameter _Handler_type is a functor that will be passed the list of operations and is expected to handle each operation appropriately, setting the status of each operation to non-zero.

Constructor & Destructor Documentation

template<typename _Operation_type, typename _Handler_type>
Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::_Aggregator ( )
inline
80  : _M_handler_busy(0)
81  {
83  }
volatile long _M_handler_busy
Definition: concurrent_priority_queue.h:131
_Operation_type *volatile _M_pPending_operations
Definition: concurrent_priority_queue.h:128
#define NULL
Definition: corecrt.h:158
template<typename _Operation_type, typename _Handler_type>
Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::~_Aggregator ( )
inline
86  {
87  }

Member Function Documentation

template<typename _Operation_type, typename _Handler_type>
void Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::_Execute ( _Operation_type *  _Op)
inline

Place operation in list and either handle list or wait for operation to complete.

98  {
99  _Operation_type *_Res;
100 
101  // Insert the operation in the queue
102  do
103  {
104  _Op->_M_pNext = _Res = _M_pPending_operations;
105  } while (_InterlockedCompareExchangePointer(reinterpret_cast<void *volatile *>(&_M_pPending_operations), _Op, _Res) != _Res);
106 
107  if (_Res == NULL)
108  {
109  // This item was the first one in the list; this thread will handle the operations. Note that by the time the
110  // thread pops the list of operations to handle, there may be several operations queued up.
112  _CONCRT_ASSERT(_Op->_M_status != 0);
113  }
114  else
115  {
116  // This item was not the first one on the list; a different thread is going to handle this operation, wait for
117  // the result to be ready.
119  while (_Op->_M_status == 0)
120  {
121  _SpinWait._SpinOnce();
122  }
123  }
124  }
Implements busy wait with no backoff
Definition: concrt.h:578
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
bool _SpinOnce()
Spins for one time quantum,until a maximum spin is reached.
Definition: concrt.h:626
void * _InterlockedCompareExchangePointer(void *volatile *, void *, void *)
void _Start_handle_operations()
Definition: concurrent_priority_queue.h:137
_Operation_type *volatile _M_pPending_operations
Definition: concurrent_priority_queue.h:128
#define NULL
Definition: corecrt.h:158
template<typename _Operation_type, typename _Handler_type>
void Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::_Initialize_handler ( _Handler_type  _Handler)
inline
90  {
91  _M_handle_operations = _Handler;
92  }
_Handler_type _M_handle_operations
Definition: concurrent_priority_queue.h:134
template<typename _Operation_type, typename _Handler_type>
void Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::_Start_handle_operations ( )
inlineprivate
138  {
139  _Operation_type * _POp_list;
140 
141  // Acquire the _M_handler_busy flag. Only one thread can possibly spin here at a time
143  while (_M_handler_busy == 1)
144  {
145  _SpinWait._SpinOnce();
146  }
147 
148  long _OldVal = _InterlockedExchange(&_M_handler_busy, 1);
149  _CONCRT_ASSERT(_OldVal == 0);
150 
151  // Get the list of pending operations
152  _POp_list = reinterpret_cast<_Operation_type *>(_InterlockedExchangePointer(reinterpret_cast<void * volatile *>(&_M_pPending_operations), NULL));
153 
154  // Handle all the operations
155  _M_handle_operations(_POp_list);
156 
157  // Release the handler
158  _OldVal = _InterlockedExchange(&_M_handler_busy, 0);
159  _CONCRT_ASSERT(_OldVal == 1);
160  }
Implements busy wait with no backoff
Definition: concrt.h:578
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
bool _SpinOnce()
Spins for one time quantum,until a maximum spin is reached.
Definition: concrt.h:626
volatile long _M_handler_busy
Definition: concurrent_priority_queue.h:131
_Handler_type _M_handle_operations
Definition: concurrent_priority_queue.h:134
_Operation_type *volatile _M_pPending_operations
Definition: concurrent_priority_queue.h:128
#define NULL
Definition: corecrt.h:158

Member Data Documentation

template<typename _Operation_type, typename _Handler_type>
_Handler_type Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::_M_handle_operations
private
template<typename _Operation_type, typename _Handler_type>
volatile long Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::_M_handler_busy
private
template<typename _Operation_type, typename _Handler_type>
_Operation_type* volatile Concurrency::details::_Aggregator< _Operation_type, _Handler_type >::_M_pPending_operations
private

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