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 * pplcancellation_token.h
20 *
21 * Parallel Patterns Library : cancellation_token
22 *
23 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
24 ****/
25 
26 #pragma once
27 
28 #ifndef _PPLWIN_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 #include <mutex>
37 #include <condition_variable>
38 
39 #pragma pack(push,_CRT_PACKING)
40 // All header files are required to be protected from the macro new
41 #pragma push_macro("new")
42 #undef new
43 
44 namespace Concurrency
45 {
46 
47 namespace details
48 {
49 
50  // Base class for all reference counted objects
52  {
53  public:
54 
55  virtual ~_RefCounter()
56  {
57  _ASSERTE(_M_refCount == 0);
58  }
59 
60  // Acquires a reference
61  // Returns the new reference count.
62  long _Reference()
63  {
64  long _Refcount = _InterlockedIncrement(&_M_refCount);
65 
66  // 0 - 1 transition is illegal
67  _ASSERTE(_Refcount > 1);
68  return _Refcount;
69  }
70 
71  // Releases the reference
72  // Returns the new reference count
73  long _Release()
74  {
75  long _Refcount = _InterlockedDecrement(&_M_refCount);
76  _ASSERTE(_Refcount >= 0);
77 
78  if (_Refcount == 0)
79  {
80  _Destroy();
81  }
82 
83  return _Refcount;
84  }
85 
86  protected:
87 
88  // Allow derived classes to provide their own deleter
89  virtual void _Destroy()
90  {
91  delete this;
92  }
93 
94  // Only allow instantiation through derived class
95  _RefCounter(long _InitialCount = 1) : _M_refCount(_InitialCount)
96  {
97  _ASSERTE(_M_refCount > 0);
98  }
99 
100  // Reference count
101  volatile long _M_refCount;
102  };
103 
105 
107  {
108  private:
109 
110  static const long _STATE_CLEAR = 0;
111  static const long _STATE_DEFER_DELETE = 1;
112  static const long _STATE_SYNCHRONIZE = 2;
113  static const long _STATE_CALLED = 3;
114 
115  public:
116 
117  _CancellationTokenRegistration(long _InitialRefs = 1) :
118  _RefCounter(_InitialRefs),
119  _M_state(_STATE_CALLED),
122  {
123  }
124 
126  {
127  return _M_pTokenState;
128  }
129 
130  protected:
131 
133  {
134  _ASSERTE(_M_state != _STATE_CLEAR);
135  }
136 
137  virtual void _Exec() = 0;
138 
139  private:
140 
142 
143  void _Invoke()
144  {
146  _ASSERTE((_Tid & 0x3) == 0); // If this ever fires, we need a different encoding for this.
147 
148  long _Result = atomic_compare_exchange(_M_state, _Tid, _STATE_CLEAR);
149 
150  if (_Result == _STATE_CLEAR)
151  {
152  _Exec();
153 
154  _Result = atomic_compare_exchange(_M_state, _STATE_CALLED, _Tid);
155 
156  if (_Result == _STATE_SYNCHRONIZE)
157  {
158  {
159  std::lock_guard<std::mutex> _Lock(_M_Mutex);
160  _M_signaled = true;
161  }
162  _M_CondVar.notify_all();
163  }
164  }
165  _Release();
166  }
167 
169  std::condition_variable _M_CondVar;
170  std::mutex _M_Mutex;
173  };
174 
175  template<typename _Function>
177  {
178  public:
179 
180  _CancellationTokenCallback(const _Function& _Func) :
181  _M_function(_Func)
182  {
183  }
184 
185  protected:
186 
187  virtual void _Exec()
188  {
189  _M_function();
190  }
191 
192  private:
193 
194  _Function _M_function;
195  };
196 
198  {
199  public:
200 
201  CancellationTokenRegistration_TaskProc(TaskProc_t _Proc, _In_ void *_PData, int _InitialRefs) :
202  _CancellationTokenRegistration(_InitialRefs), _M_proc(_Proc), _M_pData(_PData)
203  {
204  }
205 
206  protected:
207 
208  virtual void _Exec()
209  {
210  _M_proc(_M_pData);
211  }
212 
213  private:
214 
216  void *_M_pData;
217 
218  };
219 
220  // The base implementation of a cancellation token.
222  {
223  protected:
225  {
226  private:
227  typedef struct _Node {
230 
231  _Node(_CancellationTokenRegistration* _Token) : _M_token(_Token), _M_next(nullptr)
232  {
233  }
234  } Node;
235 
236  public:
238  {
239  }
240 
242  {
243  auto _Node = _M_begin;
244  while (_Node != nullptr)
245  {
246  Node* _Tmp = _Node;
247  _Node = _Node->_M_next;
248  delete _Tmp;
249  }
250  }
251 
253  {
254  std::swap(_List._M_begin, _M_begin);
255  std::swap(_List._M_last, _M_last);
256  }
257 
258  bool empty()
259  {
260  return _M_begin == nullptr;
261  }
262 
263  template<typename _Ty>
264  void for_each(_Ty _Lambda)
265  {
266  Node* _Node = _M_begin;
267 
268  while (_Node != nullptr)
269  {
270  _Lambda(_Node->_M_token);
271  _Node = _Node->_M_next;
272  }
273  }
274 
276  {
277  auto _Node = new Node(_Token);
278  if (_M_begin == nullptr)
279  {
280  _M_begin = _Node;
281  }
282  else
283  {
284  _M_last->_M_next = _Node;
285  }
286 
287  _M_last = _Node;
288  }
289 
290  void remove(_CancellationTokenRegistration* _Token)
291  {
292  Node* _Node = _M_begin;
293  Node* _Prev = nullptr;
294 
295  while (_Node != nullptr)
296  {
297  if (_Node->_M_token == _Token) {
298  if (_Prev == nullptr)
299  {
300  _M_begin = _Node->_M_next;
301  }
302  else
303  {
304  _Prev->_M_next = _Node->_M_next;
305  }
306 
307  if (_Node->_M_next == nullptr)
308  {
309  _M_last = _Prev;
310  }
311 
312  delete _Node;
313  break;
314  }
315 
316  _Prev = _Node;
317  _Node = _Node->_M_next;
318  }
319  }
320 
321  private:
324  };
325 
326  public:
328  {
329  return new _CancellationTokenState();
330  }
331 
333  {
334  return reinterpret_cast<_CancellationTokenState *>(2);
335  }
336 
338  {
339  return (_PToken != NULL && _PToken != _None());
340  }
341 
343  _M_stateFlag(0)
344  {
345  }
346 
348  {
349  TokenRegistrationContainer _RundownList;
350  {
351  std::lock_guard<std::mutex> _Lock(_M_listLock);
352  _M_registrations.swap(_RundownList);
353  }
354 
355  _RundownList.for_each([](_CancellationTokenRegistration * _PRegistration)
356  {
358  _PRegistration->_Release();
359  });
360  }
361 
362  bool _IsCanceled() const
363  {
364  return (_M_stateFlag != 0);
365  }
366 
367  void _Cancel()
368  {
369  if (atomic_compare_exchange(_M_stateFlag, 1l, 0l) == 0)
370  {
371  TokenRegistrationContainer _RundownList;
372  {
373  std::lock_guard<std::mutex> _Lock(_M_listLock);
374  _M_registrations.swap(_RundownList);
375  }
376 
377  _RundownList.for_each([](_CancellationTokenRegistration * _PRegistration)
378  {
379  _PRegistration->_Invoke();
380  });
381 
382  _M_stateFlag = 2;
383  }
384  }
385 
386  _CancellationTokenRegistration *_RegisterCallback(TaskProc_t _PCallback, _In_ void *_PData, int _InitialRefs = 1)
387  {
388  _CancellationTokenRegistration *_PRegistration = new CancellationTokenRegistration_TaskProc(_PCallback, _PData, _InitialRefs);
389  _RegisterCallback(_PRegistration);
390  return _PRegistration;
391  }
392 
394  {
395  _PRegistration->_M_state = _CancellationTokenRegistration::_STATE_CLEAR;
396  _PRegistration->_Reference();
397  _PRegistration->_M_pTokenState = this;
398 
399  bool _Invoke = true;
400 
401  if (!_IsCanceled())
402  {
403  std::lock_guard<std::mutex> _Lock(_M_listLock);
404 
405  if (!_IsCanceled())
406  {
407  _Invoke = false;
408  _M_registrations.push_back(_PRegistration);
409  }
410  }
411 
412  if (_Invoke)
413  {
414  _PRegistration->_Invoke();
415  }
416  }
417 
419  {
420  bool _Synchronize = false;
421 
422  {
423  std::lock_guard<std::mutex> _Lock(_M_listLock);
424 
425  //
426  // If a cancellation has occurred, the registration list is guaranteed to be empty if we've observed it under the auspices of the
427  // lock. In this case, we must synchronize with the cancelling thread to guarantee that the cancellation is finished by the time
428  // we return from this method.
429  //
430  if (!_M_registrations.empty())
431  {
432  _M_registrations.remove(_PRegistration);
433  _PRegistration->_M_state = _CancellationTokenRegistration::_STATE_SYNCHRONIZE;
434  _PRegistration->_Release();
435  }
436  else
437  {
438  _Synchronize = true;
439  }
440  }
441 
442  //
443  // If the list is empty, we are in one of several situations:
444  //
445  // - The callback has already been made --> do nothing
446  // - The callback is about to be made --> flag it so it doesn't happen and return
447  // - The callback is in progress elsewhere --> synchronize with it
448  // - The callback is in progress on this thread --> do nothing
449  //
450  if (_Synchronize)
451  {
452  long _Result = atomic_compare_exchange(
453  _PRegistration->_M_state,
456  );
457 
458  switch(_Result)
459  {
462  break;
465  _ASSERTE(false);
466  break;
467  default:
468  {
470  {
471  //
472  // It is entirely legal for a caller to Deregister during a callback instead of having to provide their own synchronization
473  // mechanism between the two. In this case, we do *NOT* need to explicitly synchronize with the callback as doing so would
474  // deadlock. If the call happens during, skip any extra synchronization.
475  //
476  break;
477  }
478 
479  long _Result_1 = atomic_exchange(_PRegistration->_M_state, _CancellationTokenRegistration::_STATE_SYNCHRONIZE);
480 
482  {
483  std::unique_lock<std::mutex> _Lock(_PRegistration->_M_Mutex);
484  _PRegistration->_M_CondVar.wait(_Lock,
485  [_PRegistration]{ return _PRegistration->_M_signaled; });
486 
487  _ASSERTE(_PRegistration->_M_signaled);
488  }
489 
490  break;
491  }
492  }
493  }
494  }
495 
496  private:
497 
498  // The flag for the token state (whether it is canceled or not)
500 
501  // Lock to protect the registrations list
502  std::mutex _M_listLock;
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 
855  bool operator==(const cancellation_token_source& _Src) const
856  {
857  return _M_Impl == _Src._M_Impl;
858  }
859 
860  bool operator!=(const cancellation_token_source& _Src) const
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
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
_CRTIMP2 long __cdecl GetCurrentThreadId()
_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
_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
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
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
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
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
void _Invoke()
Definition: pplcancellation_token.h:143
virtual void _Exec()
Definition: pplcancellation_token.h:208
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
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