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  _Anon
 
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 ()
 
void _Init_refs ()
 
void _Destroy_refs ()
 
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 (_XSTD exception_ptr _Exc, bool _At_thread_exit)
 
void _Set_exception_raw (_XSTD exception_ptr _Exc, unique_lock< mutex > *_Lock, bool _At_thread_exit)
 
bool _Is_ready () 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
 
_XSTD 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
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  _Init_refs();
266  }
bool _Ready_at_thread_exit
Definition: future:484
bool _Running
Definition: future:486
void _Init_refs()
Definition: future:292
_XSTD exception_ptr _Exception
Definition: future:479
int _Ready
Definition: future:483
bool _Retrieved
Definition: future:482
bool _Has_stored_result
Definition: future:485
_Mydel * _Deleter
Definition: future:520
template<class _Ty>
virtual _Associated_state< _Ty >::~_Associated_state ( )
inlinevirtual
269  { // destroy
270  if (_Has_stored_result && !_Ready)
271  { // registered for release at thread exit
273  }
274  _Destroy_refs();
275  }
void _Unregister(mutex &_Mtx)
Definition: mutex:666
int _Ready
Definition: future:483
condition_variable _Cond
Definition: future:481
mutex _Mtx
Definition: future:480
void _Destroy_refs()
Definition: future:297
bool _Has_stored_result
Definition: future:485
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
452  { // abandon shared state
453  unique_lock<mutex> _Lock(_Mtx);
454  if (!_Has_stored_result)
455  { // queue exception
457  _Set_exception_raw(_XSTD make_exception_ptr(_Fut), &_Lock, false);
458  }
459  }
Definition: mutex:258
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
#define _XSTD
Definition: xstddef:21
void _Set_exception_raw(_XSTD exception_ptr _Exc, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:422
Definition: future:152
exception_ptr make_exception_ptr(_Ex _Except) _NOEXCEPT
Definition: exception:371
mutex _Mtx
Definition: future:480
bool _Has_stored_result
Definition: future:485
template<class _Ty>
bool _Associated_state< _Ty >::_Already_has_stored_result ( ) const
inline
442  { // return presence of stored result
443  return (_Has_stored_result);
444  }
bool _Has_stored_result
Definition: future:485
template<class _Ty>
bool _Associated_state< _Ty >::_Already_retrieved ( ) const
inline
447  { // return retrieved status
448  return (_Retrieved);
449  }
bool _Retrieved
Definition: future:482
template<class _Ty>
void _Associated_state< _Ty >::_Delete_this ( )
inlineprivate
513  { // delete this object
514  if (_Deleter)
515  _Deleter->_Delete(this);
516  else
517  delete this;
518  }
virtual void _Delete(_Associated_state< _Ty > *)=0
_Mydel * _Deleter
Definition: future:520
template<class _Ty>
void _Associated_state< _Ty >::_Destroy_refs ( )
inline
298  { // destroy reference count
299  }
template<class _Ty>
virtual void _Associated_state< _Ty >::_Do_notify ( unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inlineprivatevirtual
499  { // notify waiting threads
500  _Has_stored_result = true;
501  if (_At_thread_exit)
502  { // notify at thread exit
503  _Cond._Register(*_Lock, &_Ready);
504  }
505  else
506  { // notify immediately
507  _Ready = true;
508  _Cond.notify_all();
509  }
510  }
void notify_all() _NOEXCEPT
Definition: mutex:558
void _Register(unique_lock< mutex > &_Lck, int *_Ready)
Definition: mutex:660
int _Ready
Definition: future:483
condition_variable _Cond
Definition: future:481
bool _Has_stored_result
Definition: future:485
template<class _Ty>
virtual _Ty& _Associated_state< _Ty >::_Get_value ( bool  _Get_only_once)
inlinevirtual
350  { // return the stored result or throw stored exception
351  unique_lock<mutex> _Lock(_Mtx);
352  if (_Get_only_once && _Retrieved)
355  if (_Exception)
357  _Retrieved = true;
359  while (!_Ready)
360  _Cond.wait(_Lock);
361  if (_Exception)
363  return (_Result);
364  }
void _Maybe_run_deferred_function(unique_lock< mutex > &_Lock)
Definition: future:468
Definition: mutex:258
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_XSTD exception_ptr _Exception
Definition: future:479
void wait(unique_lock< mutex > &_Lck)
Definition: mutex:563
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
_Ty _Result
Definition: future:478
int _Ready
Definition: future:483
condition_variable _Cond
Definition: future:481
mutex _Mtx
Definition: future:480
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Rethrow_future_exception(_XSTD exception_ptr _Ptr)
bool _Retrieved
Definition: future:482
template<class _Ty>
virtual bool _Associated_state< _Ty >::_Has_deferred_function ( ) const
inlineprivatevirtual
490  { // overridden by _Deferred_async_state
491  return (false);
492  }
template<class _Ty>
void _Associated_state< _Ty >::_Init_refs ( )
inline
293  { // initialize reference count
295  }
void _Init_atomic_counter(_Atomic_counter_t &_Counter, _Atomic_integral_t _Value)
Definition: xatomic0.h:60
_Atomic_counter_t _Refs
Definition: future:289
template<class _Ty>
bool _Associated_state< _Ty >::_Is_ready ( ) const
inline
437  { // return ready status
438  return (_Ready != 0);
439  }
int _Ready
Definition: future:483
template<class _Ty>
void _Associated_state< _Ty >::_Make_ready_at_thread_exit ( )
inlineprotected
463  { // set ready status at thread exit
465  _Ready = true;
466  }
bool _Ready_at_thread_exit
Definition: future:484
int _Ready
Definition: future:483
template<class _Ty>
void _Associated_state< _Ty >::_Maybe_run_deferred_function ( unique_lock< mutex > &  _Lock)
inlineprotected
469  { // run a deferred function if not already done
470  if (!_Running)
471  { // run the function
472  _Running = true;
473  _Run_deferred_function(_Lock);
474  }
475  }
bool _Running
Definition: future:486
virtual void _Run_deferred_function(unique_lock< mutex > &)
Definition: future:494
template<class _Ty>
void _Associated_state< _Ty >::_Release ( )
inline
283  { // decrement reference count and destroy when zero
284  if (_MT_DECR(_Refs) == 0)
285  _Delete_this();
286  }
void _Delete_this()
Definition: future:512
_Atomic_counter_t _Refs
Definition: future:289
#define _MT_DECR(x)
Definition: xmemory0:1163
template<class _Ty>
void _Associated_state< _Ty >::_Retain ( )
inline
278  { // increment reference count
279  _MT_INCR(_Refs);
280  }
#define _MT_INCR(x)
Definition: xmemory0:1161
_Atomic_counter_t _Refs
Definition: future:289
template<class _Ty>
virtual void _Associated_state< _Ty >::_Run_deferred_function ( unique_lock< mutex > &  )
inlineprivatevirtual
495  { // do nothing
496  }
template<class _Ty>
void _Associated_state< _Ty >::_Set_exception ( _XSTD exception_ptr  _Exc,
bool  _At_thread_exit 
)
inline
413  { // store a result
414  unique_lock<mutex> _Lock(_Mtx);
415  _Set_exception_raw(_Exc, &_Lock, _At_thread_exit);
416  }
Definition: mutex:258
void _Set_exception_raw(_XSTD exception_ptr _Exc, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:422
mutex _Mtx
Definition: future:480
template<class _Ty>
void _Associated_state< _Ty >::_Set_exception_raw ( _XSTD exception_ptr  _Exc,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
424  { // store a result while inside a locked block
425  if (_Has_stored_result)
428  _Exception = _Exc;
429  if (!_Exc) // make a non-null exception_ptr
430 
431  _Exception = make_exception_ptr(_Anon());
432 
433  _Do_notify(_Lock, _At_thread_exit);
434  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_XSTD exception_ptr _Exception
Definition: future:479
exception_ptr make_exception_ptr(_Ex _Except) _NOEXCEPT
Definition: exception:371
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
bool _Has_stored_result
Definition: future:485
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:498
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( const _Ty &  _Val,
bool  _At_thread_exit 
)
inline
367  { // store a result
368  unique_lock<mutex> _Lock(_Mtx);
369  _Set_value_raw(_Val, &_Lock, _At_thread_exit);
370  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:372
Definition: mutex:258
_In_ int _Val
Definition: vcruntime_string.h:62
mutex _Mtx
Definition: future:480
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( _Ty &&  _Val,
bool  _At_thread_exit 
)
inline
383  { // store a result
384  unique_lock<mutex> _Lock(_Mtx);
385  _Set_value_raw(_STD forward<_Ty>(_Val), &_Lock, _At_thread_exit);
386  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:372
Definition: mutex:258
_In_ int _Val
Definition: vcruntime_string.h:62
mutex _Mtx
Definition: future:480
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( bool  _At_thread_exit)
inline
399  { // store a (void) result
400  unique_lock<mutex> _Lock(_Mtx);
401  _Set_value_raw(&_Lock, _At_thread_exit);
402  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:372
Definition: mutex:258
mutex _Mtx
Definition: future:480
template<class _Ty>
void _Associated_state< _Ty >::_Set_value_raw ( const _Ty &  _Val,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
374  { // store a result while inside a locked block
375  if (_Has_stored_result)
378  _Result = _Val;
379  _Do_notify(_Lock, _At_thread_exit);
380  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_In_ int _Val
Definition: vcruntime_string.h:62
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
_Ty _Result
Definition: future:478
bool _Has_stored_result
Definition: future:485
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:498
template<class _Ty>
void _Associated_state< _Ty >::_Set_value_raw ( _Ty &&  _Val,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
390  { // store a result while inside a locked block
391  if (_Has_stored_result)
394  _Result = _STD forward<_Ty>(_Val);
395  _Do_notify(_Lock, _At_thread_exit);
396  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_In_ int _Val
Definition: vcruntime_string.h:62
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
_Ty _Result
Definition: future:478
bool _Has_stored_result
Definition: future:485
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:498
template<class _Ty>
void _Associated_state< _Ty >::_Set_value_raw ( unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
405  { // store a (void) result while inside a locked block
406  if (_Has_stored_result)
409  _Do_notify(_Lock, _At_thread_exit);
410  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Throw_future_error(const error_code &_Code)
bool _Has_stored_result
Definition: future:485
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:498
template<class _Ty>
virtual void _Associated_state< _Ty >::_Wait ( )
inlinevirtual
302  { // wait for signal
303  unique_lock<mutex> _Lock(_Mtx);
305  while (!_Ready)
306  _Cond.wait(_Lock);
307  }
void _Maybe_run_deferred_function(unique_lock< mutex > &_Lock)
Definition: future:468
Definition: mutex:258
void wait(unique_lock< mutex > &_Lck)
Definition: mutex:563
int _Ready
Definition: future:483
condition_variable _Cond
Definition: future:481
mutex _Mtx
Definition: future:480
template<class _Ty>
template<class _Rep , class _Per >
_Future_status _Associated_state< _Ty >::_Wait_for ( const chrono::duration< _Rep, _Per > &  _Rel_time)
inline
327  { // wait for duration
328  unique_lock<mutex> _Lock(_Mtx);
330  return (_Future_status::deferred);
331  if (_Cond.wait_for(_Lock, _Rel_time, _Test_ready(this)))
332  return (_Future_status::ready);
333  return (_Future_status::timeout);
334  }
Definition: mutex:258
_Cv_status wait_for(unique_lock< mutex > &_Lck, const chrono::duration< _Rep, _Period > &_Rel_time)
Definition: mutex:577
virtual bool _Has_deferred_function() const _NOEXCEPT
Definition: future:489
condition_variable _Cond
Definition: future:481
mutex _Mtx
Definition: future:480
template<class _Ty>
template<class _Clock , class _Dur >
_Future_status _Associated_state< _Ty >::_Wait_until ( const chrono::time_point< _Clock, _Dur > &  _Abs_time)
inline
340  { // wait until time point
341  unique_lock<mutex> _Lock(_Mtx);
343  return (_Future_status::deferred);
344  if (_Cond.wait_until(_Lock, _Abs_time, _Test_ready(this)))
345  return (_Future_status::ready);
346  return (_Future_status::timeout);
347  }
Definition: mutex:258
virtual bool _Has_deferred_function() const _NOEXCEPT
Definition: future:489
condition_variable _Cond
Definition: future:481
mutex _Mtx
Definition: future:480
_Cv_status wait_until(unique_lock< mutex > &_Lck, const chrono::time_point< _Clock, _Duration > &_Abs_time)
Definition: mutex:599
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>
_XSTD 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: