29 #error This header must not be included directly
32 #ifndef _PPLCANCELLATION_TOKEN_H
33 #define _PPLCANCELLATION_TOKEN_H
39 #pragma pack(push,_CRT_PACKING)
41 #pragma push_macro("new")
67 _ASSERTE(_Refcount > 1);
76 _ASSERTE(_Refcount >= 0);
137 virtual void _Exec() = 0;
146 _ASSERTE((_Tid & 0x3) == 0);
150 if (_Result == _STATE_CLEAR)
156 if (_Result == _STATE_SYNCHRONIZE)
159 std::lock_guard<std::mutex> _Lock(
_M_Mutex);
175 template<
typename _Function>
244 while (
_Node !=
nullptr)
263 template<
typename _Ty>
268 while (_Node !=
nullptr)
293 Node* _Prev =
nullptr;
295 while (_Node !=
nullptr)
298 if (_Prev ==
nullptr)
339 return (_PToken !=
NULL && _PToken !=
_None());
390 return _PRegistration;
396 _PRegistration->_Reference();
397 _PRegistration->_M_pTokenState =
this;
414 _PRegistration->_Invoke();
420 bool _Synchronize =
false;
434 _PRegistration->_Release();
453 _PRegistration->_M_state,
483 std::unique_lock<std::mutex> _Lock(_PRegistration->_M_Mutex);
484 _PRegistration->_M_CondVar.wait(_Lock,
485 [_PRegistration]{
return _PRegistration->_M_signaled; });
487 _ASSERTE(_PRegistration->_M_signaled);
541 _Move(_Src._M_pRegistration);
559 _Move(_Src._M_pRegistration);
594 if (_PRegistration !=
NULL)
596 _PRegistration->_Reference();
604 _PRegistration =
NULL;
716 template<
typename _Function>
724 #pragma warning(suppress: 28197)
815 typedef ::Concurrency::details::_CancellationTokenState *
_ImplType;
822 _M_Impl = new ::Concurrency::details::_CancellationTokenState;
916 template<
typename _Iter>
920 for (_Iter _It = _Begin; _It != _End; ++_It)
922 _It->register_callback( [_NewSource](){ _NewSource.
cancel(); } );
991 #pragma pop_macro("new")
994 #endif // _PPLCANCELLATION_TOKEN_H
cancellation_token(const cancellation_token &_Src)
Definition: pplcancellation_token.h:633
void swap(TokenRegistrationContainer &_List)
Definition: pplcancellation_token.h:252
static cancellation_token_source _FromImpl(_ImplType _Impl)
Definition: pplcancellation_token.h:941
cancellation_token_source(const cancellation_token_source &_Src)
Definition: pplcancellation_token.h:825
static const long _STATE_CALLED
Definition: pplcancellation_token.h:113
bool is_canceled() const
Returns true if the token has been canceled.
Definition: pplcancellation_token.h:695
_T atomic_exchange(std::atomic< _T > &_Target, _T _Value)
Definition: pplinterface.h:246
~cancellation_token_source()
Definition: pplcancellation_token.h:865
#define NULL
Definition: vcruntime.h:236
This class describes an exception thrown when an invalid operation is performed that is not more accu...
Definition: pplinterface.h:132
cancellation_token get_token() const
Returns a cancellation token associated with this source. The returned token can be polled for cancel...
Definition: pplcancellation_token.h:880
static const long _STATE_DEFER_DELETE
Definition: pplcancellation_token.h:111
static const long _STATE_SYNCHRONIZE
Definition: pplcancellation_token.h:112
_ImplType _GetImpl() const
Definition: pplcancellation_token.h:743
atomic_long _M_state
Definition: pplcancellation_token.h:168
bool empty()
Definition: pplcancellation_token.h:258
_T atomic_compare_exchange(std::atomic< _T > &_Target, _T _Exchange, _T _Comparand)
Definition: pplinterface.h:238
cancellation_token_registration & operator=(cancellation_token_registration &&_Src)
Definition: pplcancellation_token.h:554
volatile long _M_refCount
Definition: pplcancellation_token.h:101
cancellation_token_registration(const cancellation_token_registration &_Src)
Definition: pplcancellation_token.h:534
virtual void _Destroy()
Definition: pplcancellation_token.h:89
static cancellation_token_source create_linked_source(_Iter _Begin, _Iter _End)
Creates a cancellation_token_source which is canceled when one of a series of tokens represented by a...
Definition: pplcancellation_token.h:917
_CancellationTokenRegistration * _M_token
Definition: pplcancellation_token.h:228
_CancellationTokenRegistration * _RegisterCallback(TaskProc_t _PCallback, _In_ void *_PData, int _InitialRefs=1)
Definition: pplcancellation_token.h:386
details::_CancellationTokenState * _ImplType
Definition: pplcancellation_token.h:620
cancellation_token & operator=(cancellation_token &&_Src)
Definition: pplcancellation_token.h:653
static cancellation_token none()
Returns a cancellation token which can never be subject to cancellation.
Definition: pplcancellation_token.h:628
The cancellation_token_source class represents the ability to cancel some cancelable operation...
Definition: pplcancellation_token.h:811
The cancellation_token_registration class represents a callback notification from a cancellation_toke...
Definition: pplcancellation_token.h:520
CancellationTokenRegistration_TaskProc(TaskProc_t _Proc, _In_ void *_PData, int _InitialRefs)
Definition: pplcancellation_token.h:201
cancellation_token_source(cancellation_token_source &&_Src)
Definition: pplcancellation_token.h:830
cancellation_token(cancellation_token &&_Src)
Definition: pplcancellation_token.h:638
_Node(_CancellationTokenRegistration *_Token)
Definition: pplcancellation_token.h:231
void * _M_pData
Definition: pplcancellation_token.h:216
The Concurrency namespace provides classes and functions that provide access to the Concurrency Runti...
Definition: agents.h:43
std::mutex _M_Mutex
Definition: pplcancellation_token.h:170
static cancellation_token_source create_linked_source(cancellation_token &_Src)
Creates a cancellation_token_source which is canceled when the provided token is canceled.
Definition: pplcancellation_token.h:895
Definition: pplcancellation_token.h:197
void _Assign(_ImplType _Impl)
Definition: pplcancellation_token.h:959
std::condition_variable _M_CondVar
Definition: pplcancellation_token.h:169
cancellation_token & operator=(const cancellation_token &_Src)
Definition: pplcancellation_token.h:643
bool operator!=(const cancellation_token_registration &_Rhs) const
Definition: pplcancellation_token.h:569
bool operator==(const cancellation_token_registration &_Rhs) const
Definition: pplcancellation_token.h:564
bool _M_signaled
Definition: pplcancellation_token.h:171
cancellation_token_source(_ImplType _Impl)
Definition: pplcancellation_token.h:974
void _Move(_In_ details::_CancellationTokenRegistration *&_PRegistration)
Definition: pplcancellation_token.h:601
void cancel() const
Cancels the token. Any task_group, structured_task_group, or task which utilizes the token will be ca...
Definition: pplcancellation_token.h:931
virtual ~_CancellationTokenRegistration()
Definition: pplcancellation_token.h:132
TokenRegistrationContainer()
Definition: pplcancellation_token.h:237
void _Cancel()
Definition: pplcancellation_token.h:367
void remove(_CancellationTokenRegistration *_Token)
Definition: pplcancellation_token.h:290
_CancellationTokenRegistration(long _InitialRefs=1)
Definition: pplcancellation_token.h:117
_ImplType _M_Impl
Definition: pplcancellation_token.h:948
::Concurrency::details::_CancellationTokenState * _ImplType
Definition: pplcancellation_token.h:815
~cancellation_token_registration()
Definition: pplcancellation_token.h:529
virtual void _Exec()
Definition: pplcancellation_token.h:187
Definition: pplcancellation_token.h:51
bool _IsCanceled() const
Definition: pplcancellation_token.h:362
cancellation_token_registration(cancellation_token_registration &&_Src)
Definition: pplcancellation_token.h:539
cancellation_token_registration()
Definition: pplcancellation_token.h:524
cancellation_token_source & operator=(const cancellation_token_source &_Src)
Definition: pplcancellation_token.h:835
void _Clear()
Definition: pplcancellation_token.h:583
#define _In_
Definition: sal.h:305
void _Move(_ImplType &_Impl)
Definition: pplcancellation_token.h:782
void _RegisterCallback(_In_ _CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:393
Node * _M_begin
Definition: pplcancellation_token.h:322
void _DeregisterCallback(_In_ _CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:418
#define _In_opt_
Definition: sal.h:306
bool operator==(const cancellation_token_source &_Src) const
Definition: pplcancellation_token.h:855
std::mutex _M_listLock
Definition: pplcancellation_token.h:502
static _CancellationTokenState * _NewTokenState()
Definition: pplcancellation_token.h:327
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:332
_CancellationTokenState * _GetToken() const
Definition: pplcancellation_token.h:125
cancellation_token_registration(_In_ details::_CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:578
void swap(array< _Ty, _Size > &_Left, array< _Ty, _Size > &_Right) _NOEXCEPT_OP(_NOEXCEPT_OP(_Left.swap(_Right)))
Definition: array:433
Definition: pplcancellation_token.h:106
cancellation_token_source()
Constructs a new cancellation_token_source. The source can be used to flag cancellation of some cance...
Definition: pplcancellation_token.h:820
Definition: pplcancellation_token.h:224
struct Concurrency::details::_CancellationTokenState::TokenRegistrationContainer::_Node Node
virtual ~_RefCounter()
Definition: pplcancellation_token.h:55
#define false
Definition: stdbool.h:16
::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...
Definition: pplcancellation_token.h:717
TaskProc_t _M_proc
Definition: pplcancellation_token.h:215
~_CancellationTokenState()
Definition: pplcancellation_token.h:347
atomic_long _M_stateFlag
Definition: pplcancellation_token.h:499
_CancellationTokenState * _M_pTokenState
Definition: pplcancellation_token.h:172
Definition: pplcancellation_token.h:227
void _Invoke()
Definition: pplcancellation_token.h:143
virtual void _Exec()
Definition: pplcancellation_token.h:208
Node * _M_last
Definition: pplcancellation_token.h:323
void(__cdecl * TaskProc_t)(void *)
An elementary abstraction for a task, defined as void (__cdecl * TaskProc_t)(void *)...
Definition: pplinterface.h:32
static bool _IsValid(_In_opt_ _CancellationTokenState *_PToken)
Definition: pplcancellation_token.h:337
~cancellation_token()
Definition: pplcancellation_token.h:673
cancellation_token()
Definition: pplcancellation_token.h:788
long _Reference()
Definition: pplcancellation_token.h:62
_CancellationTokenState()
Definition: pplcancellation_token.h:342
_ImplType _GetImpl() const
Definition: pplcancellation_token.h:936
cancellation_token(_ImplType _Impl)
Definition: pplcancellation_token.h:793
Definition: pplcancellation_token.h:221
TokenRegistrationContainer _M_registrations
Definition: pplcancellation_token.h:505
void _Clear()
Definition: pplcancellation_token.h:950
bool is_cancelable() const
Returns an indication of whether this token can be canceled or not.
Definition: pplcancellation_token.h:684
long __cdecl _InterlockedDecrement(long volatile *)
bool operator==(const cancellation_token &_Src) const
Definition: pplcancellation_token.h:663
void _Clear()
Definition: pplcancellation_token.h:764
_ImplType _GetImplValue() const
Definition: pplcancellation_token.h:748
~TokenRegistrationContainer()
Definition: pplcancellation_token.h:241
long _Release()
Definition: pplcancellation_token.h:73
static const long _STATE_CLEAR
Definition: pplcancellation_token.h:110
void _Assign(_In_ details::_CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:592
std::atomic< long > atomic_long
Atomics
Definition: pplinterface.h:234
details::_CancellationTokenRegistration * _M_pRegistration
Definition: pplcancellation_token.h:607
_Node * _M_next
Definition: pplcancellation_token.h:229
void deregister_callback(const cancellation_token_registration &_Registration) const
Removes a callback previously registered via the register method based on the cancellation_token_regi...
Definition: pplcancellation_token.h:738
long __cdecl _InterlockedIncrement(long volatile *)
_Function _M_function
Definition: pplcancellation_token.h:194
void push_back(_CancellationTokenRegistration *_Token)
Definition: pplcancellation_token.h:275
void _Move(_ImplType &_Impl)
Definition: pplcancellation_token.h:968
_RefCounter(long _InitialCount=1)
Definition: pplcancellation_token.h:95
Definition: pplcancellation_token.h:176
void _Assign(_ImplType _Impl)
Definition: pplcancellation_token.h:773
static cancellation_token _FromImpl(_ImplType _Impl)
Definition: pplcancellation_token.h:753
bool operator!=(const cancellation_token_source &_Src) const
Definition: pplcancellation_token.h:860
cancellation_token_source & operator=(cancellation_token_source &&_Src)
Definition: pplcancellation_token.h:845
cancellation_token_registration & operator=(const cancellation_token_registration &_Src)
Definition: pplcancellation_token.h:544
bool operator!=(const cancellation_token &_Src) const
Definition: pplcancellation_token.h:668
void for_each(_Ty _Lambda)
Definition: pplcancellation_token.h:264
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
_CancellationTokenCallback(const _Function &_Func)
Definition: pplcancellation_token.h:180
The cancellation_token class represents the ability to determine whether some operation has been requ...
Definition: pplcancellation_token.h:616