STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | 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
 

Public Member Functions

 _Associated_state (_Deleter_base< _Ty > *_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_retrieved () const
 
 _Associated_state (const _Associated_state &)=delete
 
_Associated_stateoperator= (const _Associated_state &)=delete
 

Protected Member Functions

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

Protected 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
 

Private Member Functions

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
 
_Deleter_base< _Ty > * _Deleter
 

Member Typedef Documentation

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

Constructor & Destructor Documentation

template<class _Ty>
_Associated_state< _Ty >::_Associated_state ( _Deleter_base< _Ty > *  _Dp = 0)
inline
287  : _Exception(),
288  _Retrieved(false),
289  _Running(false),
290  _Ready(false),
291  _Ready_at_thread_exit(false),
292  _Has_stored_result(false),
293  _Deleter(_Dp)
294  { // construct
295  // TODO: _Associated_state ctor assumes _Ty is default constructible
296  _Init_refs();
297  }
bool _Ready_at_thread_exit
Definition: future:503
bool _Running
Definition: future:505
void _Init_refs()
Definition: future:323
_XSTD exception_ptr _Exception
Definition: future:498
_Deleter_base< _Ty > * _Deleter
Definition: future:534
int _Ready
Definition: future:502
bool _Retrieved
Definition: future:501
bool _Has_stored_result
Definition: future:504
template<class _Ty>
virtual _Associated_state< _Ty >::~_Associated_state ( )
inlinevirtual
300  { // destroy
301  if (_Has_stored_result && !_Ready)
302  { // registered for release at thread exit
304  }
305  _Destroy_refs();
306  }
void _Unregister(mutex &_Mtx)
Definition: condition_variable:147
int _Ready
Definition: future:502
condition_variable _Cond
Definition: future:500
mutex _Mtx
Definition: future:499
void _Destroy_refs()
Definition: future:328
bool _Has_stored_result
Definition: future:504
template<class _Ty>
_Associated_state< _Ty >::_Associated_state ( const _Associated_state< _Ty > &  )
delete

Member Function Documentation

template<class _Ty>
bool _Associated_state< _Ty >::_Already_retrieved ( ) const
inline
477  { // return retrieved status
478  return (_Retrieved);
479  }
bool _Retrieved
Definition: future:501
template<class _Ty>
void _Associated_state< _Ty >::_Delete_this ( )
inlineprivate
527  { // delete this object
528  if (_Deleter)
529  _Deleter->_Delete(this);
530  else
531  delete this;
532  }
_Deleter_base< _Ty > * _Deleter
Definition: future:534
template<class _Ty>
void _Associated_state< _Ty >::_Destroy_refs ( )
inline
329  { // destroy reference count
330  }
template<class _Ty>
virtual void _Associated_state< _Ty >::_Do_notify ( unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inlineprivatevirtual
513  { // notify waiting threads
514  _Has_stored_result = true;
515  if (_At_thread_exit)
516  { // notify at thread exit
517  _Cond._Register(*_Lock, &_Ready);
518  }
519  else
520  { // notify immediately
521  _Ready = true;
522  _Cond.notify_all();
523  }
524  }
void notify_all() _NOEXCEPT
Definition: condition_variable:50
void _Register(unique_lock< mutex > &_Lck, int *_Ready)
Definition: condition_variable:142
int _Ready
Definition: future:502
condition_variable _Cond
Definition: future:500
bool _Has_stored_result
Definition: future:504
template<class _Ty>
virtual _Ty& _Associated_state< _Ty >::_Get_value ( bool  _Get_only_once)
inlinevirtual
385  { // return the stored result or throw stored exception
386  unique_lock<mutex> _Lock(_Mtx);
387  if (_Get_only_once && _Retrieved)
388  _Throw_future_error(
390  if (_Exception)
391  _Rethrow_future_exception(_Exception);
392  _Retrieved = true;
394  while (!_Ready)
395  _Cond.wait(_Lock);
396  if (_Exception)
397  _Rethrow_future_exception(_Exception);
398  return (_Result);
399  }
void _Maybe_run_deferred_function(unique_lock< mutex > &_Lock)
Definition: future:488
Definition: mutex:204
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_XSTD exception_ptr _Exception
Definition: future:498
void wait(unique_lock< mutex > &_Lck)
Definition: condition_variable:55
_Ty _Result
Definition: future:497
int _Ready
Definition: future:502
condition_variable _Cond
Definition: future:500
mutex _Mtx
Definition: future:499
bool _Retrieved
Definition: future:501
template<class _Ty>
void _Associated_state< _Ty >::_Init_refs ( )
inline
324  { // initialize reference count
326  }
_Atomic_counter_t _Refs
Definition: future:320
#define _Init_atomic_counter(_Counter, _Value)
Definition: xatomic0.h:153
template<class _Ty>
bool _Associated_state< _Ty >::_Is_ready ( ) const
inline
472  { // return ready status
473  return (_Ready != 0);
474  }
int _Ready
Definition: future:502
template<class _Ty>
void _Associated_state< _Ty >::_Make_ready_at_thread_exit ( )
inlineprotected
483  { // set ready status at thread exit
485  _Ready = true;
486  }
bool _Ready_at_thread_exit
Definition: future:503
int _Ready
Definition: future:502
template<class _Ty>
void _Associated_state< _Ty >::_Maybe_run_deferred_function ( unique_lock< mutex > &  _Lock)
inlineprotected
489  { // run a deferred function if not already done
490  if (!_Running)
491  { // run the function
492  _Running = true;
493  _Run_deferred_function(_Lock);
494  }
495  }
bool _Running
Definition: future:505
virtual void _Run_deferred_function(unique_lock< mutex > &)
Definition: future:508
template<class _Ty>
void _Associated_state< _Ty >::_Release ( )
inline
314  { // decrement reference count and destroy when zero
315  if (_MT_DECR(_Mtx0, _Refs) == 0)
316  _Delete_this();
317  }
void _Delete_this()
Definition: future:526
#define _MT_DECR(mtx, x)
Definition: xmemory0:921
_Atomic_counter_t _Refs
Definition: future:320
template<class _Ty>
void _Associated_state< _Ty >::_Retain ( )
inline
309  { // increment reference count
310  _MT_INCR(_Mtx0, _Refs);
311  }
#define _MT_INCR(mtx, x)
Definition: xmemory0:919
_Atomic_counter_t _Refs
Definition: future:320
template<class _Ty>
virtual void _Associated_state< _Ty >::_Run_deferred_function ( unique_lock< mutex > &  )
inlineprivatevirtual
509  { // do nothing
510  }
template<class _Ty>
void _Associated_state< _Ty >::_Set_exception ( _XSTD exception_ptr  _Exc,
bool  _At_thread_exit 
)
inline
448  { // store a result
449  unique_lock<mutex> _Lock(_Mtx);
450  _Set_exception_raw(_Exc, &_Lock, _At_thread_exit);
451  }
Definition: mutex:204
void _Set_exception_raw(_XSTD exception_ptr _Exc, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:457
mutex _Mtx
Definition: future:499
template<class _Ty>
void _Associated_state< _Ty >::_Set_exception_raw ( _XSTD exception_ptr  _Exc,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
459  { // store a result while inside a locked block
460  if (_Has_stored_result)
461  _Throw_future_error(
463  _Exception = _Exc;
464  if (!_Exc) // make a non-null exception_ptr
465 
466  _Exception = make_exception_ptr(_Anon());
467 
468  _Do_notify(_Lock, _At_thread_exit);
469  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_XSTD exception_ptr _Exception
Definition: future:498
bool _Has_stored_result
Definition: future:504
exception_ptr make_exception_ptr(_E _Except)
Definition: exception:539
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:512
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( const _Ty &  _Val,
bool  _At_thread_exit 
)
inline
402  { // store a result
403  unique_lock<mutex> _Lock(_Mtx);
404  _Set_value_raw(_Val, &_Lock, _At_thread_exit);
405  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:407
Definition: mutex:204
mutex _Mtx
Definition: future:499
_FwdIt const _Ty _Val
Definition: algorithm:1938
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( _Ty &&  _Val,
bool  _At_thread_exit 
)
inline
418  { // store a result
419  unique_lock<mutex> _Lock(_Mtx);
420  _Set_value_raw(_STD forward<_Ty>(_Val), &_Lock, _At_thread_exit);
421  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:407
Definition: mutex:204
mutex _Mtx
Definition: future:499
_FwdIt const _Ty _Val
Definition: algorithm:1938
template<class _Ty>
void _Associated_state< _Ty >::_Set_value ( bool  _At_thread_exit)
inline
434  { // store a (void) result
435  unique_lock<mutex> _Lock(_Mtx);
436  _Set_value_raw(&_Lock, _At_thread_exit);
437  }
void _Set_value_raw(const _Ty &_Val, unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:407
Definition: mutex:204
mutex _Mtx
Definition: future:499
template<class _Ty>
void _Associated_state< _Ty >::_Set_value_raw ( const _Ty &  _Val,
unique_lock< mutex > *  _Lock,
bool  _At_thread_exit 
)
inline
409  { // store a result while inside a locked block
410  if (_Has_stored_result)
411  _Throw_future_error(
413  _Result = _Val;
414  _Do_notify(_Lock, _At_thread_exit);
415  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_Ty _Result
Definition: future:497
bool _Has_stored_result
Definition: future:504
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:512
_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
425  { // store a result while inside a locked block
426  if (_Has_stored_result)
427  _Throw_future_error(
429  _Result = _STD forward<_Ty>(_Val);
430  _Do_notify(_Lock, _At_thread_exit);
431  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
_Ty _Result
Definition: future:497
bool _Has_stored_result
Definition: future:504
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:512
_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
440  { // store a (void) result while inside a locked block
441  if (_Has_stored_result)
442  _Throw_future_error(
444  _Do_notify(_Lock, _At_thread_exit);
445  }
error_code make_error_code(_Future_errc _Errno) _NOEXCEPT
Definition: future:120
bool _Has_stored_result
Definition: future:504
virtual void _Do_notify(unique_lock< mutex > *_Lock, bool _At_thread_exit)
Definition: future:512
template<class _Ty>
virtual void _Associated_state< _Ty >::_Wait ( )
inlinevirtual
333  { // wait for signal
334  unique_lock<mutex> _Lock(_Mtx);
336  while (!_Ready)
337  _Cond.wait(_Lock);
338  }
void _Maybe_run_deferred_function(unique_lock< mutex > &_Lock)
Definition: future:488
Definition: mutex:204
void wait(unique_lock< mutex > &_Lck)
Definition: condition_variable:55
int _Ready
Definition: future:502
condition_variable _Cond
Definition: future:500
mutex _Mtx
Definition: future:499
template<class _Ty>
template<class _Rep , class _Per >
_Future_status _Associated_state< _Ty >::_Wait_for ( const chrono::duration< _Rep, _Per > &  _Rel_time)
inline
358  { // wait for duration
360  unique_lock<mutex> _Lock(_Mtx);
361 
362  bool _Cv_state =
363  _Cond.wait_for(_Lock, _Rel_time, _Test_ready(this));
364  if (!_Cv_state)
365  _Res = _Future_status::timeout;
366  return (_Res);
367  }
Definition: mutex:204
_Cv_status wait_for(unique_lock< mutex > &_Lck, const chrono::duration< _Rep, _Period > &_Rel_time)
Definition: condition_variable:69
condition_variable _Cond
Definition: future:500
mutex _Mtx
Definition: future:499
future_status
Definition: future:97
template<class _Ty>
template<class _Clock , class _Dur >
_Future_status _Associated_state< _Ty >::_Wait_until ( const chrono::time_point< _Clock, _Dur > &  _Abs_time)
inline
373  { // wait until time point
375  unique_lock<mutex> _Lock(_Mtx);
376 
377  bool _Cv_state =
378  _Cond.wait_until(_Lock, _Abs_time, _Test_ready(this));
379  if (!_Cv_state)
380  _Res = _Future_status::timeout;
381  return (_Res);
382  }
Definition: mutex:204
condition_variable _Cond
Definition: future:500
mutex _Mtx
Definition: future:499
future_status
Definition: future:97
_Cv_status wait_until(unique_lock< mutex > &_Lck, const chrono::time_point< _Clock, _Duration > &_Abs_time)
Definition: condition_variable:91
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
protected
template<class _Ty>
_Deleter_base<_Ty>* _Associated_state< _Ty >::_Deleter
private
template<class _Ty>
_XSTD exception_ptr _Associated_state< _Ty >::_Exception
protected
template<class _Ty>
bool _Associated_state< _Ty >::_Has_stored_result
protected
template<class _Ty>
mutex _Associated_state< _Ty >::_Mtx
protected
template<class _Ty>
int _Associated_state< _Ty >::_Ready
protected
template<class _Ty>
bool _Associated_state< _Ty >::_Ready_at_thread_exit
protected
template<class _Ty>
_Atomic_counter_t _Associated_state< _Ty >::_Refs
private
template<class _Ty>
_Ty _Associated_state< _Ty >::_Result
protected
template<class _Ty>
bool _Associated_state< _Ty >::_Retrieved
protected
template<class _Ty>
bool _Associated_state< _Ty >::_Running
protected

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