STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pplcancellation_token.h
Go to the documentation of this file.
1 /***
2 * ==++==
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * ==--==
17 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
18 *
19 * pplxcancellation_token.h
20 *
21 * Parallel Patterns Library : cancellation_token
22 *
23 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
24 ****/
25 
26 #pragma once
27 
28 #ifndef _PPLCONCRT_H
29 #error This header must not be included directly
30 #endif
31 
32 #ifndef _PPLCANCELLATION_TOKEN_H
33 #define _PPLCANCELLATION_TOKEN_H
34 
35 #include <pplinterface.h>
36 
37 #pragma pack(push,_CRT_PACKING)
38 // All header files are required to be protected from the macro new
39 #pragma push_macro("new")
40 #undef new
41 
42 namespace Concurrency
43 {
44 
45 namespace details
46 {
47 
48  // Base class for all reference counted objects
50  {
51  public:
52 
53  virtual ~_RefCounter()
54  {
55  _ASSERTE(_M_refCount == 0);
56  }
57 
58  // Acquires a reference
59  // Returns the new reference count.
60  long _Reference()
61  {
62  long _Refcount = _InterlockedIncrement(&_M_refCount);
63 
64  // 0 - 1 transition is illegal
65  _ASSERTE(_Refcount > 1);
66  return _Refcount;
67  }
68 
69  // Releases the reference
70  // Returns the new reference count
71  long _Release()
72  {
73  long _Refcount = _InterlockedDecrement(&_M_refCount);
74  _ASSERTE(_Refcount >= 0);
75 
76  if (_Refcount == 0)
77  {
78  _Destroy();
79  }
80 
81  return _Refcount;
82  }
83 
84  protected:
85 
86  // Allow derived classes to provide their own deleter
87  virtual void _Destroy()
88  {
89  delete this;
90  }
91 
92  // Only allow instantiation through derived class
93  _RefCounter(long _InitialCount = 1) : _M_refCount(_InitialCount)
94  {
95  _ASSERTE(_M_refCount > 0);
96  }
97 
98  // Reference count
99  volatile long _M_refCount;
100  };
101 
103 
105  {
106  private:
107 
108  static const long _STATE_CLEAR = 0;
109  static const long _STATE_DEFER_DELETE = 1;
110  static const long _STATE_SYNCHRONIZE = 2;
111  static const long _STATE_CALLED = 3;
112 
113  public:
114 
115  _CancellationTokenRegistration(long _InitialRefs = 1) :
116  _RefCounter(_InitialRefs),
117  _M_state(_STATE_CALLED),
119  {
120  }
121 
123  {
124  return _M_pTokenState;
125  }
126 
127  protected:
128 
130  {
131  _ASSERTE(_M_state != _STATE_CLEAR);
132  }
133 
134  virtual void _Exec() = 0;
135 
136  private:
137 
139 
140  void _Invoke()
141  {
143  _ASSERTE((tid & 0x3) == 0); // If this ever fires, we need a different encoding for this.
144 
145  long result = atomic_compare_exchange(_M_state, tid, _STATE_CLEAR);
146 
147  if (result == _STATE_CLEAR)
148  {
149  _Exec();
150 
151  result = atomic_compare_exchange(_M_state, _STATE_CALLED, tid);
152 
153  if (result == _STATE_SYNCHRONIZE)
154  {
155  _M_pSyncBlock->set();
156  }
157  }
158  _Release();
159  }
160 
164  };
165 
166  template<typename _Function>
168  {
169  public:
170 
171  _CancellationTokenCallback(const _Function& _Func) :
172  _M_function(_Func)
173  {
174  }
175 
176  protected:
177 
178  virtual void _Exec()
179  {
180  _M_function();
181  }
182 
183  private:
184 
185  _Function _M_function;
186  };
187 
189  {
190  public:
191 
192  CancellationTokenRegistration_TaskProc(TaskProc_t proc, _In_ void *pData, int initialRefs) :
193  _CancellationTokenRegistration(initialRefs), m_proc(proc), m_pData(pData)
194  {
195  }
196 
197  protected:
198 
199  virtual void _Exec()
200  {
201  m_proc(m_pData);
202  }
203 
204  private:
205 
207  void *m_pData;
208 
209  };
210 
211  // The base implementation of a cancellation token.
213  {
214  protected:
216  {
217  private:
218  typedef struct _Node {
221  } Node;
222 
223  public:
225  {
226  }
227 
229  {
230  auto node = _M_begin;
231  while (node != nullptr)
232  {
233  Node* tmp = node;
234  node = node->_M_next;
235  ::free(tmp);
236  }
237  }
238 
240  {
241  std::swap(list._M_begin, _M_begin);
242  std::swap(list._M_last, _M_last);
243  }
244 
245  bool empty()
246  {
247  return _M_begin == nullptr;
248  }
249 
250  template<typename T>
251  void for_each(T lambda)
252  {
253  Node* node = _M_begin;
254 
255  while (node != nullptr)
256  {
257  lambda(node->_M_token);
258  node = node->_M_next;
259  }
260  }
261 
263  {
264  Node* node = reinterpret_cast<Node*>(::malloc(sizeof(Node)));
265  if (node == nullptr)
266  {
267  throw ::std::bad_alloc();
268  }
269 
270  node->_M_token = token;
271  node->_M_next = nullptr;
272 
273  if (_M_begin == nullptr)
274  {
275  _M_begin = node;
276  }
277  else
278  {
279  _M_last->_M_next = node;
280  }
281 
282  _M_last = node;
283  }
284 
285  void remove(_CancellationTokenRegistration* token)
286  {
287  Node* node = _M_begin;
288  Node* prev = nullptr;
289 
290  while (node != nullptr)
291  {
292  if (node->_M_token == token) {
293  if (prev == nullptr)
294  {
295  _M_begin = node->_M_next;
296  }
297  else
298  {
299  prev->_M_next = node->_M_next;
300  }
301 
302  if (node->_M_next == nullptr)
303  {
304  _M_last = prev;
305  }
306 
307  ::free(node);
308  break;
309  }
310 
311  prev = node;
312  node = node->_M_next;
313  }
314  }
315 
316  private:
319  };
320 
321  public:
322 
324  {
325  return new _CancellationTokenState();
326  }
327 
329  {
330  return reinterpret_cast<_CancellationTokenState *>(2);
331  }
332 
334  {
335  return (_PToken != NULL && _PToken != _None());
336  }
337 
339  _M_stateFlag(0)
340  {
341  }
342 
344  {
345  TokenRegistrationContainer rundownList;
346  {
348  _M_registrations.swap(rundownList);
349  }
350 
351  rundownList.for_each([](_CancellationTokenRegistration * pRegistration)
352  {
354  pRegistration->_Release();
355  });
356  }
357 
358  bool _IsCanceled() const
359  {
360  return (_M_stateFlag != 0);
361  }
362 
363  void _Cancel()
364  {
365  if (atomic_compare_exchange(_M_stateFlag, 1l, 0l) == 0)
366  {
367  TokenRegistrationContainer rundownList;
368  {
370  _M_registrations.swap(rundownList);
371  }
372 
373  rundownList.for_each([](_CancellationTokenRegistration * pRegistration)
374  {
375  pRegistration->_Invoke();
376  });
377 
378  _M_stateFlag = 2;
380  }
381  }
382 
383  _CancellationTokenRegistration *_RegisterCallback(TaskProc_t _PCallback, _In_ void *_PData, int _InitialRefs = 1)
384  {
385  _CancellationTokenRegistration *pRegistration = new CancellationTokenRegistration_TaskProc(_PCallback, _PData, _InitialRefs);
386  _RegisterCallback(pRegistration);
387  return pRegistration;
388  }
389 
391  {
392  _PRegistration->_M_state = _CancellationTokenRegistration::_STATE_CLEAR;
393  _PRegistration->_Reference();
394  _PRegistration->_M_pTokenState = this;
395 
396  bool invoke = true;
397 
398  if (!_IsCanceled())
399  {
401 
402  if (!_IsCanceled())
403  {
404  invoke = false;
405  _M_registrations.push_back(_PRegistration);
406  }
407  }
408 
409  if (invoke)
410  {
411  _PRegistration->_Invoke();
412  }
413  }
414 
416  {
417  bool synchronize = false;
418 
419  {
421 
422  //
423  // If a cancellation has occurred, the registration list is guaranteed to be empty if we've observed it under the auspices of the
424  // lock. In this case, we must synchronize with the cancelling thread to guarantee that the cancellation is finished by the time
425  // we return from this method.
426  //
427  if (!_M_registrations.empty())
428  {
429  _M_registrations.remove(_PRegistration);
430  _PRegistration->_M_state = _CancellationTokenRegistration::_STATE_SYNCHRONIZE;
431  _PRegistration->_Release();
432  }
433  else
434  {
435  synchronize = true;
436  }
437  }
438 
439  //
440  // If the list is empty, we are in one of several situations:
441  //
442  // - The callback has already been made --> do nothing
443  // - The callback is about to be made --> flag it so it doesn't happen and return
444  // - The callback is in progress elsewhere --> synchronize with it
445  // - The callback is in progress on this thread --> do nothing
446  //
447  if (synchronize)
448  {
449  long result = atomic_compare_exchange(
450  _PRegistration->_M_state,
453  );
454 
455  switch(result)
456  {
459  break;
462  _ASSERTE(false);
463  break;
464  default:
465  {
466  long tid = result;
468  {
469  //
470  // It is entirely legal for a caller to Deregister during a callback instead of having to provide their own synchronization
471  // mechanism between the two. In this case, we do *NOT* need to explicitly synchronize with the callback as doing so would
472  // deadlock. If the call happens during, skip any extra synchronization.
473  //
474  break;
475  }
476 
478  _PRegistration->_M_pSyncBlock = &ev;
479 
480  long result_1 = atomic_exchange(_PRegistration->_M_state, _CancellationTokenRegistration::_STATE_SYNCHRONIZE);
481 
483  {
484  _PRegistration->_M_pSyncBlock->wait(::Concurrency::extensibility::event_t::timeout_infinite);
485  }
486 
487  break;
488  }
489  }
490  }
491  }
492 
493  private:
494 
495  // The flag for the token state (whether it is canceled or not)
497 
498  // Notification of completion of cancellation of this token.
499  extensibility::event_t _M_cancelComplete; // Hmm.. where do we wait for it??
500 
501  // Lock to protect the registrations list
503 
504  // The protected list of registrations
506  };
507 
508 } // namespace details
509 
511 class cancellation_token;
512 
513 
521 {
522 public:
523 
526  {
527  }
528 
530  {
531  _Clear();
532  }
533 
535  {
537  }
538 
540  {
541  _Move(_Src._M_pRegistration);
542  }
543 
545  {
546  if (this != &_Src)
547  {
548  _Clear();
550  }
551  return *this;
552  }
553 
555  {
556  if (this != &_Src)
557  {
558  _Clear();
559  _Move(_Src._M_pRegistration);
560  }
561  return *this;
562  }
563 
565  {
566  return _M_pRegistration == _Rhs._M_pRegistration;
567  }
568 
570  {
571  return !(operator==(_Rhs));
572  }
573 
574 private:
575 
576  friend class cancellation_token;
577 
579  _M_pRegistration(_PRegistration)
580  {
581  }
582 
583  void _Clear()
584  {
585  if (_M_pRegistration != NULL)
586  {
588  }
590  }
591 
593  {
594  if (_PRegistration != NULL)
595  {
596  _PRegistration->_Reference();
597  }
598  _M_pRegistration = _PRegistration;
599  }
600 
602  {
603  _M_pRegistration = _PRegistration;
604  _PRegistration = NULL;
605  }
606 
608 };
609 
610 
617 {
618 public:
619 
621 
629  {
630  return cancellation_token();
631  }
632 
634  {
635  _Assign(_Src._M_Impl);
636  }
637 
639  {
640  _Move(_Src._M_Impl);
641  }
642 
644  {
645  if (this != &_Src)
646  {
647  _Clear();
648  _Assign(_Src._M_Impl);
649  }
650  return *this;
651  }
652 
654  {
655  if (this != &_Src)
656  {
657  _Clear();
658  _Move(_Src._M_Impl);
659  }
660  return *this;
661  }
662 
663  bool operator==(const cancellation_token& _Src) const
664  {
665  return _M_Impl == _Src._M_Impl;
666  }
667 
668  bool operator!=(const cancellation_token& _Src) const
669  {
670  return !(operator==(_Src));
671  }
672 
674  {
675  _Clear();
676  }
677 
684  bool is_cancelable() const
685  {
686  return (_M_Impl != NULL);
687  }
688 
695  bool is_canceled() const
696  {
697  return (_M_Impl != NULL && _M_Impl->_IsCanceled());
698  }
699 
716  template<typename _Function>
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)
726  _M_Impl->_RegisterCallback(_PCallback);
727  return cancellation_token_registration(_PCallback);
728  }
729 
738  void deregister_callback(const cancellation_token_registration& _Registration) const
739  {
741  }
742 
743  _ImplType _GetImpl() const
744  {
745  return _M_Impl;
746  }
747 
748  _ImplType _GetImplValue() const
749  {
751  }
752 
753  static cancellation_token _FromImpl(_ImplType _Impl)
754  {
755  return cancellation_token(_Impl);
756  }
757 
758 private:
759 
761 
762  _ImplType _M_Impl;
763 
764  void _Clear()
765  {
766  if (_M_Impl != NULL)
767  {
768  _M_Impl->_Release();
769  }
770  _M_Impl = NULL;
771  }
772 
773  void _Assign(_ImplType _Impl)
774  {
775  if (_Impl != NULL)
776  {
777  _Impl->_Reference();
778  }
779  _M_Impl = _Impl;
780  }
781 
782  void _Move(_ImplType &_Impl)
783  {
784  _M_Impl = _Impl;
785  _Impl = NULL;
786  }
787 
789  _M_Impl(NULL)
790  {
791  }
792 
793  cancellation_token(_ImplType _Impl) :
794  _M_Impl(_Impl)
795  {
797  {
798  _M_Impl = NULL;
799  }
800 
801  if (_M_Impl != NULL)
802  {
803  _M_Impl->_Reference();
804  }
805  }
806 };
807 
812 {
813 public:
814 
815  typedef ::Concurrency::details::_CancellationTokenState * _ImplType;
816 
821  {
822  _M_Impl = new ::Concurrency::details::_CancellationTokenState;
823  }
824 
826  {
827  _Assign(_Src._M_Impl);
828  }
829 
831  {
832  _Move(_Src._M_Impl);
833  }
834 
836  {
837  if (this != &_Src)
838  {
839  _Clear();
840  _Assign(_Src._M_Impl);
841  }
842  return *this;
843  }
844 
846  {
847  if (this != &_Src)
848  {
849  _Clear();
850  _Move(_Src._M_Impl);
851  }
852  return *this;
853  }
854 
856  {
857  return _M_Impl == _Src._M_Impl;
858  }
859 
861  {
862  return !(operator==(_Src));
863  }
864 
866  {
867  if (_M_Impl != NULL)
868  {
869  _M_Impl->_Release();
870  }
871  }
872 
881  {
882  return cancellation_token(_M_Impl);
883  }
884 
896  {
897  cancellation_token_source newSource;
898  _Src.register_callback( [newSource](){ newSource.cancel(); } );
899  return newSource;
900  }
901 
916  template<typename _Iter>
917  static cancellation_token_source create_linked_source(_Iter _Begin, _Iter _End)
918  {
919  cancellation_token_source newSource;
920  for (_Iter _It = _Begin; _It != _End; ++_It)
921  {
922  _It->register_callback( [newSource](){ newSource.cancel(); } );
923  }
924  return newSource;
925  }
926 
931  void cancel() const
932  {
933  _M_Impl->_Cancel();
934  }
935 
936  _ImplType _GetImpl() const
937  {
938  return _M_Impl;
939  }
940 
941  static cancellation_token_source _FromImpl(_ImplType _Impl)
942  {
943  return cancellation_token_source(_Impl);
944  }
945 
946 private:
947 
948  _ImplType _M_Impl;
949 
950  void _Clear()
951  {
952  if (_M_Impl != NULL)
953  {
954  _M_Impl->_Release();
955  }
956  _M_Impl = NULL;
957  }
958 
959  void _Assign(_ImplType _Impl)
960  {
961  if (_Impl != NULL)
962  {
963  _Impl->_Reference();
964  }
965  _M_Impl = _Impl;
966  }
967 
968  void _Move(_ImplType &_Impl)
969  {
970  _M_Impl = _Impl;
971  _Impl = NULL;
972  }
973 
974  cancellation_token_source(_ImplType _Impl) :
975  _M_Impl(_Impl)
976  {
978  {
979  _M_Impl = NULL;
980  }
981 
982  if (_M_Impl != NULL)
983  {
984  _M_Impl->_Reference();
985  }
986  }
987 };
988 
989 } // namespace Concurrency
990 
991 #pragma pop_macro("new")
992 #pragma pack(pop)
993 
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
_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
_CRTIMP long __cdecl GetCurrentThreadId()
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)
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
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
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
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
void _Invoke()
Definition: pplcancellation_token.h:140
virtual void _Exec()
Definition: pplcancellation_token.h:199
void(__cdecl * TaskProc_t)(void *)
An elementary abstraction for a task, defined as void (__cdecl * TaskProc_t)(void *)...
Definition: pplinterface.h:43
Definition: list:860
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
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