29 #error This header must not be included directly
32 #ifndef _PPLCANCELLATION_TOKEN_H
33 #define _PPLCANCELLATION_TOKEN_H
37 #pragma pack(push,_CRT_PACKING)
39 #pragma push_macro("new")
134 virtual void _Exec() = 0;
147 if (result == _STATE_CLEAR)
153 if (result == _STATE_SYNCHRONIZE)
166 template<
typename _Function>
231 while (node !=
nullptr)
255 while (node !=
nullptr)
264 Node* node =
reinterpret_cast<Node*
>(::malloc(
sizeof(
Node)));
267 throw ::std::bad_alloc();
290 while (node !=
nullptr)
335 return (_PToken !=
NULL && _PToken !=
_None());
387 return pRegistration;
393 _PRegistration->_Reference();
394 _PRegistration->_M_pTokenState =
this;
411 _PRegistration->_Invoke();
417 bool synchronize =
false;
431 _PRegistration->_Release();
450 _PRegistration->_M_state,
478 _PRegistration->_M_pSyncBlock = &ev;
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
TaskProc_t m_proc
Definition: pplcancellation_token.h:206
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:111
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:154
~cancellation_token_source()
Definition: pplcancellation_token.h:865
This class describes an exception thrown when an invalid operation is performed that is not more accu...
Definition: concrt.h:1705
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:109
static const long _STATE_SYNCHRONIZE
Definition: pplcancellation_token.h:110
_ImplType _GetImpl() const
Definition: pplcancellation_token.h:743
atomic_long _M_state
Definition: pplcancellation_token.h:161
bool empty()
Definition: pplcancellation_token.h:245
_T atomic_compare_exchange(std::atomic< _T > &_Target, _T _Exchange, _T _Comparand)
Definition: pplinterface.h:146
cancellation_token_registration & operator=(cancellation_token_registration &&_Src)
Definition: pplcancellation_token.h:554
volatile long _M_refCount
Definition: pplcancellation_token.h:99
cancellation_token_registration(const cancellation_token_registration &_Src)
Definition: pplcancellation_token.h:534
extensibility::event_t * _M_pSyncBlock
Definition: pplcancellation_token.h:162
virtual void _Destroy()
Definition: pplcancellation_token.h:87
static _CancellationTokenState * _CancellationTokenState::_NewTokenState()
Definition: pplcancellation_token.h:323
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:219
_CancellationTokenRegistration * _RegisterCallback(TaskProc_t _PCallback, _In_ void *_PData, int _InitialRefs=1)
Definition: pplcancellation_token.h:383
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
cancellation_token_source(cancellation_token_source &&_Src)
Definition: pplcancellation_token.h:830
extensibility::event_t _M_cancelComplete
Definition: pplcancellation_token.h:499
cancellation_token(cancellation_token &&_Src)
Definition: pplcancellation_token.h:638
void push_back(_CancellationTokenRegistration *token)
Definition: pplcancellation_token.h:262
The Concurrency namespace provides classes and functions that provide access to the Concurrency Runti...
Definition: agents.h:42
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
_CRTIMP _CRTNOALIAS void __cdecl free(_Pre_maybenull_ _Post_invalid_ void *_Memory)
Definition: pplcancellation_token.h:188
void _Assign(_ImplType _Impl)
Definition: pplcancellation_token.h:959
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
#define NULL
Definition: crtdbg.h:30
cancellation_token_source(_ImplType _Impl)
Definition: pplcancellation_token.h:974
CancellationTokenRegistration_TaskProc(TaskProc_t proc, _In_ void *pData, int initialRefs)
Definition: pplcancellation_token.h:192
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:129
TokenRegistrationContainer()
Definition: pplcancellation_token.h:224
void _Cancel()
Definition: pplcancellation_token.h:363
_CancellationTokenRegistration(long _InitialRefs=1)
Definition: pplcancellation_token.h:115
_ImplType _M_Impl
Definition: pplcancellation_token.h:948
A non-reentrant mutex which is explicitly aware of the Concurrency Runtime.
Definition: concrt.h:3548
::Concurrency::details::_CancellationTokenState * _ImplType
Definition: pplcancellation_token.h:815
~cancellation_token_registration()
Definition: pplcancellation_token.h:529
virtual void _Exec()
Definition: pplcancellation_token.h:178
Definition: pplcancellation_token.h:49
bool _IsCanceled() const
Definition: pplcancellation_token.h:358
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
_CRTIMP void set()
Signals the event.
#define _ASSERTE(expr)
Definition: crtdbg.h:216
void _Clear()
Definition: pplcancellation_token.h:583
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
#define _In_
Definition: sal.h:314
void _Move(_ImplType &_Impl)
Definition: pplcancellation_token.h:782
void _RegisterCallback(_In_ _CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:390
Node * _M_begin
Definition: pplcancellation_token.h:317
void _DeregisterCallback(_In_ _CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:415
#define _In_opt_
Definition: sal.h:315
bool operator==(const cancellation_token_source &_Src) const
Definition: pplcancellation_token.h:855
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:328
_CancellationTokenState * _GetToken() const
Definition: pplcancellation_token.h:122
void swap(TokenRegistrationContainer &list)
Definition: pplcancellation_token.h:239
cancellation_token_registration(_In_ details::_CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:578
Definition: pplcancellation_token.h:104
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:215
struct Concurrency::details::_CancellationTokenState::TokenRegistrationContainer::_Node Node
void remove(_CancellationTokenRegistration *token)
Definition: pplcancellation_token.h:285
virtual ~_RefCounter()
Definition: pplcancellation_token.h:53
_BidIt prev(_BidIt _First, typename iterator_traits< _BidIt >::difference_type _Off=1)
Definition: xutility:784
::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
~_CancellationTokenState()
Definition: pplcancellation_token.h:343
atomic_long _M_stateFlag
Definition: pplcancellation_token.h:496
_CancellationTokenState * _M_pTokenState
Definition: pplcancellation_token.h:163
Definition: pplcancellation_token.h:218
void _Invoke()
Definition: pplcancellation_token.h:140
virtual void _Exec()
Definition: pplcancellation_token.h:199
Node * _M_last
Definition: pplcancellation_token.h:318
void(__cdecl * TaskProc_t)(void *)
An elementary abstraction for a task, defined as void (__cdecl * TaskProc_t)(void *)...
Definition: pplinterface.h:43
static bool _IsValid(_In_opt_ _CancellationTokenState *_PToken)
Definition: pplcancellation_token.h:333
~cancellation_token()
Definition: pplcancellation_token.h:673
void swap(array< _Ty, _Size > &_Left, array< _Ty, _Size > &_Right) _NOEXCEPT_OP(_NOEXCEPT_OP(_Left.swap(_Right)))
Definition: array:429
cancellation_token()
Definition: pplcancellation_token.h:788
long _Reference()
Definition: pplcancellation_token.h:60
_CancellationTokenState()
Definition: pplcancellation_token.h:338
_ImplType _GetImpl() const
Definition: pplcancellation_token.h:936
static const unsigned int timeout_infinite
Value indicating that a wait should never time out.
Definition: concrt.h:4076
extensibility::critical_section_t _M_listLock
Definition: pplcancellation_token.h:502
cancellation_token(_ImplType _Impl)
Definition: pplcancellation_token.h:793
Definition: pplcancellation_token.h:212
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:228
long _Release()
Definition: pplcancellation_token.h:71
void for_each(T lambda)
Definition: pplcancellation_token.h:251
static const long _STATE_CLEAR
Definition: pplcancellation_token.h:108
void _Assign(_In_ details::_CancellationTokenRegistration *_PRegistration)
Definition: pplcancellation_token.h:592
std::atomic< long > atomic_long
Atomics
Definition: pplinterface.h:142
details::_CancellationTokenRegistration * _M_pRegistration
Definition: pplcancellation_token.h:607
_Node * _M_next
Definition: pplcancellation_token.h:220
A manual reset event which is explicitly aware of the Concurrency Runtime.
Definition: concrt.h:3982
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:185
An exception safe RAII wrapper for a critical_section object.
Definition: concrt.h:3661
void _Move(_ImplType &_Impl)
Definition: pplcancellation_token.h:968
_RefCounter(long _InitialCount=1)
Definition: pplcancellation_token.h:93
Definition: pplcancellation_token.h:167
void * m_pData
Definition: pplcancellation_token.h:207
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
_ImplType _M_Impl
Definition: pplcancellation_token.h:762
_CancellationTokenCallback(const _Function &_Func)
Definition: pplcancellation_token.h:171
The cancellation_token class represents the ability to determine whether some operation has been requ...
Definition: pplcancellation_token.h:616