STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
_Associated_state< _Ty > Class Template Reference

Classes

struct  _Test_ready
 

Public Types

typedef _Ty _State_type
 
typedef _Deleter_base< _Ty > _Mydel
 

Public Member Functions

 _Associated_state (_Mydel *_Dp=0)
 
virtual ~_Associated_state () _NOEXCEPT
 
void _Retain ()
 
void _Release ()
 
virtual void _Wait ()
 
template<class _Rep , class _Per >
_Future_status _Wait_for (const chrono::duration< _Rep, _Per > &_Rel_time)
 
template<class _Clock , class _Dur >
_Future_status _Wait_until (const chrono::time_point< _Clock, _Dur > &_Abs_time)
 
virtual _Ty & _Get_value (bool _Get_only_once)
 
void _Set_value (const _Ty &_Val, bool _At_thread_exit)
 
void _Set_value_raw (const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
 
void _Set_value (_Ty &&_Val, bool _At_thread_exit)
 
void _Set_value_raw (_Ty &&_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
 
void _Set_value (bool _At_thread_exit)
 
void _Set_value_raw (unique_lock< mutex > *_Lock, bool _At_thread_exit)
 
void _Set_exception (exception_ptr _Exc, bool _At_thread_exit)
 
void _Set_exception_raw (exception_ptr _Exc, unique_lock< mutex > *_Lock, bool _At_thread_exit)
 
bool _Is_ready () const
 
bool _Is_ready_at_thread_exit () const
 
bool _Already_has_stored_result () const
 
bool _Already_retrieved () const
 
void _Abandon ()
 
 _Associated_state (const _Associated_state &)=delete
 
_Associated_stateoperator= (const _Associated_state &)=delete
 

Public Attributes

_Ty _Result
 
exception_ptr _Exception
 
mutex _Mtx
 
condition_variable _Cond
 
bool _Retrieved
 
int _Ready
 
bool _Ready_at_thread_exit
 
bool _Has_stored_result
 
bool _Running
 

Protected Member Functions

void _Make_ready_at_thread_exit ()
 
void _Maybe_run_deferred_function (unique_lock< mutex > &_Lock)
 

Private Member Functions

virtual bool _Has_deferred_function () const _NOEXCEPT
 
virtual void _Run_deferred_function (unique_lock< mutex > &)
 
virtual void _Do_notify (unique_lock< mutex > *_Lock, bool _At_thread_exit)
 
void _Delete_this ()
 

Private Attributes

_Atomic_counter_t _Refs
 
_Mydel_Deleter
 

Member Typedef Documentation

template<class _Ty>
typedef _Deleter_base<_Ty> _Associated_state< _Ty >::_Mydel
template<class _Ty>
typedef _Ty _Associated_state< _Ty >::_State_type

Constructor & Destructor Documentation

template<class _Ty>
_Associated_state< _Ty >::_Associated_state ( _Mydel _Dp = 0)
inline
255  : _Refs(1), // non-atomic initialization
256  _Exception(),
257  _Retrieved(false),
258  _Running(false),
259  _Ready(false),
260  _Ready_at_thread_exit(false),
261  _Has_stored_result(false),
262  _Deleter(_Dp)
263  { // construct
264  // TODO: _Associated_state ctor assumes _Ty is default constructible
265  }
exception_ptr _Exception
Definition: future:465
bool _Ready_at_thread_exit
Definition: future:470
bool _Running
Definition: future:472
_Atomic_counter_t _Refs
Definition: future:287
int _Ready
Definition: future:469
bool _Retrieved
Definition: future:468
bool _Has_stored_result
Definition: future:471
_Mydel * _Deleter
Definition: future:506
template<class _Ty>
virtual _Associated_state< _Ty >::~_Associated_state ( )
inlinevirtual
268  { // destroy
269  if (_Has_stored_result && !_Ready)
270  { // registered for release at thread exit
272  }
273  }
void _Unregister(mutex &_Mtx)
Definition: mutex:670
int _Ready
Definition: future:469
condition_variable _Cond
Definition: future:467
mutex _Mtx
Definition: future:466
bool _Has_stored_result
Definition: future:471
template<class _Ty>
_Associated_state< _Ty >::_Associated_state ( const _Associated_state< _Ty > &  )
delete

Member Function Documentation

template<class _Ty>
void _Associated_state< _Ty >::_Abandon ( )
inline
438  { // abandon shared state
439  unique_lock<mutex> _Lock(_Mtx);
440  if (!_Has_stored_result)
441  { // queue exception
443  _Set_exception_raw(_STD make_exception_ptr(_Fut), &_Lock, false);
444  }
445  }
Definition: mutex:259
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:119
void _Set_exception_raw(exception_ptr _Exc, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:407
Definition: future:151
exception_ptr make_exception_ptr(_Ex _Except) _NOEXCEPT
Definition: exception:378
mutex _Mtx
Definition: future:466
bool _Has_stored_result
Definition: future:471
template<class _Ty>
bool _Associated_state< _Ty >::_Already_has_stored_result ( ) const
inline
428  { // return presence of stored result
429  return (_Has_stored_result);
430  }
bool _Has_stored_result
Definition: future:471
template<class _Ty>
bool _Associated_state< _Ty >::_Already_retrieved ( ) const
inline
433  { // return retrieved status
434  return (_Retrieved);
435  }
bool _Retrieved
Definition: future:468
template<class _Ty>
void _Associated_state< _Ty >::_Delete_this ( )
inlineprivate
499  { // delete this object
500  if (_Deleter)
501  _Deleter->_Delete(this);
502  else
503  delete this;
504  }
virtual void _Delete(_Associated_state< _Ty > *)=0
_Mydel * _Deleter
Definition: future:506
template<class _Ty>
virtual void _Associated_state< _Ty >::_Do_notify ( unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inlineprivatevirtual
485  { // notify waiting threads
486  _Has_stored_result = true;
487  if (_At_thread_exit)
488  { // notify at thread exit
489  _Cond._Register(*_Lock, &_Ready);
490  }
491  else
492  { // notify immediately
493  _Ready = true;
494  _Cond.notify_all();
495  }
496  }
void notify_all() _NOEXCEPT
Definition: mutex:559
void _Register(unique_lock< mutex > &_Lck, int *_Ready)
Definition: mutex:664
int _Ready
Definition: future:469
condition_variable _Cond
Definition: future:467
bool _Has_stored_result
Definition: future:471
template<class _Ty>
virtual _Ty& _Associated_state< _Ty >::_Get_value ( bool  _Get_only_once)
inlinevirtual
339  { // return the stored result or throw stored exception
340  unique_lock<mutex> _Lock(_Mtx);
341  if (_Get_only_once && _Retrieved)
344  if (_Exception)
346  _Retrieved = true;
348  while (!_Ready)
349  _Cond.wait(_Lock);
350  if (_Exception)
352  return (_Result);
353  }
exception_ptr _Exception
Definition: future:465
void _Maybe_run_deferred_function(unique_lock< mutex > &_Lock)
Definition: future:454
Definition: mutex:259
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:119
void wait(unique_lock< mutex > &_Lck)
Definition: mutex:564
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
_Ty _Result
Definition: future:464
int _Ready
Definition: future:469
condition_variable _Cond
Definition: future:467
mutex _Mtx
Definition: future:466
bool _Retrieved
Definition: future:468
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Rethrow_future_exception(exception_ptr _Ptr)
template<class _Ty>
virtual bool _Associated_state< _Ty >::_Has_deferred_function ( ) const
inlineprivatevirtual
476  { // overridden by _Deferred_async_state
477  return (false);
478  }
template<class _Ty>
bool _Associated_state< _Ty >::_Is_ready ( ) const
inline
418  { // return ready status
419  return (_Ready != 0);
420  }
int _Ready
Definition: future:469
template<class _Ty>
bool _Associated_state< _Ty >::_Is_ready_at_thread_exit ( ) const
inline
423  { // return ready at thread exit status
424  return (_Ready_at_thread_exit);
425  }
bool _Ready_at_thread_exit
Definition: future:470
template<class _Ty>
void _Associated_state< _Ty >::_Make_ready_at_thread_exit ( )
inlineprotected
449  { // set ready status at thread exit
451  _Ready = true;
452  }
bool _Ready_at_thread_exit
Definition: future:470
int _Ready
Definition: future:469
template<class _Ty>
void _Associated_state< _Ty >::_Maybe_run_deferred_function ( unique_lock< mutex > &  _Lock)
inlineprotected
455  { // run a deferred function if not already done
456  if (!_Running)
457  { // run the function
458  _Running = true;
459  _Run_deferred_function(_Lock);
460  }
461  }
bool _Running
Definition: future:472
virtual void _Run_deferred_function(unique_lock< mutex > &)
Definition: future:480
template<class _Ty>
void _Associated_state< _Ty >::_Release ( )
inline
281  { // decrement reference count and destroy when zero
282  if (_MT_DECR(_Refs) == 0)
283  _Delete_this();
284  }
void _Delete_this()
Definition: future:498
_Atomic_counter_t _Refs
Definition: future:287
#define _MT_DECR(x)
Definition: xmemory0:1264
template<class _Ty>
void _Associated_state< _Ty >::_Retain ( )
inline
276  { // increment reference count
277  _MT_INCR(_Refs);
278  }
#define _MT_INCR(x)
Definition: xmemory0:1262
_Atomic_counter_t _Refs
Definition: future:287
template<class _Ty>
virtual void _Associated_state< _Ty >::_Run_deferred_function ( unique_lock< mutex > &  )
inlineprivatevirtual
481  { // do nothing
482  }
template<class _Ty>
void _Associated_state< _Ty >::_Set_exception ( exception_ptr  _Exc,
bool  _At_thread_exit 
)
inline
402  { // store a result
403  unique_lock<mutex> _Lock(_Mtx);
404  _Set_exception_raw(_Exc, &_Lock, _At_thread_exit);
405  }
Definition: mutex:259
void _Set_exception_raw(exception_ptr _Exc, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:407
mutex _Mtx
Definition: future:466
template<class _Ty>
void _Associated_state< _Ty >::_Set_exception_raw ( exception_ptr  _Exc,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
409  { // store a result while inside a locked block
410  if (_Has_stored_result)
413  _Exception = _Exc;
414  _Do_notify(_Lock, _At_thread_exit);
415  }
exception_ptr _Exception
Definition: future:465
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:119
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
bool _Has_stored_result
Definition: future:471
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:484
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( const _Ty &  _Val,
bool  _At_thread_exit 
)
inline
356  { // store a result
357  unique_lock<mutex> _Lock(_Mtx);
358  _Set_value_raw(_Val, &_Lock, _At_thread_exit);
359  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:361
Definition: mutex:259
mutex _Mtx
Definition: future:466
_FwdIt const _Ty _Val
Definition: algorithm:1938
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( _Ty &&  _Val,
bool  _At_thread_exit 
)
inline
372  { // store a result
373  unique_lock<mutex> _Lock(_Mtx);
374  _Set_value_raw(_STD forward<_Ty>(_Val), &_Lock, _At_thread_exit);
375  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:361
Definition: mutex:259
mutex _Mtx
Definition: future:466
_FwdIt const _Ty _Val
Definition: algorithm:1938
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( bool  _At_thread_exit)
inline
388  { // store a (void) result
389  unique_lock<mutex> _Lock(_Mtx);
390  _Set_value_raw(&_Lock, _At_thread_exit);
391  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:361
Definition: mutex:259
mutex _Mtx
Definition: future:466
template<class _Ty>
void _Associated_state< _Ty >::_Set_value_raw ( const _Ty &  _Val,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
363  { // store a result while inside a locked block
364  if (_Has_stored_result)
367  _Result = _Val;
368  _Do_notify(_Lock, _At_thread_exit);
369  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:119
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
_Ty _Result
Definition: future:464
bool _Has_stored_result
Definition: future:471
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:484
_FwdIt const _Ty _Val
Definition: algorithm:1938
template<class _Ty>
void _Associated_state< _Ty >::_Set_value_raw ( _Ty &&  _Val,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
379  { // store a result while inside a locked block
380  if (_Has_stored_result)
383  _Result = _STD forward<_Ty>(_Val);
384  _Do_notify(_Lock, _At_thread_exit);
385  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:119
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
_Ty _Result
Definition: future:464
bool _Has_stored_result
Definition: future:471
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:484
_FwdIt const _Ty _Val
Definition: algorithm:1938
template<class _Ty>
void _Associated_state< _Ty >::_Set_value_raw ( unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
394  { // store a (void) result while inside a locked block
395  if (_Has_stored_result)
398  _Do_notify(_Lock, _At_thread_exit);
399  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:119
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
bool _Has_stored_result
Definition: future:471
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:484
template<class _Ty>
virtual void _Associated_state< _Ty >::_Wait ( )
inlinevirtual
291  { // wait for signal
292  unique_lock<mutex> _Lock(_Mtx);
294  while (!_Ready)
295  _Cond.wait(_Lock);
296  }
void _Maybe_run_deferred_function(unique_lock< mutex > &_Lock)
Definition: future:454
Definition: mutex:259
void wait(unique_lock< mutex > &_Lck)
Definition: mutex:564
int _Ready
Definition: future:469
condition_variable _Cond
Definition: future:467
mutex _Mtx
Definition: future:466
template<class _Ty>
template<class _Rep , class _Per >
_Future_status _Associated_state< _Ty >::_Wait_for ( const chrono::duration< _Rep, _Per > &  _Rel_time)
inline
316  { // wait for duration
317  unique_lock<mutex> _Lock(_Mtx);
319  return (_Future_status::deferred);
320  if (_Cond.wait_for(_Lock, _Rel_time, _Test_ready(this)))
321  return (_Future_status::ready);
322  return (_Future_status::timeout);
323  }
Definition: mutex:259
_Cv_status wait_for(unique_lock< mutex > &_Lck, const chrono::duration< _Rep, _Period > &_Rel_time)
Definition: mutex:579
virtual bool _Has_deferred_function() const _NOEXCEPT
Definition: future:475
condition_variable _Cond
Definition: future:467
mutex _Mtx
Definition: future:466
template<class _Ty>
template<class _Clock , class _Dur >
_Future_status _Associated_state< _Ty >::_Wait_until ( const chrono::time_point< _Clock, _Dur > &  _Abs_time)
inline
329  { // wait until time point
330  unique_lock<mutex> _Lock(_Mtx);
332  return (_Future_status::deferred);
333  if (_Cond.wait_until(_Lock, _Abs_time, _Test_ready(this)))
334  return (_Future_status::ready);
335  return (_Future_status::timeout);
336  }
Definition: mutex:259
virtual bool _Has_deferred_function() const _NOEXCEPT
Definition: future:475
condition_variable _Cond
Definition: future:467
mutex _Mtx
Definition: future:466
_Cv_status wait_until(unique_lock< mutex > &_Lck, const chrono::time_point< _Clock, _Duration > &_Abs_time)
Definition: mutex:601
template<class _Ty>
_Associated_state& _Associated_state< _Ty >::operator= ( const _Associated_state< _Ty > &  )
delete

Member Data Documentation

template<class _Ty>
condition_variable _Associated_state< _Ty >::_Cond
template<class _Ty>
_Mydel* _Associated_state< _Ty >::_Deleter
private
template<class _Ty>
exception_ptr _Associated_state< _Ty >::_Exception
template<class _Ty>
bool _Associated_state< _Ty >::_Has_stored_result
template<class _Ty>
mutex _Associated_state< _Ty >::_Mtx
template<class _Ty>
int _Associated_state< _Ty >::_Ready
template<class _Ty>
bool _Associated_state< _Ty >::_Ready_at_thread_exit
template<class _Ty>
_Atomic_counter_t _Associated_state< _Ty >::_Refs
private
template<class _Ty>
_Ty _Associated_state< _Ty >::_Result
template<class _Ty>
bool _Associated_state< _Ty >::_Retrieved
template<class _Ty>
bool _Associated_state< _Ty >::_Running

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