STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Concurrency::cancellation_token Class Reference

The cancellation_token class represents the ability to determine whether some operation has been requested to cancel. A given token can be associated with a task_group, structured_task_group, or task to provide implicit cancellation. It can also be polled for cancellation or have a callback registered for if and when the associated cancellation_token_source is canceled. More...

#include <pplcancellation_token.h>

Public Types

typedef details::_CancellationTokenState_ImplType
 

Public Member Functions

 cancellation_token (const cancellation_token &_Src)
 
 cancellation_token (cancellation_token &&_Src)
 
cancellation_tokenoperator= (const cancellation_token &_Src)
 
cancellation_tokenoperator= (cancellation_token &&_Src)
 
bool operator== (const cancellation_token &_Src) const
 
bool operator!= (const cancellation_token &_Src) const
 
 ~cancellation_token ()
 
bool is_cancelable () const
 Returns an indication of whether this token can be canceled or not. More...
 
bool is_canceled () const
 Returns true if the token has been canceled. More...
 
template<typename _Function >
::Concurrency::cancellation_token_registration register_callback (const _Function &_Func) const
 Registers a callback function with the token. If and when the token is canceled, the callback will be made. Note that if the token is already canceled at the point where this method is called, the callback will be made immediately and synchronously. More...
 
void deregister_callback (const cancellation_token_registration &_Registration) const
 Removes a callback previously registered via the register method based on the cancellation_token_registration object returned at the time of registration. More...
 
_ImplType _GetImpl () const
 
_ImplType _GetImplValue () const
 

Static Public Member Functions

static cancellation_token none ()
 Returns a cancellation token which can never be subject to cancellation. More...
 
static cancellation_token _FromImpl (_ImplType _Impl)
 

Private Member Functions

void _Clear ()
 
void _Assign (_ImplType _Impl)
 
void _Move (_ImplType &_Impl)
 
 cancellation_token ()
 
 cancellation_token (_ImplType _Impl)
 

Private Attributes

_ImplType _M_Impl
 

Friends

class cancellation_token_source
 

Detailed Description

The cancellation_token class represents the ability to determine whether some operation has been requested to cancel. A given token can be associated with a task_group, structured_task_group, or task to provide implicit cancellation. It can also be polled for cancellation or have a callback registered for if and when the associated cancellation_token_source is canceled.

Member Typedef Documentation

Constructor & Destructor Documentation

Concurrency::cancellation_token::cancellation_token ( const cancellation_token _Src)
inline
634  {
635  _Assign(_Src._M_Impl);
636  }
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
void _Assign(_ImplType _Impl)
Definition: pplcancellation_token.h:773
Concurrency::cancellation_token::cancellation_token ( cancellation_token &&  _Src)
inline
639  {
640  _Move(_Src._M_Impl);
641  }
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
void _Move(_ImplType &_Impl)
Definition: pplcancellation_token.h:782
Concurrency::cancellation_token::~cancellation_token ( )
inline
674  {
675  _Clear();
676  }
void _Clear()
Definition: pplcancellation_token.h:764
Concurrency::cancellation_token::cancellation_token ( )
inlineprivate
788  :
789  _M_Impl(NULL)
790  {
791  }
#define NULL
Definition: crtdbg.h:30
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
Concurrency::cancellation_token::cancellation_token ( _ImplType  _Impl)
inlineprivate
793  :
794  _M_Impl(_Impl)
795  {
797  {
798  _M_Impl = NULL;
799  }
800 
801  if (_M_Impl != NULL)
802  {
803  _M_Impl->_Reference();
804  }
805  }
#define NULL
Definition: crtdbg.h:30
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:328
long _Reference()
Definition: pplcancellation_token.h:60
_ImplType _M_Impl
Definition: pplcancellation_token.h:762

Member Function Documentation

void Concurrency::cancellation_token::_Assign ( _ImplType  _Impl)
inlineprivate
774  {
775  if (_Impl != NULL)
776  {
777  _Impl->_Reference();
778  }
779  _M_Impl = _Impl;
780  }
#define NULL
Definition: crtdbg.h:30
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
void Concurrency::cancellation_token::_Clear ( )
inlineprivate
765  {
766  if (_M_Impl != NULL)
767  {
768  _M_Impl->_Release();
769  }
770  _M_Impl = NULL;
771  }
#define NULL
Definition: crtdbg.h:30
long _Release()
Definition: pplcancellation_token.h:71
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
static cancellation_token Concurrency::cancellation_token::_FromImpl ( _ImplType  _Impl)
inlinestatic
754  {
755  return cancellation_token(_Impl);
756  }
cancellation_token()
Definition: pplcancellation_token.h:788
_ImplType Concurrency::cancellation_token::_GetImpl ( ) const
inline
744  {
745  return _M_Impl;
746  }
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
_ImplType Concurrency::cancellation_token::_GetImplValue ( ) const
inline
749  {
751  }
#define NULL
Definition: crtdbg.h:30
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:328
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
void Concurrency::cancellation_token::_Move ( _ImplType _Impl)
inlineprivate
783  {
784  _M_Impl = _Impl;
785  _Impl = NULL;
786  }
#define NULL
Definition: crtdbg.h:30
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
void Concurrency::cancellation_token::deregister_callback ( const cancellation_token_registration _Registration) const
inline

Removes a callback previously registered via the register method based on the cancellation_token_registration object returned at the time of registration.

Parameters
_RegistrationThe cancellation_token_registration object corresponding to the callback to be deregistered. This token must have been previously returned from a call to the register method.
739  {
740  _M_Impl->_DeregisterCallback(_Registration._M_pRegistration);
741  }
void _DeregisterCallback(_In_ _CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:415
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
bool Concurrency::cancellation_token::is_cancelable ( ) const
inline

Returns an indication of whether this token can be canceled or not.

Returns
An indication of whether this token can be canceled or not.
685  {
686  return (_M_Impl != NULL);
687  }
#define NULL
Definition: crtdbg.h:30
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
bool Concurrency::cancellation_token::is_canceled ( ) const
inline

Returns true if the token has been canceled.

Returns
The value true if the token has been canceled; otherwise, the value false.
696  {
697  return (_M_Impl != NULL && _M_Impl->_IsCanceled());
698  }
#define NULL
Definition: crtdbg.h:30
bool _IsCanceled() const
Definition: pplcancellation_token.h:358
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
static cancellation_token Concurrency::cancellation_token::none ( )
inlinestatic

Returns a cancellation token which can never be subject to cancellation.

Returns
A cancellation token that cannot be canceled.
629  {
630  return cancellation_token();
631  }
cancellation_token()
Definition: pplcancellation_token.h:788
bool Concurrency::cancellation_token::operator!= ( const cancellation_token _Src) const
inline
669  {
670  return !(operator==(_Src));
671  }
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
bool operator==(const cancellation_token &_Src) const
Definition: pplcancellation_token.h:663
cancellation_token& Concurrency::cancellation_token::operator= ( const cancellation_token _Src)
inline
644  {
645  if (this != &_Src)
646  {
647  _Clear();
648  _Assign(_Src._M_Impl);
649  }
650  return *this;
651  }
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
void _Clear()
Definition: pplcancellation_token.h:764
void _Assign(_ImplType _Impl)
Definition: pplcancellation_token.h:773
cancellation_token& Concurrency::cancellation_token::operator= ( cancellation_token &&  _Src)
inline
654  {
655  if (this != &_Src)
656  {
657  _Clear();
658  _Move(_Src._M_Impl);
659  }
660  return *this;
661  }
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
void _Move(_ImplType &_Impl)
Definition: pplcancellation_token.h:782
void _Clear()
Definition: pplcancellation_token.h:764
bool Concurrency::cancellation_token::operator== ( const cancellation_token _Src) const
inline
664  {
665  return _M_Impl == _Src._M_Impl;
666  }
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
template<typename _Function >
::Concurrency::cancellation_token_registration Concurrency::cancellation_token::register_callback ( const _Function &  _Func) const
inline

Registers a callback function with the token. If and when the token is canceled, the callback will be made. Note that if the token is already canceled at the point where this method is called, the callback will be made immediately and synchronously.

Template Parameters
_FunctionThe type of the function object that will be called back when this cancellation_token is canceled.
Parameters
_FuncThe function object that will be called back when this cancellation_token is canceled.
Returns
A cancellation_token_registration object which can be utilized in the deregister method to deregister a previously registered callback and prevent it from being made. The method will throw an invalid_operation exception if it is called on a cancellation_token object that was created using the cancellation_token::none method.
718  {
719  if (_M_Impl == NULL)
720  {
721  // A callback cannot be registered if the token does not have an associated source.
722  throw invalid_operation();
723  }
724 #pragma warning(suppress: 28197)
725  details::_CancellationTokenCallback<_Function> *_PCallback = new details::_CancellationTokenCallback<_Function>(_Func);
726  _M_Impl->_RegisterCallback(_PCallback);
727  return cancellation_token_registration(_PCallback);
728  }
_CancellationTokenRegistration * _RegisterCallback(TaskProc_t _PCallback, _In_ void *_PData, int _InitialRefs=1)
Definition: pplcancellation_token.h:383
#define NULL
Definition: crtdbg.h:30
_ImplType _M_Impl
Definition: pplcancellation_token.h:762

Friends And Related Function Documentation

friend class cancellation_token_source
friend

Member Data Documentation

_ImplType Concurrency::cancellation_token::_M_Impl
private

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