29 #if defined (__cplusplus_winrt)
34 #define _DBG_ONLY(X) X
37 #endif // #ifdef _DEBUG
39 #ifndef _PPLTASK_ASYNC_LOGGING
40 #define _PPLTASK_ASYNC_LOGGING 1
41 #endif // #ifndef _PPLTASK_ASYNC_LOGGING
43 #if _PPLTASK_ASYNC_LOGGING
44 #pragma detect_mismatch("_PPLTASK_ASYNC_LOGGING", "1")
46 #pragma detect_mismatch("_PPLTASK_ASYNC_LOGGING", "0")
47 #endif // #if _PPLTASK_ASYNC_LOGGING
49 #pragma pack(push,_CRT_PACKING)
52 #pragma warning(disable: 28197)
53 #pragma warning(disable: 4100) // Unreferenced formal parameter - needed for document generation
54 #pragma warning(disable: 4127) // constant express in if condition - we use it for meta programming
57 #pragma push_macro("new")
86 template <
typename _Type>
class task;
90 #ifndef PPL_TASK_SAVE_FRAME_COUNT
92 #define PPL_TASK_SAVE_FRAME_COUNT 10
94 #define PPL_TASK_SAVE_FRAME_COUNT 1
99 #define _EXPAND_STR(x) #x
100 #pragma detect_mismatch("ppltask_saved_frame_numbers", _EXPAND_STR(PPL_TASK_SAVE_FRAME_COUNT))
112 #if PPL_TASK_SAVE_FRAME_COUNT > 1
113 #if defined(__cplusplus_winrt) && !defined(_DEBUG)
114 #pragma message ("WARNING: Redefining PPL_TASK_SAVE_FRAME_COUNT under Release build for non-desktop applications is not supported; only one frame will be captured!")
116 #define _CAPTURE_CALLSTACK() ::Concurrency::details::_TaskCreationCallstack::_CaptureMultiFramesCallstack(_ReturnAddress(), PPL_TASK_SAVE_FRAME_COUNT)
118 #define _CAPTURE_CALLSTACK() ::Concurrency::details::_TaskCreationCallstack::_CaptureSingleFrameCallstack(_ReturnAddress())
145 static void __declspec(noreturn) __cdecl _NoCallOnDefaultTask_ErrorImpl()
166 _M_SingleFrame =
nullptr;
183 if (_CaptureFrames > 1)
202 template<
typename _Ty>
214 template<
typename _Ty>
226 template <
typename _Ty>
232 template <
typename _Ty>
238 template <
typename _Ty>
243 #if defined(__cplusplus_winrt)
244 template <
typename _Type>
250 template <
typename _Type>
251 struct _Unhat<
_Type^>
256 value struct _NonUserType {
public:
int _Dummy; };
258 template <
typename _Type,
bool _IsValueTypeOrRefType = __is_val
id_winrt_type(_Type)>
259 struct _ValueTypeOrRefType
261 typedef _NonUserType
_Value;
264 template <
typename _Type>
270 template <
typename _T1,
typename _T2>
271 _T2 _ProgressTypeSelector(Windows::Foundation::IAsyncOperationWithProgress<_T1,_T2>^);
273 template <
typename _T1>
274 _T1 _ProgressTypeSelector(Windows::Foundation::IAsyncActionWithProgress<_T1>^);
276 template <
typename _Type>
277 struct _GetProgressType
279 typedef decltype(_ProgressTypeSelector(details::declval<_Type>()))
_Value;
282 template <typename
_Type>
288 template <
typename _Ty>
293 template <
typename _T1,
typename _T2>
296 template <
typename _Ty>
300 struct _TaskTypeTraits
304 typedef typename _NormalizeVoidToUnitType<_TaskRetType>::
_Type _NormalizedTaskRetType;
306 static const
bool _IsAsyncTask = _IsAsync;
307 static const
bool _IsUnwrappedTaskOrAsync = _IsUnwrappedAsyncSelector<_AsyncKind>::
_Value;
310 template<typename
_Type>
313 typedef decltype(((_Type)
nullptr)->GetResults()) _TaskRetType;
314 typedef _TaskRetType _NormalizedTaskRetType;
317 static const
bool _IsAsyncTask = true;
318 static const
bool _IsUnwrappedTaskOrAsync = _IsUnwrappedAsyncSelector<_AsyncKind>::_Value;
322 template <
typename _Type>
325 static const bool _Value =
false;
328 template <
typename _Type,
bool _IsAsync = false>
335 static const
bool _IsAsyncTask =
false;
350 static const bool _IsAsyncTask =
false;
351 static const bool _IsUnwrappedTaskOrAsync =
false;
357 template <
typename _Function,
typename _Type>
auto _ReturnTypeHelper(_Type _Obj, _Function _Func,
int, ...) -> decltype(_Func(_Obj));
364 template <
typename _Function>
auto _VoidReturnTypeHelper(_Function _Func,
int, ...) -> decltype(_Func());
369 template<
typename _Function,
typename _ExpectedParameterType>
372 typedef decltype(
_ReturnTypeHelper(details::declval<_ExpectedParameterType>(),details::declval<_Function>(), 0, 0)) _FuncRetType;
378 template<typename _Function>
385 #ifndef _PPLTASKS_NO_STDFUNC
386 template<
typename _Ty,
typename _IsTaskType>
389 static_assert(std::is_same<_IsTaskType, std::false_type>::value,
"_IsTaskType template parameter must be std::true_type or std::false_type");
393 template<
typename _Ty>
400 template<
typename _Function,
typename _ReturnType>
404 #ifndef _PPLTASKS_NO_STDFUNC
407 typedef std::function<_RetTypeT __cdecl(_ArgTypeT)>
_StdFuncT;
425 template <
typename _TaskType,
typename _FuncRetType>
433 template<
typename _Ty>
437 static const bool _IsAsyncTask =
false;
438 static const bool _IsUnwrappedTaskOrAsync =
false;
519 _M_context._M_captureMethod = _S_captureDeferred;
523 _M_context._M_pContextCallback =
nullptr;
530 if(_M_context._M_captureMethod == _S_captureDeferred)
532 _M_context._M_pContextCallback =
nullptr;
534 if (_CaptureCurrent && _IsCurrentOriginSTA())
550 _M_context._M_pContextCallback =
_Src._M_context._M_pContextCallback;
551 _Src._M_context._M_pContextCallback =
nullptr;
569 _Src._M_context._M_pContextCallback =
nullptr;
576 _ASSERTE(_M_context._M_captureMethod != _S_captureDeferred);
577 return (_M_context._M_pContextCallback !=
nullptr);
592 _CRTIMP2 void __thiscall _CallInContext(_CallbackFunction _Func,
bool _IgnoreDisconnect)
const;
596 _CallInContext(_Func,
false);
602 _CRTIMP2 void __thiscall _Assign(
void *_PContextCallback);
605 _CRTIMP2 static bool __cdecl _IsCurrentOriginSTA();
607 _CRTIMP2 void __thiscall _Capture();
615 static const size_t _S_captureDeferred = 1;
619 template<
typename _Type>
624 void Set(
const _Type& _type)
642 void Set(
const std::vector<bool>& _type)
650 std::vector<bool> _Ret(
_Result.size());
658 #if defined (__cplusplus_winrt)
660 template<
typename _Type>
663 void Set(_Type^
const & _type)
670 return _M_Result.
Get();
681 template<
typename _Type>
682 struct _ResultHolder<
std::
vector<_Type^>>
684 void Set(
const std::vector<_Type^>& _type)
688 for (
auto _PTask = _type.begin(); _PTask != _type.end(); ++_PTask)
694 std::vector<_Type^> Get()
697 std::vector<_Type^> _Return;
698 _Return.reserve(
_Result.size());
700 for (
auto _PTask =
_Result.begin(); _PTask !=
_Result.end(); ++_PTask)
702 _Return.push_back(_PTask->Get());
708 std::vector< ::Platform::Agile<_Type^> >
_Result;
711 template<
typename _Type>
712 struct _ResultHolder<
std::
pair<_Type^, void*> >
714 void Set(
const std::pair<_Type^, size_t>& _type)
719 std::pair<_Type^, size_t> Get()
724 std::pair< ::Platform::Agile<_Type^>,
size_t> _M_Result;
739 _M_exceptionObserved(0), _M_stdException(_E), _M_stackTrace(_stackTrace)
746 if (_M_exceptionObserved == 0)
757 if (_M_exceptionObserved == 0)
780 #if defined (__cplusplus_winrt)
781 template<
typename _AsyncOperationType,
typename _CompletionHandlerType,
typename _Result>
785 ref struct _AsyncInfoImpl
abstract : Windows::Foundation::IAsyncOperation<_Result>
791 Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ _M_CompletedHandler;
793 _AsyncInfoImpl( _AsyncOperationType _AsyncInfo ) : _M_asyncInfo(_AsyncInfo) {}
796 virtual void Cancel() { _M_asyncInfo.
Get()->Cancel(); }
797 virtual void Close() { _M_asyncInfo.
Get()->Close(); }
799 virtual property Windows::Foundation::HResult ErrorCode
801 Windows::Foundation::HResult
get()
803 return _M_asyncInfo.
Get()->ErrorCode;
807 virtual property UINT Id
811 return _M_asyncInfo.
Get()->Id;
815 virtual property Windows::Foundation::AsyncStatus Status
817 Windows::Foundation::AsyncStatus
get()
819 return _M_asyncInfo.
Get()->Status;
823 virtual _Result GetResults() {
throw std::runtime_error(
"derived class must implement"); }
825 virtual property Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ Completed
827 Windows::Foundation::AsyncOperationCompletedHandler<_Result>^
get()
829 return _M_CompletedHandler;
832 void set(Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ _Value)
834 _M_CompletedHandler =
_Value;
835 _M_asyncInfo.
Get()->Completed =
ref new _CompletionHandlerType([&](_AsyncOperationType, Windows::Foundation::AsyncStatus _Status) {
836 _M_CompletedHandler->Invoke(
this, _Status);
845 template<
typename _Result,
typename _Progress>
846 ref struct _IAsyncOperationWithProgressToAsyncOperationConverter
sealed :
847 _AsyncInfoImpl<Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^,
848 Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_Result,_Progress>,
852 _IAsyncOperationWithProgressToAsyncOperationConverter(Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^ _Operation) :
853 _AsyncInfoImpl<
Windows::Foundation::IAsyncOperationWithProgress<
_Result,_Progress>^,
854 Windows::Foundation::AsyncOperationWithProgressCompletedHandler<
_Result,_Progress>,
858 virtual _Result GetResults()
override {
return _M_asyncInfo.
Get()->GetResults(); }
864 ref struct _IAsyncActionToAsyncOperationConverter
sealed :
865 _AsyncInfoImpl<Windows::Foundation::IAsyncAction^,
866 Windows::Foundation::AsyncActionCompletedHandler,
870 _IAsyncActionToAsyncOperationConverter(Windows::Foundation::IAsyncAction^ _Operation) :
871 _AsyncInfoImpl<
Windows::Foundation::IAsyncAction^,
872 Windows::Foundation::AsyncActionCompletedHandler,
873 details::_Unit_type>(_Operation) {}
879 _M_asyncInfo.
Get()->GetResults();
887 template<
typename _Progress>
888 ref struct _IAsyncActionWithProgressToAsyncOperationConverter
sealed :
889 _AsyncInfoImpl<Windows::Foundation::IAsyncActionWithProgress<_Progress>^,
890 Windows::Foundation::AsyncActionWithProgressCompletedHandler<_Progress>,
894 _IAsyncActionWithProgressToAsyncOperationConverter(Windows::Foundation::IAsyncActionWithProgress<_Progress>^ _Action) :
895 _AsyncInfoImpl<
Windows::Foundation::IAsyncActionWithProgress<_Progress>^,
896 Windows::Foundation::AsyncActionWithProgressCompletedHandler<_Progress>,
897 details::_Unit_type>(_Action) {}
902 _M_asyncInfo.
Get()->GetResults();
963 #if defined (__cplusplus_winrt)
999 static task_continuation_context use_current()
1001 return get_current_winrt_context();
1027 return _M_RunInline;
1045 _M_hasPresetCreationCallstack =
true;
1046 _M_presetCreationCallstack = _callstack;
1050 _M_hasPresetCreationCallstack =
false;
1072 _M_HasCancellationToken(false),
1073 _M_HasScheduler(false)
1082 _M_CancellationToken(_Token),
1084 _M_HasCancellationToken(true),
1085 _M_HasScheduler(false)
1095 _M_ContinuationContext(_ContinuationContext),
1096 _M_HasCancellationToken(false),
1097 _M_HasScheduler(false)
1106 _M_CancellationToken(_Token),
1107 _M_ContinuationContext(_ContinuationContext),
1108 _M_HasCancellationToken(true),
1109 _M_HasScheduler(false)
1116 template<
typename _SchedType>
1118 : _M_Scheduler(
std::
move(_Scheduler)),
1121 _M_HasCancellationToken(false),
1122 _M_HasScheduler(true)
1130 : _M_Scheduler(&_Scheduler),
1133 _M_HasCancellationToken(false),
1134 _M_HasScheduler(true)
1142 : _M_Scheduler(
std::
move(_Scheduler)),
1145 _M_HasCancellationToken(false),
1146 _M_HasScheduler(true)
1154 : _M_Scheduler(_TaskOptions.get_scheduler()),
1155 _M_CancellationToken(_TaskOptions.get_cancellation_token()),
1156 _M_ContinuationContext(_TaskOptions.get_continuation_context()),
1157 _M_HasCancellationToken(_TaskOptions.has_cancellation_token()),
1158 _M_HasScheduler(_TaskOptions.has_scheduler())
1167 _M_CancellationToken = _Token;
1168 _M_HasCancellationToken =
true;
1176 _M_ContinuationContext = _ContinuationContext;
1184 return _M_HasCancellationToken;
1192 return _M_CancellationToken;
1200 return _M_ContinuationContext;
1208 return _M_HasScheduler;
1216 return _M_Scheduler;
1243 _CreationStack(_Creation_stack), _InliningMode(_Inlining_mode) {}
1260 auto _CreationStack = _Task_Options_Int._M_hasPresetCreationCallstack ?
1263 return _ThenImplOptions(_TokenState, &_ContinuationContext, _Scheduler, _CreationStack,_InliningMode);
1276 struct _Task_impl_base;
1279 template<
typename _ReturnType>
1282 typedef std::shared_ptr<_Task_impl<_ReturnType>>
_Type;
1299 virtual _Task_ptr_base _GetTaskImplBase()
const = 0;
1309 #if _PPLTASK_ASYNC_LOGGING
1319 _CRTIMP2 void __thiscall _LogScheduleTask(
bool _isContinuation);
1322 _CRTIMP2 void __thiscall _LogCancelTask();
1325 _CRTIMP2 void __thiscall _LogTaskCompleted();
1331 _CRTIMP2 void __thiscall _LogTaskExecutionCompleted();
1334 _CRTIMP2 void __thiscall _LogWorkItemStarted();
1337 _CRTIMP2 void __thiscall _LogWorkItemCompleted();
1341 _M_scheduled =
false;
1342 _M_taskPostEventStarted =
false;
1363 inline void _LogCancelTask(_Task_impl_base *) {}
1364 struct _TaskEventLogger
1366 void _LogScheduleTask(
bool) {}
1367 void _LogCancelTask() {}
1368 void _LogWorkItemStarted() {}
1369 void _LogWorkItemCompleted() {}
1370 void _LogTaskExecutionStarted() {}
1371 void _LogTaskExecutionCompleted() {}
1372 void _LogTaskCompleted() {}
1373 _TaskEventLogger(_Task_impl_base *) {}
1375 struct _TaskWorkItemRAIILogger
1377 _TaskWorkItemRAIILogger(_TaskEventLogger &) {}
1396 template<
typename _ReturnType,
typename _DerivedTaskHandle,
typename _BaseTaskHandle>
1406 _M_pTask->_M_taskEventLogger._LogTaskCompleted();
1414 if (!_M_pTask->_TransitionedToStarted())
1416 static_cast<const _DerivedTaskHandle *
>(
this)->_SyncCancelAndPropagateException();
1420 _M_pTask->_M_taskEventLogger._LogTaskExecutionStarted();
1424 static_cast<const _DerivedTaskHandle *
>(
this)->_Perform();
1426 _M_pTask->_Cancel(
true);
1428 _M_pTask->_Cancel(
true);
1432 _M_pTask->_M_taskEventLogger._LogTaskExecutionCompleted();
1465 : _M_TaskState(_Created),
1466 _M_fFromAsync(false), _M_fUnwrappedTask(false),
1467 _M_pRegistration(nullptr), _M_Continuations(nullptr), _M_TaskCollection(_Scheduler_arg),
1468 _M_taskEventLogger(
this)
1471 _M_pTokenState = _PTokenState;
1472 _ASSERTE(_M_pTokenState !=
nullptr);
1474 _M_pTokenState->_Reference();
1479 _ASSERTE(_M_pTokenState !=
nullptr);
1482 _M_pTokenState->_Release();
1488 bool _DoWait =
true;
1490 if (_IsNonBlockingThread())
1494 if (!_IsCompleted() && !_IsCanceled())
1517 _M_TaskCollection._Wait();
1533 _M_TaskCollection._RunAndWait();
1545 if(!_HasUserException())
1550 _M_exceptionHolder->_RethrowUserException();
1557 if (_M_fUnwrappedTask)
1559 _M_TaskCollection._Wait();
1564 if (_HasUserException())
1566 _M_exceptionHolder->_RethrowUserException();
1568 else if (_IsCanceled())
1595 virtual bool _CancelAndRunContinuations(
bool _SynchronousCancel,
bool _UserException,
bool _PropagatedFromAncestor,
const std::shared_ptr<_ExceptionHolder>& _ExHolder) = 0;
1600 return _CancelAndRunContinuations(_SynchronousCancel,
false,
false, _M_exceptionHolder);
1606 return _CancelAndRunContinuations(
true,
true, _PropagatedFromAncestor, _ExHolder);
1613 return _CancelAndRunContinuations(
true,
true,
false, std::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack()));
1620 auto _CancellationCallback = [_WeakPtr](){
1623 auto _task = _WeakPtr.lock();
1624 if (_task !=
nullptr)
1625 _task->_Cancel(
false);
1629 _M_pTokenState->_RegisterCallback(_M_pRegistration);
1634 if (_M_pRegistration !=
nullptr)
1636 _M_pTokenState->_DeregisterCallback(_M_pRegistration);
1637 _M_pRegistration->_Release();
1638 _M_pRegistration =
nullptr;
1644 return (_M_TaskState == _Created);
1649 return (_M_TaskState == _Started);
1654 return (_M_TaskState == _PendingCancel);
1669 return static_cast<bool>(_M_exceptionHolder);
1675 return _M_exceptionHolder;
1680 return _M_fFromAsync;
1685 _M_fFromAsync = _Async;
1690 return _M_pTaskCreationCallstack;
1695 _M_pTaskCreationCallstack = _Callstack;
1710 _M_TaskCollection._ScheduleTask(_PTaskHandle, _InliningMode);
1728 if (!_HasUserException())
1748 if (_HasUserException())
1752 _ImplBase->_CancelWithExceptionHolder(_GetExceptionHolder(),
true);
1758 _ImplBase->_Cancel(
true);
1766 _ASSERTE(!_ImplBase->_IsCanceled());
1767 return _ImplBase->_ScheduleContinuationTask(_PTaskHandle);
1771 delete _PTaskHandle;
1778 _M_taskEventLogger._LogScheduleTask(
true);
1837 enum { _Nothing, _Schedule, _Cancel, _CancelWithException } _Do = _Nothing;
1842 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
1847 else if (_IsCanceled())
1849 if (_HasUserException())
1851 _Do = _CancelWithException;
1861 _PTaskHandle->
_M_next = _M_Continuations;
1862 _M_Continuations = _PTaskHandle;
1881 delete _PTaskHandle;
1884 case _CancelWithException:
1888 _PTaskHandle->
_GetTaskImplBase()->_CancelWithExceptionHolder(_GetExceptionHolder(),
true);
1890 delete _PTaskHandle;
1906 _M_Continuations =
nullptr;
1912 _RunContinuation(_Cur);
1917 _CRTIMP2 static bool __cdecl _IsNonBlockingThread();
1919 #if defined (__cplusplus_winrt)
1920 template<
typename _ReturnType,
typename>
1936 _AsyncOp->Completed =
ref new Windows::Foundation::AsyncOperationCompletedHandler<_ReturnType>(
1939 if (_Status == Windows::Foundation::AsyncStatus::Canceled)
1941 _OuterTask->_Cancel(
true);
1943 else if (_Status == Windows::Foundation::AsyncStatus::Error)
1945 _OuterTask->_CancelWithException(
1946 std::make_exception_ptr(::Platform::Exception::ReCreateException(static_cast<int>(_Operation->ErrorCode.Value))));
1950 _ASSERTE(_Status == Windows::Foundation::AsyncStatus::Completed);
1954 _OuterTask->_FinalizeAndRunContinuations(_Operation->GetResults());
1971 _OuterTask->_SetUnwrappedAsyncOp(_AsyncOp);
1975 template<
typename _ReturnType,
typename _InternalReturnType>
1978 _ASSERTE(_OuterTask->_M_fUnwrappedTask && !_OuterTask->_IsCanceled());
1989 if (_AncestorTask.
_GetImpl()->_IsCompleted())
1991 _OuterTask->_FinalizeAndRunContinuations(_AncestorTask.
_GetImpl()->_GetResult());
1996 if (_AncestorTask.
_GetImpl()->_HasUserException())
2000 _OuterTask->_CancelWithExceptionHolder(_AncestorTask.
_GetImpl()->_GetExceptionHolder(),
false);
2004 _OuterTask->_Cancel(
true);
2013 return _M_TaskCollection._GetScheduler();
2062 template<
typename _ReturnType>
2074 _DeregisterCancellation();
2077 virtual bool _CancelAndRunContinuations(
bool _SynchronousCancel,
bool _UserException,
bool _PropagatedFromAncestor,
const std::shared_ptr<_ExceptionHolder> & _ExceptionHolder_arg)
2079 enum { _Nothing, _RunContinuations, _Cancel } _Do = _Nothing;
2081 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2084 _ASSERTE(_SynchronousCancel && !_IsCompleted());
2086 _ASSERTE(!_IsCanceled() || _PropagatedFromAncestor);
2099 _M_exceptionHolder = _ExceptionHolder_arg;
2106 if (_IsCompleted() || _IsCanceled() || (_IsPendingCancel() && !_SynchronousCancel))
2108 _ASSERTE(!_IsCompleted() || !_HasUserException());
2111 _ASSERTE(!_SynchronousCancel || !_HasUserException());
2114 if (_SynchronousCancel)
2121 _Do = _RunContinuations;
2136 _M_TaskState = _PendingCancel;
2138 _M_taskEventLogger._LogCancelTask();
2146 if (_M_InternalCancellation)
2149 _M_InternalCancellation();
2151 _M_TaskCollection._Cancel();
2154 case _RunContinuations:
2157 _M_TaskCollection._Complete();
2159 if (_M_Continuations)
2176 _M_Result.Set(_Result);
2183 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2187 _ASSERTE(!_HasUserException() && !_IsCompleted());
2196 _M_TaskCollection._Complete();
2197 _RunTaskContinuations();
2205 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2208 if (_IsPendingCancel())
2212 _M_TaskState = _Started;
2216 #if defined (__cplusplus_winrt)
2219 bool _DoCancel =
false;
2221 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2223 if (_IsPendingCancel())
2228 else if (!_IsCanceled() && !_IsCompleted())
2230 _M_TaskState = _Started;
2231 _M_InternalCancellation = [=] {
2246 return _IsCompleted() || _IsCanceled();
2251 return _M_Result.Get();
2258 template<
typename _ResultType>
2270 _M_fHasValue(false), _M_fIsCanceled(false)
2276 return _M_exceptionHolder !=
nullptr;
2281 for(
auto _TaskIt = _M_tasks.begin(); _TaskIt != _M_tasks.end(); ++_TaskIt )
2283 _ASSERTE(!_M_fHasValue && !_M_fIsCanceled);
2285 (*_TaskIt)->_Cancel(
true);
2301 return [=]() -> _Unit_type { _Func();
return _Unit_type(); };
2304 template <
typename _Type>
2307 return [=](
_Unit_type) -> _Type {
return _Func(); };
2310 template <
typename _Type>
2313 return [=](_Type _Obj) -> _Unit_type { _Func(_Obj);
return _Unit_type(); };
2339 template<
typename _ResultType>
2348 : _M_Impl(
std::
make_shared<details::_Task_completion_event_impl<_ResultType>>())
2377 bool _RunContinuations =
false;
2379 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2381 if (!_IsTriggered())
2383 _M_Impl->_M_value.Set(
_Result);
2384 _M_Impl->_M_fHasValue =
true;
2386 _Tasks.swap(_M_Impl->_M_tasks);
2387 _RunContinuations =
true;
2391 if (_RunContinuations)
2393 for(
auto _TaskIt = _Tasks.begin(); _TaskIt != _Tasks.end(); ++_TaskIt )
2396 if ((*_TaskIt)->_IsPendingCancel())
2397 (*_TaskIt)->_Cancel(
true);
2403 (*_TaskIt)->_FinalizeAndRunContinuations(_M_Impl->_M_value.Get());
2413 template<
typename _E>
2415 bool set_exception(_E _Except) const
2442 return _CancelInternal();
2449 template<
typename _ExHolderType>
2453 if(_StoreException(_ExHolder, _SetExceptionAddressHint))
2455 _Canceled = _CancelInternal();
2470 template<
typename _ExHolderType>
2473 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2474 if (!_IsTriggered() && !_M_Impl->_HasUserException())
2478 _M_Impl->_M_exceptionHolder = _ToExceptionHolder(_ExHolder, _SetExceptionAddressHint);
2489 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2490 if (_M_Impl->_M_exceptionHolder)
2493 _M_Impl->_M_exceptionHolder.reset();
2502 return _M_Impl->_M_fHasValue || _M_Impl->_M_fIsCanceled;
2514 return std::make_shared<details::_ExceptionHolder>(_ExceptionPtr, _SetExceptionAddressHint);
2518 template <
typename _Ty>
friend class task;
2531 if (_M_Impl->_M_fIsCanceled)
2537 bool _Cancel =
false;
2539 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2541 if (!_M_Impl->_M_fIsCanceled)
2543 _M_Impl->_M_fIsCanceled =
true;
2544 _Tasks.swap(_M_Impl->_M_tasks);
2549 bool _UserException = _M_Impl->_HasUserException();
2553 for(
auto _TaskIt = _Tasks.begin(); _TaskIt != _Tasks.end(); ++_TaskIt )
2558 (*_TaskIt)->_CancelWithExceptionHolder(_M_Impl->_M_exceptionHolder,
true);
2562 (*_TaskIt)->_Cancel(
true);
2575 enum { _Nothing, _Trigger, _Cancel } _Action = _Nothing;
2577 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2580 if (_M_Impl->_HasUserException())
2584 else if (_M_Impl->_M_fHasValue)
2590 _M_Impl->_M_tasks.push_back(_TaskParam);
2597 _TaskParam->_FinalizeAndRunContinuations(_M_Impl->_M_value.Get());
2600 _TaskParam->_CancelWithExceptionHolder(_M_Impl->_M_exceptionHolder,
true);
2608 std::shared_ptr<details::_Task_completion_event_impl<_ResultType>>
_M_Impl;
2647 template<
typename _E>
2649 bool set_exception(_E _Except) const
2674 _M_unitEvent._Cancel();
2681 void _Cancel(
const std::shared_ptr<details::_ExceptionHolder>& _ExHolder)
const
2683 _M_unitEvent._Cancel(_ExHolder);
2693 return _M_unitEvent._StoreException(_ExHolder);
2702 _M_unitEvent._ClearStoredException();
2710 return _M_unitEvent._IsTriggered();
2714 template <
typename _Ty>
friend class task;
2722 _M_unitEvent._RegisterTask(_TaskParam);
2738 template<
typename _ReturnType,
typename _Ty>
2741 #if defined (__cplusplus_winrt)
2743 template<
typename _ReturnType,
typename _Ty>
2748 template<
typename _ReturnType,
typename _Ty>
2751 template<
typename _ReturnType,
typename _Ty>
2755 template<
typename _ReturnType,
typename _Ty>
2758 template<
typename _ReturnType,
typename _Ty>
2761 static_assert(std::is_same<decltype(_IsValidTaskCtor<_ReturnType, _Ty>(_Param,0,0,0,0)),
std::true_type>::value,
2762 #
if defined (__cplusplus_winrt)
2763 "incorrect argument for task constructor; must be a callable object, an asynchronous operation or a task_completion_event"
2765 "incorrect argument for task constructor; must be either a callable object or a task_completion_event"
2768 #if defined (__cplusplus_winrt)
2770 "incorrect template argument for task; consider using the return type of the async operation");
2776 #if defined (__cplusplus_winrt)
2780 template<
typename _Ty>
2781 static auto _IsValidCreateAsync(_Ty _Param,
int,
int,
int,
int) -> decltype(_Param(),
std::true_type());
2784 template<
typename _Ty>
2788 template<
typename _Ty>
2792 template<
typename _Ty>
2796 template<
typename _Ty>
2804 template<
typename _InpType,
typename _OutType>
2808 static auto _Perform(std::function<_OutType(_InpType)> _Func) -> decltype(_Func)
2814 template<
typename _OutType>
2818 static auto _Perform(std::function<_OutType(
void)> _Func) -> decltype(details::_MakeUnitToTFunc<_OutType>(_Func))
2820 return details::_MakeUnitToTFunc<_OutType>(_Func);
2824 template<
typename _InType>
2828 static auto _Perform(std::function<
void(_InType)> _Func) -> decltype(details::_MakeTToUnitFunc<_InType>(_Func))
2830 return details::_MakeTToUnitFunc<_InType>(_Func);
2846 template<
typename _RetType>
2850 static auto _Perform(std::function<_RetType(
void)> _Func) -> decltype(_Func)
2880 template<
typename _ReturnType>
2953 template<
typename _Ty>
2955 explicit
task(_Ty _Param)
2958 details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
3001 template<
typename _Ty>
3005 details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
3007 _CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
3081 if (
this != &_Other)
3083 _M_Impl = _Other._M_Impl;
3101 if (
this != &_Other)
3128 template<
typename _Function>
3130 auto then(const _Function& _Func) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
3140 #ifndef _PPLTASKS_NO_STDFUNC
3143 return _ThenImpl<_ReturnType>(_Func, _Options);
3171 template<
typename _Function>
3173 auto then(const _Function& _Func,
task_options _TaskOptions) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
3179 auto _ContinuationContext = _TaskOptions.get_continuation_context();
3182 #ifndef _PPLTASKS_NO_STDFUNC
3185 return _ThenImpl<_ReturnType>(_Func, _Options);
3217 template<
typename _Function>
3222 task_options _TaskOptions(_CancellationToken, _ContinuationContext);
3227 #ifndef _PPLTASKS_NO_STDFUNC
3230 return _ThenImpl<_ReturnType>(_Func, _Options);
3247 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3250 return _M_Impl->_Wait();
3265 _ReturnType
get()
const
3269 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3277 return _M_Impl->_GetResult();
3293 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3296 return _M_Impl->_IsDone();
3309 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3312 return _M_Impl->_GetScheduler();
3326 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3328 return _M_Impl->_IsApartmentAware();
3340 return (_M_Impl == _Rhs._M_Impl);
3364 _M_Impl->_RegisterCancellation(_M_Impl);
3380 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3409 _GetImpl()->_SetAsync(_Async);
3417 _GetImpl()->_SetTaskCreationCallstack(_callstack);
3425 template<
typename _Function>
3430 auto _Scheduler = _GetImpl()->_GetScheduler();
3437 #ifndef _PPLTASKS_NO_STDFUNC
3440 return _ThenImpl<_ReturnType>(_Func, _Options);
3445 template <
typename _Ty>
friend class task;
3449 template <
typename _InternalReturnType,
typename _Function,
typename _TypeSelection>
3451 details::_PPLTaskHandle<_ReturnType, _InitialTaskHandle<_InternalReturnType, _Function, _TypeSelection>, details::_UnrealizedChore_t>
3455 : details::_PPLTaskHandle<_ReturnType,
_InitialTaskHandle<_InternalReturnType, _Function, _TypeSelection>, details::_UnrealizedChore_t>::_PPLTaskHandle(_TaskImpl)
3456 , _M_function(_func)
3462 template <
typename _Func>
3471 _Init(_TypeSelection());
3476 this->_M_pTask->_Cancel(
true);
3499 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask, _LogWorkItemAndInvokeUserLambda(_M_function));
3502 #if defined (__cplusplus_winrt)
3510 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
ref new details::_IAsyncActionToAsyncOperationConverter(_LogWorkItemAndInvokeUserLambda(_M_function)));
3522 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
3523 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_InternalReturnType,_ProgressType>(_LogWorkItemAndInvokeUserLambda(_M_function)));
3531 void _Init(details::_TypeSelectorAsyncActionWithProgress)
const
3535 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
3536 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(_LogWorkItemAndInvokeUserLambda(_M_function)));
3545 template <
typename _InternalReturnType,
typename _ContinuationReturnType,
typename _Function,
typename _IsTaskBased,
typename _TypeSelection>
3548 _ContinuationTaskHandle<_InternalReturnType, _ContinuationReturnType, _Function, _IsTaskBased, _TypeSelection>, details::_ContinuationTaskHandleBase>
3558 : details::_PPLTaskHandle<typename details::_NormalizeVoidToUnitType<_ContinuationReturnType>::_Type,
3559 _ContinuationTaskHandle<_InternalReturnType, _ContinuationReturnType, _Function, _IsTaskBased, _TypeSelection>, details::_ContinuationTaskHandleBase>
3560 ::_PPLTaskHandle(_ContinuationImpl)
3561 , _M_ancestorTaskImpl(_AncestorImpl)
3562 , _M_function(_Func)
3564 this->_M_isTaskBasedContinuation = _IsTaskBased::value;
3565 this->_M_continuationContext =
_Context;
3566 this->_M_continuationContext._Resolve(_AncestorImpl->_IsApartmentAware());
3567 this->_M_inliningMode = _InliningMode;
3572 template <
typename _Func,
typename _Arg>
3576 return _func(std::forward<_Arg>(_value));
3581 _Continue(_IsTaskBased(), _TypeSelection());
3586 if (_M_ancestorTaskImpl->_HasUserException())
3590 this->_M_pTask->_CancelWithExceptionHolder(_M_ancestorTaskImpl->_GetExceptionHolder(),
true);
3596 this->_M_pTask->_Cancel(
true);
3607 this->_M_pTask->_FinalizeAndRunContinuations(
3623 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3629 #if defined (__cplusplus_winrt)
3639 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3641 ref new details::_IAsyncActionToAsyncOperationConverter(
3657 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3659 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_ContinuationReturnType, _ProgressType>(_OpWithProgress));
3667 void _Continue(
std::false_type, details::_TypeSelectorAsyncActionWithProgress)
const
3669 typedef details::_FunctionTypeTraits<_Function, _InternalReturnType>::_FuncRetType _FuncOutputType;
3671 auto _OpWithProgress = _LogWorkItemAndInvokeUserLambda(_Continuation_func_transformer<_InternalReturnType, _FuncOutputType>::_Perform(_M_function), _M_ancestorTaskImpl->_GetResult());
3674 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3676 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(_OpWithProgress));
3690 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3691 this->_M_pTask->_FinalizeAndRunContinuations(
3708 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3709 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3710 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask)));
3713 #if defined (__cplusplus_winrt)
3725 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3726 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3727 ref new details::_IAsyncActionToAsyncOperationConverter(_LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3741 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3745 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3746 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_ContinuationReturnType, _ProgressType>(
3747 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3757 void _Continue(
std::true_type, details::_TypeSelectorAsyncActionWithProgress)
const
3760 task<_InternalReturnType> _ResultTask;
3761 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3765 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3766 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(
3767 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3775 template<
typename _InternalReturnType,
typename _Function>
3780 _M_Impl->_M_fFromAsync = _Async_type_traits::_IsAsyncTask;
3781 _M_Impl->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3782 _M_Impl->_M_taskEventLogger._LogScheduleTask(
false);
3783 _M_Impl->_ScheduleTask(
new _InitialTaskHandle<_InternalReturnType, _Function, typename _Async_type_traits::_AsyncKind>(_GetImpl(), _Func),
details::_NoInline);
3794 #if defined (__cplusplus_winrt)
3800 _M_Impl->_M_fFromAsync =
true;
3803 details::_Task_impl_base::_AsyncInit<_ReturnType, _ReturnType>(_M_Impl, _AsyncOp);
3811 _TaskInitAsyncOp(_AsyncOp);
3817 template<
typename _Progress>
3827 template<
typename _Function>
3830 _TaskInitWithFunctor<_ReturnType, _Function>(_Func);
3836 template<
typename _Ty>
3839 _TaskInitNoFunctor(_Param);
3845 template<
typename _InternalReturnType,
typename _Function>
3851 typedef typename _Async_type_traits::_TaskRetType _TaskType;
3858 if (_Options._PTokenState ==
nullptr)
3860 if (_Function_type_traits::_Takes_task::value)
3866 _Options._PTokenState = _GetImpl()->_M_pTokenState;
3871 _ContinuationTask._CreateImpl(_Options._PTokenState, _Options._Scheduler);
3873 _ContinuationTask._GetImpl()->_M_fFromAsync = (_GetImpl()->_M_fFromAsync || _Async_type_traits::_IsAsyncTask);
3874 _ContinuationTask._GetImpl()->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3875 _ContinuationTask._SetTaskCreationCallstack(_Options._CreationStack);
3877 _GetImpl()->_ScheduleContinuation(
new _ContinuationTaskHandle<_InternalReturnType, _TaskType, _Function, typename _Function_type_traits::_Takes_task, typename _Async_type_traits::_AsyncKind>(
3878 _GetImpl(), _ContinuationTask._GetImpl(), _Func, *_Options._PContinuationContext, _Options._InliningMode));
3880 return _ContinuationTask;
3967 template<
typename _Ty>
3971 details::_ValidateTaskConstructorArgs<void,_Ty>(_Param);
3973 _M_unitTask.
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
4005 task(
const task& _Other): _M_unitTask(_Other._M_unitTask){}
4032 task(task&& _Other) : _M_unitTask(
std::
move(_Other._M_unitTask)) {}
4047 if (
this != &_Other)
4049 _M_unitTask = _Other._M_unitTask;
4067 if (
this != &_Other)
4069 _M_unitTask =
std::move(_Other._M_unitTask);
4098 template<
typename _Function>
4100 auto then(const _Function& _Func, task_options _TaskOptions = task_options()) const -> typename details::_ContinuationTypeTraits<_Function,
void>::_TaskOfType
4106 auto _ContinuationContext = _TaskOptions.get_continuation_context();
4109 #ifndef _PPLTASKS_NO_STDFUNC
4112 return _M_unitTask._ThenImpl<
void>(_Func, _Options);
4144 template<
typename _Function>
4149 task_options _TaskOptions(_CancellationToken, _ContinuationContext);
4154 #ifndef _PPLTASKS_NO_STDFUNC
4157 return _M_unitTask._ThenImpl<
void>(_Func, _Options);
4172 return _M_unitTask.wait();
4200 return _M_unitTask.is_done();
4211 return _M_unitTask.scheduler();
4223 return _M_unitTask.is_apartment_aware();
4255 _M_unitTask._CreateImpl(_Ct, _Scheduler);
4263 return _M_unitTask._M_Impl;
4268 if (!_M_unitTask._M_Impl)
4270 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
4273 return _M_unitTask._M_Impl;
4281 _M_unitTask._SetImpl(_Impl);
4297 _M_unitTask._SetAsync(_Async);
4305 _M_unitTask._SetTaskCreationCallstack(_callstack);
4311 template<
typename _Function>
4317 auto _Scheduler = _ThenGetImpl()->_GetScheduler();
4324 #ifndef _PPLTASKS_NO_STDFUNC
4327 return _M_unitTask._ThenImpl<
void>(_Func, _Options);
4332 template <
typename _Ty>
friend class task;
4343 #if defined (__cplusplus_winrt)
4344 void _TaskInitNoFunctor(Windows::Foundation::IAsyncAction^ _AsyncAction)
4349 _M_unitTask._TaskInitAsyncOp(
ref new details::_IAsyncActionToAsyncOperationConverter(_AsyncAction));
4355 template<
typename _P>
4356 void _TaskInitNoFunctor(Windows::Foundation::IAsyncActionWithProgress<_P>^ _AsyncActionWithProgress)
4358 _M_unitTask._TaskInitAsyncOp(
ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_P>(_AsyncActionWithProgress));
4365 template<
typename _Function>
4368 _M_unitTask._TaskInitWithFunctor<
void, _Function>(_Func);
4374 template<
typename _Ty>
4377 _TaskInitNoFunctor(_Param);
4390 #if defined (__cplusplus_winrt)
4392 template<
typename _Ty>
4397 template<
typename _Ty,
typename _Progress>
4398 _Ty
_GetUnwrappedType(Windows::Foundation::IAsyncOperationWithProgress<_Ty, _Progress>^);
4400 template<
typename _Progress>
4401 void _GetUnwrappedType(Windows::Foundation::IAsyncActionWithProgress<_Progress>^);
4405 template<
typename _Ty>
4409 template<
typename _Ty>
4412 template<
typename _Ty>
4422 template<
typename _Ty>
4426 template<
typename _Ty>
4430 template<
typename _Ty>
4437 template<
typename _Ty>
4440 template<
typename _Ty>
4443 template<
typename _Ty>
4451 return __hr == 0x800706BA
4452 || __hr == 0x80010108
4453 || __hr == 0x89020001;
4485 template<
typename _Ty>
4487 auto create_task(_Ty _Param, task_options _TaskOptions = task_options()) -> task<typename details::_TaskTypeFromParam<_Ty>::_Type>
4490 #
if defined (__cplusplus_winrt)
4491 "incorrect argument for create_task; can be a callable object, an asynchronous operation, or a task_completion_event"
4493 "incorrect argument for create_task; must be either a callable object or a task_completion_event"
4498 return _CreatedTask;
4532 template<
typename _ReturnType>
4534 task<_ReturnType> create_task(const task<_ReturnType>& _Task)
4536 task<_ReturnType> _CreatedTask(_Task);
4537 return _CreatedTask;
4540 #if defined (__cplusplus_winrt)
4543 template<
typename _Ty>
4544 task<_Ty> _To_task_helper(Windows::Foundation::IAsyncOperation<_Ty>^ _Op)
4546 return task<_Ty>(_Op);
4549 template<
typename _Ty,
typename _Progress>
4550 task<_Ty> _To_task_helper(Windows::Foundation::IAsyncOperationWithProgress<_Ty, _Progress>^ _Op)
4552 return task<_Ty>(_Op);
4555 inline task<void> _To_task_helper(Windows::Foundation::IAsyncAction^ _Op)
4557 return task<void>(_Op);
4560 template<
typename _Progress>
4561 task<void> _To_task_helper(Windows::Foundation::IAsyncActionWithProgress<_Progress>^ _Op)
4563 return task<void>(_Op);
4566 template<
typename _ProgressType>
4567 class _ProgressDispatcherBase
4571 virtual ~_ProgressDispatcherBase()
4575 virtual void _Report(
const _ProgressType&
_Val) = 0;
4578 template<
typename _ProgressType,
typename _ClassPtrType>
4579 class _ProgressDispatcher :
public _ProgressDispatcherBase<_ProgressType>
4583 virtual ~_ProgressDispatcher()
4587 _ProgressDispatcher(_ClassPtrType _Ptr) : _M_ptr(_Ptr)
4591 virtual void _Report(
const _ProgressType&
_Val)
4593 _M_ptr->_FireProgress(_Val);
4598 _ClassPtrType _M_ptr;
4614 template<
typename _ProgressType>
4615 class progress_reporter
4617 typedef std::shared_ptr<details::_ProgressDispatcherBase<_ProgressType>> _PtrType;
4628 void report(
const _ProgressType&
_Val)
const
4630 _M_dispatcher->_Report(_Val);
4633 template<
typename _ClassPtrType>
4634 static progress_reporter _CreateReporter(_ClassPtrType _Ptr)
4636 progress_reporter _Reporter;
4637 details::_ProgressDispatcherBase<_ProgressType> *_PDispatcher =
new details::_ProgressDispatcher<_ProgressType, _ClassPtrType>(_Ptr);
4638 _Reporter._M_dispatcher = _PtrType(_PDispatcher);
4641 progress_reporter() {}
4644 progress_reporter(details::_ProgressReporterCtorArgType);
4647 _PtrType _M_dispatcher;
4655 enum _AsyncStatusInternal
4660 _AsyncCompleted = 1,
4664 _AsyncCancelPending,
4673 enum _AsyncResultType
4675 SingleResult = 0x0001,
4676 MultipleResults = 0x0002
4683 struct _ZeroArgumentFunctor { };
4684 struct _OneArgumentFunctor { };
4685 struct _TwoArgumentFunctor { };
4694 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4695 _Arg1 _Arg1ClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4698 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4699 _Arg2 _Arg2ClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4701 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4702 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4704 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4705 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4711 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4712 _Arg1 _Arg1ClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4715 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4716 void _Arg2ClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4718 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4719 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4721 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4722 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)(_Arg1)
const);
4728 template<
typename _Class,
typename _ReturnType>
4729 void _Arg1ClassHelperThunk(_ReturnType (_Class::*)()
const);
4732 template<
typename _Class,
typename _ReturnType>
4733 void _Arg2ClassHelperThunk(_ReturnType (_Class::*)()
const);
4736 template<
typename _Class,
typename _ReturnType>
4737 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)()
const);
4739 template<
typename _Class,
typename _ReturnType>
4740 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)()
const);
4748 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4749 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4751 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4752 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4754 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4755 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4757 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4758 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4760 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4761 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4763 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4764 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4766 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4767 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4769 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4770 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4772 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4773 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4775 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4776 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4778 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4779 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4781 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4782 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4787 template<
typename _ReturnType,
typename _Arg1>
4788 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4790 template<
typename _ReturnType,
typename _Arg1>
4791 void _Arg2PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4793 template<
typename _ReturnType,
typename _Arg1>
4794 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4796 template<
typename _ReturnType,
typename _Arg1>
4797 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)(_Arg1));
4799 template<
typename _ReturnType,
typename _Arg1>
4800 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4802 template<
typename _ReturnType,
typename _Arg1>
4803 void _Arg2PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4805 template<
typename _ReturnType,
typename _Arg1>
4806 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4808 template<
typename _ReturnType,
typename _Arg1>
4809 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)(_Arg1));
4811 template<
typename _ReturnType,
typename _Arg1>
4812 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4814 template<
typename _ReturnType,
typename _Arg1>
4815 void _Arg2PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4817 template<
typename _ReturnType,
typename _Arg1>
4818 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4820 template<
typename _ReturnType,
typename _Arg1>
4821 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)(_Arg1));
4826 template<
typename _ReturnType>
4827 void _Arg1PFNHelperThunk(_ReturnType(__cdecl *)());
4829 template<
typename _ReturnType>
4830 void _Arg2PFNHelperThunk(_ReturnType(__cdecl *)());
4832 template<
typename _ReturnType>
4833 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)());
4835 template<
typename _ReturnType>
4836 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)());
4838 template<
typename _ReturnType>
4839 void _Arg1PFNHelperThunk(_ReturnType(__stdcall *)());
4841 template<
typename _ReturnType>
4842 void _Arg2PFNHelperThunk(_ReturnType(__stdcall *)());
4844 template<
typename _ReturnType>
4845 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)());
4847 template<
typename _ReturnType>
4848 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)());
4850 template<
typename _ReturnType>
4851 void _Arg1PFNHelperThunk(_ReturnType(__fastcall *)());
4853 template<
typename _ReturnType>
4854 void _Arg2PFNHelperThunk(_ReturnType(__fastcall *)());
4856 template<
typename _ReturnType>
4857 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)());
4859 template<
typename _ReturnType>
4860 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)());
4862 template<
typename _Ty>
4863 struct _FunctorArguments
4865 static const size_t _Count = 0;
4869 struct _FunctorArguments<_OneArgumentFunctor>
4871 static const size_t _Count = 1;
4875 struct _FunctorArguments<_TwoArgumentFunctor>
4877 static const size_t _Count = 2;
4880 template<
typename _Ty>
4881 struct _FunctorTypeTraits
4883 typedef decltype(_ArgumentCountHelper(&(_Ty::operator()))) _ArgumentCountType;
4884 static const
size_t _ArgumentCount = _FunctorArguments<_ArgumentCountType>::
_Count;
4886 typedef decltype(_ReturnTypeClassHelperThunk(&(_Ty::operator()))) _ReturnType;
4887 typedef decltype(_Arg1ClassHelperThunk(&(_Ty::operator()))) _Argument1Type;
4888 typedef decltype(_Arg2ClassHelperThunk(&(_Ty::operator()))) _Argument2Type;
4891 template<typename _Ty>
4892 struct _FunctorTypeTraits<_Ty *>
4894 typedef decltype(_ArgumentCountHelper(details::declval<_Ty*>())) _ArgumentCountType;
4895 static const
size_t _ArgumentCount = _FunctorArguments<_ArgumentCountType>::_Count;
4897 typedef decltype(_ReturnTypePFNHelperThunk(details::
declval<_Ty*>())) _ReturnType;
4898 typedef decltype(_Arg1PFNHelperThunk(details::
declval<_Ty*>())) _Argument1Type;
4899 typedef decltype(_Arg2PFNHelperThunk(details::
declval<_Ty*>())) _Argument2Type;
4902 template<typename _Ty>
4903 struct _ProgressTypeTraits
4905 static const bool _TakesProgress =
false;
4906 typedef void _ProgressType;
4909 template<
typename _Ty>
4910 struct _ProgressTypeTraits<progress_reporter<_Ty>>
4912 static const bool _TakesProgress =
true;
4913 typedef typename _Ty _ProgressType;
4917 template<typename _Ty, size_t _Count = _FunctorTypeTraits<_Ty>::_ArgumentCount>
4918 struct _CAFunctorOptions
4920 static const bool _TakesProgress =
false;
4921 static const bool _TakesToken =
false;
4922 typedef void _ProgressType;
4925 template<
typename _Ty>
4926 struct _CAFunctorOptions<_Ty, 1>
4930 typedef typename _FunctorTypeTraits<_Ty>::_Argument1Type _Argument1Type;
4934 static const bool _TakesProgress = _ProgressTypeTraits<_Argument1Type>::_TakesProgress;
4935 static const bool _TakesToken = !_TakesProgress;
4936 typedef typename _ProgressTypeTraits<_Argument1Type>::_ProgressType _ProgressType;
4939 template<
typename _Ty>
4940 struct _CAFunctorOptions<_Ty, 2>
4944 typedef typename _FunctorTypeTraits<_Ty>::_Argument1Type _Argument1Type;
4948 static const bool _TakesProgress =
true;
4949 static const bool _TakesToken =
true;
4950 typedef typename _ProgressTypeTraits<_Argument1Type>::_ProgressType _ProgressType;
4964 template<
typename _AsyncSelector,
typename _ReturnType>
4965 struct _SelectorTaskGenerator
4967 template<
typename _Function>
4968 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4970 task_options _taskOptinos(_Cts.get_token());
4972 return task<_ReturnType>(_Func(), _taskOptinos);
4975 template<
typename _Function>
4976 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4978 task_options _taskOptinos(_Cts.get_token());
4980 return task<_ReturnType>(_Func(_Cts.get_token()), _taskOptinos);
4983 template<
typename _Function,
typename _ProgressObject>
4984 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4986 task_options _taskOptinos(_Cts.get_token());
4988 return task<_ReturnType>(_Func(_Progress), _taskOptinos);
4991 template<
typename _Function,
typename _ProgressObject>
4992 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4994 task_options _taskOptinos(_Cts.get_token());
4996 return task<_ReturnType>(_Func(_Progress, _Cts.get_token()), _taskOptinos);
5000 template<
typename _AsyncSelector>
5001 struct _SelectorTaskGenerator<_AsyncSelector, void>
5003 template<
typename _Function>
5004 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5006 task_options _taskOptinos(_Cts.get_token());
5008 return task<void>(_Func(), _taskOptinos);
5011 template<
typename _Function>
5012 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5014 task_options _taskOptinos(_Cts.get_token());
5016 return task<void>(_Func(_Cts.get_token()), _taskOptinos);
5019 template<
typename _Function,
typename _ProgressObject>
5020 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5022 task_options _taskOptinos(_Cts.get_token());
5024 return task<void>(_Func(_Progress), _taskOptinos);
5027 template<
typename _Function,
typename _ProgressObject>
5028 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5030 task_options _taskOptinos(_Cts.get_token());
5032 return task<void>(_Func(_Progress, _Cts.get_token()), _taskOptinos);
5039 template<
typename _ReturnType>
5040 struct _SelectorTaskGenerator<_TypeSelectorNoAsync, _ReturnType>
5043 #pragma warning(push)
5044 #pragma warning(disable: 4702)
5045 template<
typename _Function>
5046 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5048 task_options _taskOptinos(_Cts.get_token());
5050 return task<_ReturnType>( [=]() -> _ReturnType {
5056 #pragma warning(pop)
5058 template<
typename _Function>
5059 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5061 task_options _taskOptinos(_Cts.get_token());
5063 return task<_ReturnType>( [=]() -> _ReturnType {
5066 return _Func(_Cts.get_token());
5070 template<
typename _Function,
typename _ProgressObject>
5071 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5073 task_options _taskOptinos(_Cts.get_token());
5075 return task<_ReturnType>( [=]() -> _ReturnType {
5078 return _Func(_Progress);
5082 template<
typename _Function,
typename _ProgressObject>
5083 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5085 task_options _taskOptinos(_Cts.get_token());
5087 return task<_ReturnType>( [=]() -> _ReturnType {
5090 return _Func(_Progress, _Cts.get_token());
5096 struct _SelectorTaskGenerator<_TypeSelectorNoAsync, void>
5098 template<
typename _Function>
5099 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5101 task_options _taskOptinos(_Cts.get_token());
5103 return task<void>( [=]() {
5110 template<
typename _Function>
5111 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5113 task_options _taskOptinos(_Cts.get_token());
5115 return task<void>( [=]() {
5118 _Func(_Cts.get_token());
5122 template<
typename _Function,
typename _ProgressObject>
5123 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5125 task_options _taskOptinos(_Cts.get_token());
5127 return task<void>( [=]() {
5134 template<
typename _Function,
typename _ProgressObject>
5135 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5137 task_options _taskOptinos(_Cts.get_token());
5139 return task<void>( [=]() {
5142 _Func(_Progress, _Cts.get_token());
5150 template<
typename _ReturnType>
5151 struct _SelectorTaskGenerator<_TypeSelectorAsyncTask, _ReturnType>
5153 template<
typename _Function>
5154 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5159 template<
typename _Function>
5160 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5162 return _Func(_Cts.get_token());
5165 template<
typename _Function,
typename _ProgressObject>
5166 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5168 return _Func(_Progress);
5171 template<
typename _Function,
typename _ProgressObject>
5172 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5174 return _Func(_Progress, _Cts.get_token());
5179 struct _SelectorTaskGenerator<_TypeSelectorAsyncTask, void>
5181 template<
typename _Function>
5182 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5187 template<
typename _Function>
5188 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5190 return _Func(_Cts.get_token());
5193 template<
typename _Function,
typename _ProgressObject>
5194 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5196 return _Func(_Progress);
5199 template<
typename _Function,
typename _ProgressObject>
5200 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5202 return _Func(_Progress, _Cts.get_token());
5206 template<
typename _Generator,
bool _TakesToken,
bool TakesProgress>
5207 struct _TaskGenerator
5211 template<
typename _Generator>
5212 struct _TaskGenerator<_Generator, false, false>
5214 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5215 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5216 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5218 #ifndef _PPLTASKS_NO_STDFUNC
5219 typedef decltype(_Func()) _ReturnType;
5220 typedef
std::
function<_ReturnType __cdecl()> _StdFunction;
5221 return _Generator::_GenerateTask_0(_StdFunction(_Func), _Cts, _callstack);
5223 return _Generator::_GenerateTask_0(_Func, _Cts, _callstack);
5228 template<
typename _Generator>
5229 struct _TaskGenerator<_Generator, true, false>
5231 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5232 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5233 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5235 #ifndef _PPLTASKS_NO_STDFUNC
5236 typedef decltype(_Func(details::declval<cancellation_token>())) _ReturnType;
5237 return _Generator::_GenerateTask_1C(
std::
function<_ReturnType __cdecl(cancellation_token)>(_Func), _Cts, _callstack);
5239 return _Generator::_GenerateTask_1C(_Func, _Cts, _callstack);
5244 template<
typename _Generator>
5245 struct _TaskGenerator<_Generator, false, true>
5247 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5248 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5249 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5251 #ifndef _PPLTASKS_NO_STDFUNC
5252 typedef decltype(_Func(
details::declval<
const progress_reporter<_ProgressType>&>())) _ReturnType;
5253 return _Generator::_GenerateTask_1P(
std::
function<_ReturnType __cdecl(const progress_reporter<_ProgressType>&)>(_Func), progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5255 return _Generator::_GenerateTask_1P(_Func, progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5260 template<
typename _Generator>
5261 struct _TaskGenerator<_Generator, true, true>
5263 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5264 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5265 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5267 #ifndef _PPLTASKS_NO_STDFUNC
5268 typedef decltype(_Func(
details::declval<
const progress_reporter<_ProgressType>&>(), details::declval<cancellation_token>())) _ReturnType;
5269 return _Generator::_GenerateTask_2PC(
std::
function<_ReturnType __cdecl(const progress_reporter<_ProgressType>&, cancellation_token)>(_Func), progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5271 return _Generator::_GenerateTask_2PC(_Func, progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5297 template<
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken,
bool _TakesProgress>
5298 struct _AsyncAttributes
5302 template<
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken>
5303 struct _AsyncAttributes<_ProgressType, _ReturnType, _TaskTraits, _TakesToken, true>
5305 typedef Windows::Foundation::IAsyncOperationWithProgress<_ReturnType, _ProgressType> _AsyncBaseType;
5306 typedef Windows::Foundation::AsyncOperationProgressHandler<_ReturnType, _ProgressType> _ProgressDelegateType;
5307 typedef Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_ReturnType, _ProgressType> _CompletionDelegateType;
5308 typedef _ReturnType _ReturnType;
5309 typedef _ProgressType _ProgressType;
5310 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5311 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5312 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, true> _TaskGenerator;
5314 static const bool _TakesProgress =
true;
5315 static const bool _TakesToken = _TakesToken;
5318 template<
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken>
5319 struct _AsyncAttributes<_ProgressType, _ReturnType, _TaskTraits, _TakesToken, false>
5321 typedef Windows::Foundation::IAsyncOperation<_ReturnType> _AsyncBaseType;
5322 typedef _Zip _ProgressDelegateType;
5323 typedef Windows::Foundation::AsyncOperationCompletedHandler<_ReturnType> _CompletionDelegateType;
5324 typedef _ReturnType _ReturnType;
5325 typedef _ProgressType _ProgressType;
5326 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5327 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5328 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, false> _TaskGenerator;
5330 static const bool _TakesProgress =
false;
5331 static const bool _TakesToken = _TakesToken;
5334 template<
typename _ProgressType,
typename _TaskTraits,
bool _TakesToken>
5335 struct _AsyncAttributes<_ProgressType, void, _TaskTraits, _TakesToken, true>
5337 typedef Windows::Foundation::IAsyncActionWithProgress<_ProgressType> _AsyncBaseType;
5338 typedef Windows::Foundation::AsyncActionProgressHandler<_ProgressType> _ProgressDelegateType;
5339 typedef Windows::Foundation::AsyncActionWithProgressCompletedHandler<_ProgressType> _CompletionDelegateType;
5340 typedef void _ReturnType;
5341 typedef _ProgressType _ProgressType;
5342 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5343 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5344 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, true> _TaskGenerator;
5346 static const bool _TakesProgress =
true;
5347 static const bool _TakesToken = _TakesToken;
5350 template<
typename _ProgressType,
typename _TaskTraits,
bool _TakesToken>
5351 struct _AsyncAttributes<_ProgressType, void, _TaskTraits, _TakesToken, false>
5353 typedef Windows::Foundation::IAsyncAction _AsyncBaseType;
5354 typedef _Zip _ProgressDelegateType;
5355 typedef Windows::Foundation::AsyncActionCompletedHandler _CompletionDelegateType;
5356 typedef void _ReturnType;
5357 typedef _ProgressType _ProgressType;
5358 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5359 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5360 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, false> _TaskGenerator;
5362 static const bool _TakesProgress =
false;
5363 static const bool _TakesToken = _TakesToken;
5366 template<
typename _Function>
5367 struct _AsyncLambdaTypeTraits
5369 typedef typename _FunctorTypeTraits<_Function>::_ReturnType _ReturnType;
5370 typedef typename _FunctorTypeTraits<_Function>::_Argument1Type _Argument1Type;
5371 typedef typename _CAFunctorOptions<_Function>::_ProgressType _ProgressType;
5373 static const bool _TakesProgress = _CAFunctorOptions<_Function>::_TakesProgress;
5374 static const bool _TakesToken = _CAFunctorOptions<_Function>::_TakesToken;
5376 typedef _TaskTypeTraits<_ReturnType> _TaskTraits;
5377 typedef _AsyncAttributes<_ProgressType, typename _TaskTraits::_TaskRetType, _TaskTraits, _TakesToken, _TakesProgress> _AsyncAttributes;
5380 struct _AsyncAttributesTaskGenerator
5383 template<
typename _Function,
typename _ClassPtr,
typename _AsyncAttributesT>
5384 static task<typename _AsyncAttributesT::_ReturnType> _Generate_Task(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5386 return _AsyncAttributesT::_TaskGenerator::_GenerateTask<_Function, _ClassPtr, _AsyncAttributesT::_ProgressType>(_Func, _Ptr, _Cts, _callstack);
5397 template <
typename _Attributes, _AsyncResultType _ResultType = SingleResult >
5398 ref class _AsyncInfoBase
abstract : _Attributes::_AsyncBaseType
5403 _M_currentStatus(_AsyncStatusInternal::_AsyncCreated),
5405 _M_completeDelegate(nullptr),
5406 _M_CompleteDelegateAssigned(0),
5413 virtual typename _Attributes::_ReturnType GetResults()
5415 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5418 virtual property unsigned int Id
5422 _CheckValidStateForAsyncInfoCall();
5427 void set(
unsigned int id)
5429 _CheckValidStateForAsyncInfoCall();
5433 throw ::Platform::Exception::CreateException(E_INVALIDARG);
5435 else if (_M_currentStatus != _AsyncStatusInternal::_AsyncCreated)
5437 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5444 virtual property Windows::Foundation::AsyncStatus Status
5446 Windows::Foundation::AsyncStatus
get()
5448 _CheckValidStateForAsyncInfoCall();
5450 _AsyncStatusInternal _Current = _M_currentStatus;
5458 case _AsyncCancelPending:
5459 _Current = _AsyncCanceled;
5462 _Current = _AsyncStarted;
5468 return static_cast<Windows::Foundation::AsyncStatus
>(_Current);
5472 virtual property Windows::Foundation::HResult ErrorCode
5474 Windows::Foundation::HResult
get()
5476 _CheckValidStateForAsyncInfoCall();
5478 Windows::Foundation::HResult _Hr;
5479 _Hr.Value = _M_errorCode;
5484 virtual property typename _Attributes::_ProgressDelegateType^ Progress
5486 typename typename _Attributes::_ProgressDelegateType^
get()
5488 return _GetOnProgress();
5491 void set(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
5493 _PutOnProgress(_ProgressHandler);
5497 virtual void Cancel()
5499 if (_TransitionToState(_AsyncCancelPending))
5505 virtual void Close()
5507 if (_TransitionToState(_AsyncClosed))
5513 if (_M_currentStatus != _AsyncClosed)
5515 throw ::Platform::Exception::CreateException(E_ILLEGAL_STATE_CHANGE);
5520 virtual property typename _Attributes::_CompletionDelegateType^ Completed
5522 typename _Attributes::_CompletionDelegateType^
get()
5524 _CheckValidStateForDelegateCall();
5525 return _M_completeDelegate;
5528 void set(
typename _Attributes::_CompletionDelegateType^ _CompleteHandler)
5530 _CheckValidStateForDelegateCall();
5532 if (InterlockedIncrement(&_M_CompleteDelegateAssigned) == 1)
5535 _M_completeDelegate = _CompleteHandler;
5539 if (_IsTerminalState())
5546 throw ::Platform::Exception::CreateException(E_ILLEGAL_DELEGATE_ASSIGNMENT);
5557 if (_TransitionToState(_AsyncStarted))
5563 throw ::Platform::Exception::CreateException(E_ILLEGAL_STATE_CHANGE);
5568 void _FireCompletion()
5570 _TryTransitionToCompleted();
5573 if (_M_completeDelegate !=
nullptr && InterlockedIncrement(&_M_CallbackMade) == 1)
5575 _M_completeDelegateContext._CallInContext([=] {
5579 _M_completeDelegate((_Attributes::_AsyncBaseType^)
this, this->Status);
5580 _M_completeDelegate =
nullptr;
5582 catch(::Platform::Exception^ _ex)
5585 _M_completeDelegate =
nullptr;
5595 virtual typename _Attributes::_ProgressDelegateType^ _GetOnProgress()
5597 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5600 virtual void _PutOnProgress(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
5602 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5605 bool _TryTransitionToCompleted()
5607 return _TransitionToState(_AsyncStatusInternal::_AsyncCompleted);
5610 bool _TryTransitionToCancelled()
5612 return _TransitionToState(_AsyncStatusInternal::_AsyncCanceled);
5615 bool _TryTransitionToError(
const HRESULT error)
5618 return _TransitionToState(_AsyncStatusInternal::_AsyncError);
5624 inline void _CheckValidStateForDelegateCall()
5626 if (_M_currentStatus == _AsyncClosed)
5628 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5635 inline void _CheckValidStateForResultsCall()
5637 _AsyncStatusInternal _Current = _M_currentStatus;
5639 if (_Current == _AsyncError)
5641 throw ::Platform::Exception::CreateException(_M_errorCode);
5643 #pragma warning(push)
5644 #pragma warning(disable: 4127) // Conditional expression is constant
5646 if (_ResultType == SingleResult)
5647 #pragma warning(pop)
5649 if (_Current != _AsyncCompleted)
5651 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5655 else if (_Current != _AsyncStarted &&
5656 _Current != _AsyncCancelPending &&
5657 _Current != _AsyncCanceled &&
5658 _Current != _AsyncCompleted)
5660 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5667 inline bool _ContinueAsyncOperation()
5669 return (_M_currentStatus == _AsyncStarted);
5675 virtual void _OnStart() = 0;
5676 virtual void _OnClose() = 0;
5677 virtual void _OnCancel() = 0;
5685 inline void _CheckValidStateForAsyncInfoCall()
5687 _AsyncStatusInternal _Current = _M_currentStatus;
5688 if (_Current == _AsyncClosed)
5690 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5692 else if (_Current == _AsyncCreated)
5694 throw ::Platform::Exception::CreateException(E_ASYNC_OPERATION_NOT_STARTED);
5699 inline bool _TransitionToState(
const _AsyncStatusInternal _NewState)
5701 _AsyncStatusInternal _Current = _M_currentStatus;
5707 case _AsyncStatusInternal::_AsyncStarted:
5708 if (_Current != _AsyncCreated)
5713 case _AsyncStatusInternal::_AsyncCompleted:
5714 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5719 case _AsyncStatusInternal::_AsyncCancelPending:
5720 if (_Current != _AsyncStarted)
5725 case _AsyncStatusInternal::_AsyncCanceled:
5726 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5731 case _AsyncStatusInternal::_AsyncError:
5732 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5737 case _AsyncStatusInternal::_AsyncClosed:
5738 if (!_IsTerminalState(_Current))
5751 _AsyncStatusInternal _RetState =
static_cast<_AsyncStatusInternal
>(
5754 static_cast<LONG>(_Current)));
5759 return (_RetState == _Current);
5762 inline bool _IsTerminalState()
5764 return _IsTerminalState(_M_currentStatus);
5767 inline bool _IsTerminalState(_AsyncStatusInternal
status)
5769 return (status == _AsyncError ||
5770 status == _AsyncCanceled ||
5771 status == _AsyncCompleted ||
5772 status == _AsyncClosed);
5777 _ContextCallback _M_completeDelegateContext;
5778 typename _Attributes::_CompletionDelegateType^
volatile _M_completeDelegate;
5779 _AsyncStatusInternal
volatile _M_currentStatus;
5780 HRESULT
volatile _M_errorCode;
5782 long volatile _M_CompleteDelegateAssigned;
5783 long volatile _M_CallbackMade;
5795 template<
typename _Attributes,
bool _HasProgress, _AsyncResultType _ResultType = SingleResult >
5796 ref class __declspec(no_empty_identity_interface) _AsyncProgressBase
abstract : _AsyncInfoBase<_Attributes, _ResultType>
5800 template<
typename _Attributes, _AsyncResultType _ResultType>
5801 ref class __declspec(no_empty_identity_interface) _AsyncProgressBase<_Attributes, true, _ResultType>
abstract : _AsyncInfoBase<_Attributes, _ResultType>
5805 _AsyncProgressBase() : _AsyncInfoBase<_Attributes, _ResultType>(),
5806 _M_progressDelegate(nullptr)
5810 virtual typename _Attributes::_ProgressDelegateType^ _GetOnProgress()
override
5812 _CheckValidStateForDelegateCall();
5813 return _M_progressDelegate;
5816 virtual void _PutOnProgress(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
override
5818 _CheckValidStateForDelegateCall();
5819 _M_progressDelegate = _ProgressHandler;
5823 void _FireProgress(
const typename _Attributes::_ProgressType& _ProgressValue)
5825 if (_M_progressDelegate !=
nullptr)
5827 _M_progressDelegateContext._CallInContext([=] {
5830 _M_progressDelegate((_Attributes::_AsyncBaseType^)
this, _ProgressValue);
5832 catch(::Platform::Exception^ _ex)
5835 _M_progressDelegate =
nullptr;
5847 _ContextCallback _M_progressDelegateContext;
5848 typename _Attributes::_ProgressDelegateType^ _M_progressDelegate;
5854 template<
typename _Function>
5855 ref class _AsyncTaskGeneratorThunk
sealed : _AsyncProgressBase<typename _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes,
5856 _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes::_TakesProgress>
5860 typedef typename _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes _Attributes;
5861 typedef typename _Attributes::_AsyncBaseType _AsyncBaseType;
5863 _AsyncTaskGeneratorThunk(
const _Function& _Func,
const _TaskCreationCallstack &_callstack) : _M_func(_Func), _M_creationCallstack(_callstack)
5871 virtual typename _Attributes::_ReturnType GetResults()
override
5873 _CheckValidStateForResultsCall();
5874 return _M_task.get();
5884 virtual void _OnStart()
override
5890 _M_task = _AsyncAttributesTaskGenerator::_Generate_Task<_Function, _AsyncTaskGeneratorThunk<_Function>^, _Attributes>(_M_func,
this, _M_cts, _M_creationCallstack);
5891 _M_task.then([=](task<typename _Attributes::_ReturnType> _Antecedent) {
5896 catch (task_canceled&)
5898 _TryTransitionToCancelled();
5900 catch (::Platform::Exception^ _Ex)
5902 _TryTransitionToError(_Ex->HResult);
5906 _TryTransitionToError(E_FAIL);
5912 virtual void _OnCancel()
override
5917 virtual void _OnClose()
override
5923 task<typename _Attributes::_ReturnType> _M_task;
5924 cancellation_token_source _M_cts;
5925 _TaskCreationCallstack _M_creationCallstack;
5970 template<
typename _Function>
5972 details::_AsyncTaskGeneratorThunk<_Function> ^create_async(const _Function& _Func)
5974 static_assert(std::is_same<decltype(details::_IsValidCreateAsync(_Func,0,0,0,0)),
std::true_type>::value,
5975 "argument to create_async must be a callable object taking zero, one or two arguments");
5987 template<
typename _Type>
5990 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
5994 void _Resize(
size_t _Len,
bool _SkipVector =
false)
5999 _M_vector._Result.resize(_Len);
6003 task_completion_event<_Unit_type> _M_completed;
6004 _ResultHolder<std::vector<_Type> > _M_vector;
6005 _ResultHolder<_Type> _M_mergeVal;
6010 template<
typename _Type>
6011 struct _RunAllParam<
std::
vector<_Type> >
6013 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
6017 void _Resize(
size_t _Len,
bool _SkipVector =
false)
6023 _M_vector.resize(_Len);
6027 task_completion_event<_Unit_type> _M_completed;
6028 std::vector<_ResultHolder<std::vector<_Type> > > _M_vector;
6035 struct _RunAllParam<_Unit_type>
6037 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
6046 task_completion_event<_Unit_type> _M_completed;
6051 inline void _JoinAllTokens_Add(
const cancellation_token_source& _MergedSrc, _CancellationTokenState *_PJoinedTokenState)
6056 _T.register_callback( [=](){
6057 _MergedSrc.cancel();
6062 template<
typename _ElementType,
typename _Function,
typename _TaskType>
6063 void _WhenAllContinuationWrapper(_RunAllParam<_ElementType>* _PParam, _Function _Func, task<_TaskType>& _Task)
6065 if (_Task._GetImpl()->_IsCompleted())
6078 _ASSERTE(_Task._GetImpl()->_IsCanceled());
6079 if (_Task._GetImpl()->_HasUserException())
6082 if (!_PParam->_M_completed._Cancel(_Task._GetImpl()->_GetExceptionHolder()))
6084 atomic_exchange(_Task._GetImpl()->_GetExceptionHolder()->_M_exceptionObserved, 1l);
6089 _PParam->_M_completed._Cancel();
6099 template<
typename _ElementType,
typename _Iterator>
6102 static task<std::vector<_ElementType>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6104 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6106 auto _PParam =
new _RunAllParam<_ElementType>();
6107 cancellation_token_source _MergedSource;
6110 task_options _Options(_TaskOptions);
6111 _Options.set_cancellation_token(_MergedSource.get_token());
6112 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6114 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> {
6115 return _PParam->_M_vector.Get();
6121 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6122 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6126 size_t _TaskNum = 0;
6127 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6130 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6132 _PParam->_Resize(_TaskNum);
6136 if( _Begin == _End )
6144 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6146 if (_PTask->is_apartment_aware())
6148 _ReturnTask._SetAsync();
6151 _PTask->_Then([_PParam, _Index](task<_ElementType> _ResultTask) {
6154 typedef _ElementType _ElementTypeDev10;
6155 auto _PParamCopy = _PParam;
6156 auto _IndexCopy =
_Index;
6157 auto _Func = [_PParamCopy, _IndexCopy, &_ResultTask](){
6158 _PParamCopy->_M_vector._Result[_IndexCopy] = _ResultTask._GetImpl()->_GetResult();
6161 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6172 template<
typename _ElementType,
typename _Iterator>
6173 struct _WhenAllImpl<
std::
vector<_ElementType>, _Iterator>
6175 static task<std::vector<_ElementType>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6177 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6179 auto _PParam =
new _RunAllParam<std::vector<_ElementType>>();
6180 cancellation_token_source _MergedSource;
6183 task_options _Options(_TaskOptions);
6184 _Options.set_cancellation_token(_MergedSource.get_token());
6185 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6187 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> {
6188 _ASSERTE(_PParam->_M_completeCount == _PParam->_M_numTasks);
6189 std::vector<_ElementType>
_Result;
6190 for(
size_t _I = 0; _I < _PParam->_M_numTasks; _I++)
6192 const std::vector<_ElementType>& _Vec = _PParam->_M_vector[_I].Get();
6193 _Result.insert(_Result.end(), _Vec.begin(), _Vec.end());
6201 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6202 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6206 size_t _TaskNum = 0;
6207 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6210 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6212 _PParam->_Resize(_TaskNum);
6216 if( _Begin == _End )
6224 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6226 if (_PTask->is_apartment_aware())
6228 _ReturnTask._SetAsync();
6231 _PTask->_Then([_PParam, _Index](task<std::vector<_ElementType>> _ResultTask) {
6233 typedef _ElementType _ElementTypeDev10;
6234 auto _PParamCopy = _PParam;
6235 auto _IndexCopy =
_Index;
6236 auto _Func = [_PParamCopy, _IndexCopy, &_ResultTask]() {
6237 _PParamCopy->_M_vector[_IndexCopy].Set(_ResultTask._GetImpl()->_GetResult());
6240 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6251 template<
typename _Iterator>
6252 struct _WhenAllImpl<void, _Iterator>
6254 static task<void> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6256 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6258 auto _PParam =
new _RunAllParam<_Unit_type>();
6259 cancellation_token_source _MergedSource;
6262 task_options _Options(_TaskOptions);
6263 _Options.set_cancellation_token(_MergedSource.get_token());
6264 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6266 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) {
6272 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6273 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6277 size_t _TaskNum = 0;
6278 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6281 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6283 _PParam->_Resize(_TaskNum);
6287 if( _Begin == _End )
6294 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6296 if (_PTask->is_apartment_aware())
6298 _ReturnTask._SetAsync();
6301 _PTask->_Then([_PParam](task<void> _ResultTask) {
6302 auto _Func = [](){};
6303 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6312 template<
typename _ReturnType>
6313 task<std::vector<_ReturnType>> _WhenAllVectorAndValue(
const task<std::vector<_ReturnType>>& _VectorTask,
const task<_ReturnType>& _ValueTask,
6314 bool _OutputVectorFirst)
6316 auto _PParam =
new _RunAllParam<_ReturnType>();
6317 cancellation_token_source _MergedSource;
6320 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _MergedSource.get_token());
6322 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ReturnType> {
6323 _ASSERTE(_PParam->_M_completeCount == 2);
6324 auto _Result = _PParam->_M_vector.Get();
6325 auto _mergeVal = _PParam->_M_mergeVal.Get();
6327 if (_OutputVectorFirst ==
true)
6329 _Result.push_back(_mergeVal);
6333 _Result.insert(_Result.begin(), _mergeVal);
6339 _JoinAllTokens_Add(_MergedSource, _VectorTask._GetImpl()->_M_pTokenState);
6340 _JoinAllTokens_Add(_MergedSource, _ValueTask._GetImpl()->_M_pTokenState);
6343 _PParam->_Resize(2,
true);
6345 if (_VectorTask.is_apartment_aware() || _ValueTask.is_apartment_aware())
6347 _ReturnTask._SetAsync();
6349 _VectorTask._Then([_PParam](task<std::vector<_ReturnType>> _ResultTask) {
6351 typedef _ReturnType _ReturnTypeDev10;
6352 auto _PParamCopy = _PParam;
6353 auto _Func = [_PParamCopy, &_ResultTask]() {
6354 auto _ResultLocal = _ResultTask._GetImpl()->_GetResult();
6355 _PParamCopy->_M_vector.Set(_ResultLocal);
6358 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6360 _ValueTask._Then([_PParam](task<_ReturnType> _ResultTask) {
6362 typedef _ReturnType _ReturnTypeDev10;
6363 auto _PParamCopy = _PParam;
6364 auto _Func = [_PParamCopy, &_ResultTask]() {
6365 auto _ResultLocal = _ResultTask._GetImpl()->_GetResult();
6366 _PParamCopy->_M_mergeVal.Set(_ResultLocal);
6369 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6399 template <
typename _Iterator>
6400 auto when_all(_Iterator _Begin, _Iterator _End,
const task_options& _TaskOptions = task_options())
6401 -> decltype (details::_WhenAllImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_TaskOptions, _Begin, _End))
6403 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6404 return details::_WhenAllImpl<_ElementType, _Iterator>::_Perform(_TaskOptions, _Begin, _End);
6432 template<
typename _ReturnType>
6433 task<std::vector<_ReturnType>>
operator&&(
const task<_ReturnType> & _Lhs,
const task<_ReturnType> & _Rhs)
6435 task<_ReturnType> _PTasks[2] = {_Lhs, _Rhs};
6436 return when_all(_PTasks, _PTasks+2);
6464 template<
typename _ReturnType>
6465 task<std::vector<_ReturnType>>
operator&&(
const task<std::vector<_ReturnType>> & _Lhs,
const task<_ReturnType> & _Rhs)
6467 return details::_WhenAllVectorAndValue(_Lhs, _Rhs,
true);
6495 template<
typename _ReturnType>
6496 task<std::vector<_ReturnType>>
operator&&(
const task<_ReturnType> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6498 return details::_WhenAllVectorAndValue(_Rhs, _Lhs,
false);
6526 template<
typename _ReturnType>
6527 task<std::vector<_ReturnType>>
operator&&(
const task<std::vector<_ReturnType>> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6529 task<std::vector<_ReturnType>> _PTasks[2] = {_Lhs, _Rhs};
6530 return when_all(_PTasks, _PTasks+2);
6558 inline task<void>
operator&&(
const task<void> & _Lhs,
const task<void> & _Rhs)
6560 task<void> _PTasks[2] = {_Lhs, _Rhs};
6561 return when_all(_PTasks, _PTasks+2);
6567 template <
typename _CompletionType>
6570 _RunAnyParam() : _M_exceptionRelatedToken(nullptr), _M_completeCount(0), _M_numTasks(0), _M_fHasExplicitToken(false)
6576 _M_exceptionRelatedToken->_Release();
6578 task_completion_event<_CompletionType> _M_Completed;
6579 cancellation_token_source _M_cancellationSource;
6580 _CancellationTokenState * _M_exceptionRelatedToken;
6583 bool _M_fHasExplicitToken;
6586 template<
typename _CompletionType,
typename _Function,
typename _TaskType>
6587 void _WhenAnyContinuationWrapper(_RunAnyParam<_CompletionType> * _PParam,
const _Function & _Func, task<_TaskType>& _Task)
6589 bool _IsTokenCanceled = !_PParam->_M_fHasExplicitToken && _Task._GetImpl()->_M_pTokenState !=
_CancellationTokenState::_None() && _Task._GetImpl()->_M_pTokenState->_IsCanceled();
6590 if (_Task._GetImpl()->_IsCompleted() && !_IsTokenCanceled)
6595 _PParam->_M_Completed._ClearStoredException();
6601 _ASSERTE(_Task._GetImpl()->_IsCanceled() || _IsTokenCanceled);
6602 if (_Task._GetImpl()->_HasUserException())
6604 if (!_IsTokenCanceled && _PParam->_M_Completed._StoreException(_Task._GetImpl()->_GetExceptionHolder()))
6607 _PParam->_M_exceptionRelatedToken = _Task._GetImpl()->_M_pTokenState;
6608 _ASSERTE(_PParam->_M_exceptionRelatedToken);
6612 _PParam->_M_exceptionRelatedToken->_Reference();
6618 atomic_exchange(_Task._GetImpl()->_GetExceptionHolder()->_M_exceptionObserved, 1l);
6625 if (!_PParam->_M_Completed._IsTriggered())
6628 if (!_PParam->_M_fHasExplicitToken)
6630 if (_PParam->_M_exceptionRelatedToken)
6632 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PParam->_M_exceptionRelatedToken);
6638 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _Task._GetImpl()->_M_pTokenState);
6642 _PParam->_M_Completed._Cancel();
6645 _PParam->_M_Completed._ClearStoredException();
6651 template<
typename _ElementType,
typename _Iterator>
6654 static task<std::pair<_ElementType, size_t>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6656 if( _Begin == _End )
6658 _THROW_NCEE(invalid_operation,
"when_any(begin, end) cannot be called on an empty container.");
6660 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6661 auto _PParam =
new _RunAnyParam<std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *>>();
6665 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PTokenState);
6666 _PParam->_M_fHasExplicitToken =
true;
6669 task_options _Options(_TaskOptions);
6670 _Options.set_cancellation_token(_PParam->_M_cancellationSource.get_token());
6671 task<std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _Options);
6674 auto _CancellationSource = _PParam->_M_cancellationSource;
6676 _PParam->_M_numTasks =
static_cast<size_t>(
std::distance(_Begin, _End));
6678 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6680 if (_PTask->is_apartment_aware())
6682 _Any_tasks_completed._SetAsync();
6685 _PTask->_Then([_PParam, _Index](task<_ElementType> _ResultTask) {
6686 auto _PParamCopy = _PParam;
6687 auto _IndexCopy =
_Index;
6688 auto _Func = [&_ResultTask, _PParamCopy, _IndexCopy]() {
6689 _PParamCopy->_M_Completed.set(
std::make_pair(
std::make_pair(_ResultTask._GetImpl()->_GetResult(), _IndexCopy), _ResultTask._GetImpl()->_M_pTokenState));
6692 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6699 return _Any_tasks_completed._Then([=](std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *> _Result) -> std::pair<_ElementType, size_t> {
6703 _JoinAllTokens_Add(_CancellationSource, _Result.second);
6705 return _Result.first;
6710 template<
typename _Iterator>
6711 struct _WhenAnyImpl<void, _Iterator>
6713 static task<size_t> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6715 if( _Begin == _End )
6717 _THROW_NCEE(invalid_operation,
"when_any(begin, end) cannot be called on an empty container.");
6720 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6721 auto _PParam =
new _RunAnyParam<std::pair<size_t, _CancellationTokenState *>>();
6725 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PTokenState);
6726 _PParam->_M_fHasExplicitToken =
true;
6729 task_options _Options(_TaskOptions);
6730 _Options.set_cancellation_token(_PParam->_M_cancellationSource.get_token());
6731 task<std::pair<size_t, _CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _Options);
6734 auto _CancellationSource = _PParam->_M_cancellationSource;
6736 _PParam->_M_numTasks =
static_cast<size_t>(
std::distance(_Begin, _End));
6738 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6740 if (_PTask->is_apartment_aware())
6742 _Any_tasks_completed._SetAsync();
6745 _PTask->_Then([_PParam, _Index](task<void> _ResultTask) {
6746 auto _PParamCopy = _PParam;
6747 auto _IndexCopy =
_Index;
6748 auto _Func = [&_ResultTask, _PParamCopy, _IndexCopy]() {
6749 _PParamCopy->_M_Completed.set(
std::make_pair(_IndexCopy, _ResultTask._GetImpl()->_M_pTokenState));
6751 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6758 return _Any_tasks_completed._Then([=](std::pair<size_t, _CancellationTokenState *> _Result) ->
size_t {
6762 _JoinAllTokens_Add(_CancellationSource, _Result.second);
6764 return _Result.first;
6790 template<
typename _Iterator>
6791 auto when_any(_Iterator _Begin, _Iterator _End,
const task_options& _TaskOptions = task_options())
6792 -> decltype (details::_WhenAnyImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_TaskOptions, _Begin, _End))
6794 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6795 return details::_WhenAnyImpl<_ElementType, _Iterator>::_Perform(_TaskOptions, _Begin, _End);
6822 template<
typename _Iterator>
6823 auto when_any(_Iterator _Begin, _Iterator _End, cancellation_token _CancellationToken)
6824 -> decltype (details::_WhenAnyImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End))
6826 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6827 return details::_WhenAnyImpl<_ElementType, _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End);
6856 template<
typename _ReturnType>
6857 task<_ReturnType>
operator||(
const task<_ReturnType> & _Lhs,
const task<_ReturnType> & _Rhs)
6859 auto _PParam =
new details::_RunAnyParam<std::pair<_ReturnType, size_t>>();
6861 task<std::pair<_ReturnType, size_t>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
6864 auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair<_ReturnType, size_t> _Ret) -> _ReturnType {
6866 _JoinAllTokens_Add(_PParam->_M_cancellationSource, reinterpret_cast<details::_CancellationTokenState *>(_Ret.second));
6870 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
6872 _ReturnTask._SetAsync();
6875 _PParam->_M_numTasks = 2;
6876 auto _Continuation = [_PParam](task<_ReturnType> _ResultTask) {
6878 auto _PParamCopy = _PParam;
6879 auto _Func = [&_ResultTask, _PParamCopy]() {
6880 _PParamCopy->_M_Completed.set(
std::make_pair(_ResultTask._GetImpl()->_GetResult(),
reinterpret_cast<size_t>(_ResultTask._GetImpl()->_M_pTokenState)));
6882 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6917 template<
typename _ReturnType>
6918 task<std::vector<_ReturnType>>
operator||(
const task<std::vector<_ReturnType>> & _Lhs,
const task<_ReturnType> & _Rhs)
6920 auto _PParam =
new details::_RunAnyParam<std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *>>();
6922 task<std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
6926 auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *> _Ret) -> std::vector<_ReturnType> {
6928 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second);
6932 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
6934 _ReturnTask._SetAsync();
6937 _PParam->_M_numTasks = 2;
6938 _Lhs._Then([_PParam](task<std::vector<_ReturnType>> _ResultTask) {
6940 auto _PParamCopy = _PParam;
6941 auto _Func = [&_ResultTask, _PParamCopy]() {
6942 auto _Result = _ResultTask._GetImpl()->_GetResult();
6943 _PParamCopy->_M_Completed.set(
std::make_pair(_Result, _ResultTask._GetImpl()->_M_pTokenState));
6945 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6949 _Rhs._Then([_PParam](task<_ReturnType> _ResultTask)
6952 typedef _ReturnType _ReturnTypeDev10;
6953 auto _PParamCopy = _PParam;
6954 auto _Func = [&_ResultTask, _PParamCopy]() {
6955 auto _Result = _ResultTask._GetImpl()->_GetResult();
6957 std::vector<_ReturnTypeDev10> _Vec;
6958 _Vec.push_back(_Result);
6959 _PParamCopy->_M_Completed.set(
std::make_pair(_Vec, _ResultTask._GetImpl()->_M_pTokenState));
6961 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6993 template<
typename _ReturnType>
6994 task<std::vector<_ReturnType>>
operator||(
const task<_ReturnType> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6996 return _Rhs || _Lhs;
7025 inline task<void>
operator||(
const task<void> & _Lhs,
const task<void> & _Rhs)
7027 auto _PParam =
new details::_RunAnyParam<std::pair<details::_Unit_type, details::_CancellationTokenState *>>();
7029 task<std::pair<details::_Unit_type, details::_CancellationTokenState *>> _Any_task_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
7032 auto _ReturnTask = _Any_task_completed._Then([=](std::pair<details::_Unit_type, details::_CancellationTokenState *> _Ret) {
7034 details::_JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second);
7037 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
7039 _ReturnTask._SetAsync();
7042 _PParam->_M_numTasks = 2;
7043 auto _Continuation = [_PParam](task<void> _ResultTask)
mutable {
7045 auto _PParam1 = _PParam;
7046 auto _Func = [&_ResultTask, _PParam1]() {
7049 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
7058 template<
typename _Ty>
7059 task<_Ty> task_from_result(_Ty _Param,
const task_options& _TaskOptions = task_options())
7061 task_completion_event<_Ty> _Tce;
7063 return create_task(_Tce, _TaskOptions);
7066 inline task<void> task_from_result(
const task_options& _TaskOptions = task_options())
7068 task_completion_event<void> _Tce;
7070 return create_task(_Tce, _TaskOptions);
7073 template<
typename _TaskType,
typename _ExType>
7074 task<_TaskType> task_from_exception(_ExType _Exception,
const task_options& _TaskOptions = task_options())
7076 task_completion_event<_TaskType> _Tce;
7077 _Tce.set_exception(_Exception);
7078 return create_task(_Tce, _TaskOptions);
7091 task<bool> do_while(std::function<task<bool>(
void)> _Func)
7093 task<bool> _First = _Func();
7094 return _First.then([=](
bool _Guard) -> task<bool> {
7096 return do_while(_Func);
7106 #pragma pop_macro("new")
7107 #pragma warning(pop)
7110 #endif // _PPLTASKS_H
Definition: ppltasks.h:1038
_InitialTaskHandle(const typename details::_Task_ptr< _ReturnType >::_Type &_TaskImpl, const _Function &_func)
Definition: ppltasks.h:3454
Definition: xtr1common:23
return
Definition: corecrt_memcpy_s.h:60
std::shared_ptr< _ExceptionHolder > _M_exceptionHolder
Definition: ppltasks.h:2027
void _set_creation_callstack(const _TaskCreationCallstack &_callstack)
Definition: ppltasks.h:1043
void _RethrowUserException()
Definition: ppltasks.h:755
virtual ~_PPLTaskHandle()
Definition: ppltasks.h:1403
std::function< _Unit_type(void)> _MakeVoidToUnitFunc(const std::function< void(void)> &_Func)
Definition: ppltasks.h:2299
bool _IsCompleted()
Definition: ppltasks.h:1657
static _TaskCreationCallstack _CaptureSingleFrameCallstack(void *_SingleFrame)
Definition: ppltasks.h:170
_TaskCreationCallstack _M_presetCreationCallstack
Definition: ppltasks.h:1041
_Ty _Type
Definition: ppltasks.h:205
scheduler_ptr _M_Scheduler
Definition: ppltasks.h:1225
void _TaskInitMaybeFunctor(_Function &_Func, std::true_type)
Initializes a task using a callable object.
Definition: ppltasks.h:4366
Definition: ppltasks.h:401
_T atomic_exchange(std::atomic< _T > &_Target, _T _Value)
Definition: pplinterface.h:246
Definition: functional:68
void _Continue(std::false_type, details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3605
_Variant_copymove_layer_ & operator=(_Variant_copymove_layer_ &&_That) _NOEXCEPT_OP((conjunction< is_nothrow_move_constructible< _Types >...
void _SyncCancelAndPropagateException() const
Definition: ppltasks.h:3584
task_options()
Default list of task creation options
Definition: ppltasks.h:1068
bool _M_HasScheduler
Definition: ppltasks.h:1230
std::function< _Unit_type(_Unit_type)> _MakeUnitToUnitFunc(const std::function< void(void)> &_Func)
Definition: ppltasks.h:2316
_ThenImplOptions(_CancellationTokenState *_Token_state, const task_continuation_context *_Continuation_context, scheduler_ptr _PScheduler, _TaskCreationCallstack _Creation_stack, _TaskInliningMode_t _Inlining_mode=_NoInline)
Definition: ppltasks.h:1240
This class describes an exception thrown when an invalid operation is performed that is not more accu...
Definition: pplinterface.h:132
Definition: ppltasks.h:1290
_CRTIMP2 void __thiscall _LogWorkItemStarted()
bool _HasUserException()
Definition: ppltasks.h:1667
Definition: ppltasks.h:1347
reference_wrapper< _Ty > ref(_Ty &_Val) _NOEXCEPT
Definition: type_traits:1839
auto _Then(const _Function &_Func, details::_CancellationTokenState *_PTokenState, details::_TaskInliningMode_t _InliningMode=details::_ForceInline) const -> typename details::_ContinuationTypeTraits< _Function, void >::_TaskOfType
An internal version of then that takes additional flags and executes the continuation inline...
Definition: ppltasks.h:4312
bool _M_scheduled
Definition: ppltasks.h:1315
void Set(const std::vector< bool > &_type)
Definition: ppltasks.h:642
std::shared_ptr< _Task_impl_base > _Task_ptr_base
Definition: ppltasks.h:1287
~_TaskWorkItemRAIILogger()
Definition: ppltasks.h:1355
_Holder(_TaskProcThunk *_PThunk)
Definition: ppltasks.h:462
bool _ForceInline() const
Definition: ppltasks.h:1025
bool _M_RunInline
Definition: ppltasks.h:1032
#define S_OK
Definition: comutil.h:62
void _SetTaskCreationCallstack(const details::_TaskCreationCallstack &_callstack)
Sets a field in the task impl to the return callstack for calls to the task constructors and the then...
Definition: ppltasks.h:3415
std::function< _Type(_Unit_type)> _MakeUnitToTFunc(const std::function< _Type(void)> &_Func)
Definition: ppltasks.h:2305
_ContinuationList _M_Continuations
Definition: ppltasks.h:2032
details::_Task_ptr< _ReturnType >::_Type _M_ancestorTaskImpl
Definition: ppltasks.h:3552
Definition: ppltasks.h:1238
_Ty _Type
Definition: ppltasks.h:235
void _Perform() const
Definition: ppltasks.h:3469
auto _IsCallable(_Function _Func, int) -> decltype(_Func(), std::true_type())
std::vector< void * > _M_frames
Definition: ppltasks.h:162
_TaskCreationCallstack _M_stackTrace
Definition: ppltasks.h:776
scheduler_ptr _GetScheduler() const
Definition: ppltasks.h:2011
const details::_Task_ptr< _ReturnType >::_Type & _ThenGetImpl() const
Definition: ppltasks.h:3376
~_Task_completion_event_impl()
Definition: ppltasks.h:2279
bool operator==(const _Concurrent_queue_iterator< _C, _Ty > &_I, const _Concurrent_queue_iterator< _C, _U > &_J)
Definition: concurrent_queue.h:318
Definition: concrt.h:4304
Definition: pplinterface.h:228
_TaskWorkItemRAIILogger(_TaskEventLogger &_taskHandleLogger)
Definition: ppltasks.h:1350
_ContextCallback(bool _DeferCapture=false)
Definition: ppltasks.h:515
bool operator==(const _ContextCallback &_Rhs) const
Definition: ppltasks.h:582
const ::std::shared_ptr< scheduler_interface > & get_ambient_scheduler()
Definition: pplwin.h:88
void _LogTaskExecutionStarted()
Definition: ppltasks.h:1328
_Task_ptr_base _GetTaskImplBase() const
Definition: ppltasks.h:1437
void _RunContinuation(_ContinuationTaskHandleBase *_PTaskHandle)
Function executes a continuation. This function is recorded by a parent task implementation when a co...
Definition: ppltasks.h:1743
std::mutex _M_taskListCritSec
Definition: ppltasks.h:2291
details::_NormalizeVoidToUnitType< _ContinuationReturnType >::_Type _NormalizedContinuationReturnType
Definition: ppltasks.h:3550
task_options(cancellation_token _Token)
Task option that specify a cancellation token
Definition: ppltasks.h:1080
Definition: ppltasks.h:199
__declspec(noinline) static _TaskCreationCallstack _CaptureMultiFramesCallstack(void *_SingleFrame
_PPLTaskHandle(const typename _Task_ptr< _ReturnType >::_Type &_PTask)
Definition: ppltasks.h:1399
static cancellation_token none()
Returns a cancellation token which can never be subject to cancellation.
Definition: pplcancellation_token.h:628
task_continuation_context * _PContinuationContext
Definition: ppltasks.h:1249
_ContinuationTaskHandleBase * _M_next
Definition: ppltasks.h:1292
auto _FilterValidTaskType(_Ty _Param, int) -> decltype(_GetTaskType(_Param, _IsCallable(_Param, 0)))
#define _TRY_BEGIN
Definition: xstddef:26
#define _CATCH(x)
Definition: xstddef:27
bool _IsCanceled()
Definition: ppltasks.h:1662
task(const task &_Other)
Constructs a task object.
Definition: ppltasks.h:3039
This class describes an exception thrown by the PPL tasks layer in order to force the current task to...
Definition: pplinterface.h:163
return _csc
Definition: ppltasks.h:189
_OutIt transform(_InIt _First, _InIt _Last, _OutIt _Dest, _Fn1 _Func)
Definition: algorithm:967
auto _VoidIsTaskHelper(_Function _Func, int, int) -> decltype(_Func(std::declval< task< void >>()), std::true_type())
task< details::_Unit_type > _M_unitTask
Definition: ppltasks.h:4381
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: ppltasks.h:2340
void _SetTaskCreationCallstack(const details::_TaskCreationCallstack &_callstack)
Sets a field in the task impl to the return callstack for calls to the task constructors and the then...
Definition: ppltasks.h:4303
Definition: exception:254
Definition: concrt.h:4305
#define _CATCH_END
Definition: xstddef:29
_Unit_type _Type
Definition: ppltasks.h:211
::Concurrency::details::_TaskCollection_t _M_TaskCollection
Definition: ppltasks.h:2041
task_completion_event()
Constructs a task_completion_event object.
Definition: ppltasks.h:2347
bool _M_fHasValue
Definition: ppltasks.h:2294
_Task_ptr< _ReturnType >::_Type _M_pTask
Definition: ppltasks.h:1442
__declspec(noinline) bool set_exception(std
Propagates an exception to all tasks associated with this event.
Definition: ppltasks.h:2428
task< typename _TaskTypeTraits< typename _FunctionTypeTraits< _Function, _ReturnType >::_FuncRetType >::_TaskRetType > _TaskOfType
Definition: ppltasks.h:403
void _Init(details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3484
void _Resolve(bool _CaptureCurrent)
Definition: ppltasks.h:528
__declspec(noinline) explicit task(_Ty _Param)
Constructs a task object.
Definition: ppltasks.h:2954
cancellation_token _M_CancellationToken
Definition: ppltasks.h:1226
static task_continuation_context get_current_winrt_context()
Returns a task continuation context object that represents the current winrt thread context...
Definition: ppltasks.h:956
file_status status(const path &)
Definition: filesystem:3129
_Function _M_function
Definition: ppltasks.h:3453
_CancellationTokenState * _PTokenState
Definition: ppltasks.h:1245
Definition: ppltasks.h:620
void _SetImpl(typename details::_Task_ptr< _ReturnType >::_Type &&_Impl)
Set the implementation of the task to be the supplied implementation using a move instead of a copy...
Definition: ppltasks.h:3398
bool operator==(const task< void > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:4233
std::vector< typename _Task_ptr< _ResultType >::_Type > _TaskList
Definition: ppltasks.h:2267
void _Perform() const
Definition: ppltasks.h:3579
void _TaskInitNoFunctor(task_completion_event< _ReturnType > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:3789
_Internal_task_options & _get_internal_task_options(task_options &_Options)
Definition: ppltasks.h:1267
Represents the allowed options for creating a task
Definition: ppltasks.h:1060
task()
Constructs a task object.
Definition: ppltasks.h:3930
The Concurrency namespace provides classes and functions that provide access to the Concurrency Runti...
Definition: agents.h:43
Definition: ppltasks.h:198
Definition: ppltasks.h:3450
bool _M_isTaskBasedContinuation
Definition: ppltasks.h:1294
Definition: ppltasks.h:4435
bool _Cancel(bool _SynchronousCancel)
Definition: ppltasks.h:1597
The implementation of a first-class task. This structure contains the task group used to execute the ...
Definition: ppltasks.h:1277
void _TaskRetType
Definition: ppltasks.h:346
_TaskEventLogger(_Task_impl_base *_task)
Definition: ppltasks.h:1339
void _SetAsync(bool _Async=true)
Sets a property determining whether the task is apartment aware.
Definition: ppltasks.h:4295
cancellation_token get_cancellation_token() const
Returns the cancellation token
Definition: ppltasks.h:1190
_TaskEventLogger _M_taskEventLogger
Definition: ppltasks.h:2046
size_t _CaptureFrames
Definition: ppltasks.h:180
_ExceptionHolder(const std::exception_ptr &_E, const _TaskCreationCallstack &_stackTrace)
Definition: ppltasks.h:738
Definition: ppltasks.h:1457
Definition: ppltasks.h:329
std::function< void __cdecl(void)> _CallbackFunction
Definition: ppltasks.h:499
static const bool _Value
Definition: ppltasks.h:217
_CancellationTokenState * _M_pTokenState
Definition: ppltasks.h:2035
_TaskInliningMode_t _M_inliningMode
Definition: ppltasks.h:1297
integral_constant< bool, false > false_type
Definition: xtr1common:42
_In_ size_t _In_ int _Index
Definition: time.h:102
bool _IsApartmentAware()
Definition: ppltasks.h:1678
void _Cancel() const
Cancel the task_completion_event. Any task created using this event will be marked as canceled if it ...
Definition: ppltasks.h:2672
Definition: ppltasks.h:1460
scheduler_ptr scheduler() const
Returns the scheduler for this task
Definition: ppltasks.h:4209
_Task_impl_base * _M_task
Definition: ppltasks.h:1314
Definition: pplinterface.h:224
auto _LogWorkItemAndInvokeUserLambda(_Func &&_func, _Arg &&_value) const -> decltype(_func(std::forward< _Arg >(_value)))
Definition: ppltasks.h:3573
_CRTIMP2 void __thiscall _CallInContext(_CallbackFunction _Func, bool _IgnoreDisconnect) const
task_completion_event< details::_Unit_type > _M_unitEvent
Definition: ppltasks.h:2726
bool _IsHRCOMDisconnected(int __hr)
Definition: ppltasks.h:4449
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: ppltasks.h:2626
_Internal_task_options()
Definition: ppltasks.h:1048
unsigned char _Unit_type
Definition: ppltasks.h:192
virtual ~_InitialTaskHandle()
Definition: ppltasks.h:3460
__declspec(noinline) bool set_exception(_E _Except) const
Definition: ppltasks.h:2648
bool _CancelWithException(const std::exception_ptr &_Exception)
Definition: ppltasks.h:1609
bool is_done() const
Determines if the task is completed.
Definition: ppltasks.h:3289
_Iter_diff_t< _InIt > distance(_InIt _First, _InIt _Last)
Definition: xutility:1111
Definition: ppltasks.h:323
_TaskProcThunk * _M_pThunk
Definition: ppltasks.h:471
bool has_scheduler() const
Indicates whether a scheduler n was specified by the user
Definition: ppltasks.h:1206
_TaskCreationCallstack()
Definition: ppltasks.h:164
bool _IsTriggered() const
Tests whether current event has been either Set, or Canceled.
Definition: ppltasks.h:2500
void _DeregisterCancellation()
Definition: ppltasks.h:1632
#define _REPORT_PPLTASK_UNOBSERVED_EXCEPTION()
Definition: pplwin.h:125
const details::_Task_ptr< details::_Unit_type >::_Type & _ThenGetImpl() const
Definition: ppltasks.h:4266
void _ScheduleContinuationTask(_ContinuationTaskHandleBase *_PTaskHandle)
Definition: ppltasks.h:1775
Definition: pplinterface.h:226
Definition: ppltasks.h:215
static std::shared_ptr< details::_ExceptionHolder > _ToExceptionHolder(std::exception_ptr _ExceptionPtr, const details::_TaskCreationCallstack &_SetExceptionAddressHint)
Definition: ppltasks.h:2512
details::_Internal_task_options _M_InternalTaskOptions
Definition: ppltasks.h:1228
task_status _Wait()
Definition: ppltasks.h:1486
bool _StoreException(const std::shared_ptr< details::_ExceptionHolder > &_ExHolder) const
Method that stores an exception in the task completion event. This is used internally by when_any...
Definition: ppltasks.h:2691
void * _M_SingleFrame
Definition: ppltasks.h:161
void _SetImpl(details::_Task_ptr< details::_Unit_type >::_Type &&_Impl)
Set the implementation of the task to be the supplied implementation using a move instead of a copy...
Definition: ppltasks.h:4287
void _TaskInitMaybeFunctor(_Function &_Func, std::true_type)
Initializes a task using a callable object.
Definition: ppltasks.h:3828
_TaskInliningMode_t _InliningMode
Definition: ppltasks.h:1248
_CRTIMP2 void __thiscall _LogWorkItemCompleted()
#define _ASSERTE(expr)
Definition: crtdbg.h:707
task()
Constructs a task object.
Definition: ppltasks.h:2912
Definition: ppltasks.h:732
void _Continue(std::false_type, details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3619
virtual bool _CancelAndRunContinuations(bool _SynchronousCancel, bool _UserException, bool _PropagatedFromAncestor, const std::shared_ptr< _ExceptionHolder > &_ExceptionHolder_arg)
Requests cancellation on the task and schedules continuations if the task can be transitioned to a te...
Definition: ppltasks.h:2077
shared_ptr< _Ty > make_shared(_Types &&..._Args)
Definition: memory:1381
void _Init(details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3497
_In_ wctype_t _Type
Definition: corecrt_wctype.h:111
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3884
volatile _TaskInternalState _M_TaskState
Definition: ppltasks.h:2017
std::vector< char > _Result
Definition: ppltasks.h:655
_UnwrapTaskType< _Type >::_Type _TaskRetType
Definition: ppltasks.h:331
void _ClearStoredException() const
Internal method that observe and clear the exception stored in the task completion event...
Definition: ppltasks.h:2700
Definition: vccorlib.h:117
_TaskInliningMode
The enum defines inlining scheduling policy for ppltasks. Scheduling a chore or a functor with _TaskI...
Definition: pplinterface.h:221
virtual ~_Task_impl_base()
Definition: ppltasks.h:1477
auto _LogWorkItemAndInvokeUserLambda(_Func _func) const -> decltype(_func())
Definition: ppltasks.h:3463
union Concurrency::details::_ContextCallback::@100 _M_context
_TaskCreationCallstack _CreationStack
Definition: ppltasks.h:1247
constexpr pair< typename _Unrefwrap< _Ty1 >::type, typename _Unrefwrap< _Ty2 >::type > make_pair(_Ty1 &&_Val1, _Ty2 &&_Val2)
Definition: utility:340
_ResultHolder< _ResultType > _M_value
Definition: ppltasks.h:2292
return * this
Definition: variant:950
auto _ThenImpl(const _Function &_Func, details::_ThenImplOptions &_Options) const -> typename details::_ContinuationTypeTraits< _Function, _InternalReturnType >::_TaskOfType
The one and only implementation of then for void and non-void tasks.
Definition: ppltasks.h:3846
bool has_cancellation_token() const
Indicates whether a cancellation token was specified by the user
Definition: ppltasks.h:1182
#define bool
Definition: stdbool.h:15
task_continuation_context get_continuation_context() const
Returns the continuation context
Definition: ppltasks.h:1198
_ContinuationTaskHandleBase * _ContinuationList
Definition: ppltasks.h:2029
_Boolarray operator&&(const valarray< _Ty > &_Left, const _Ty &_Right)
Definition: valarray:656
bool operator!=(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent different internal tasks.
Definition: ppltasks.h:3350
_TaskList _M_tasks
Definition: ppltasks.h:2290
__declspec(deprecated("Concurrency::EnableTracing is a deprecated function.")) _CONCRTIMP HRESULT __cdecl EnableTracing()
Enables tracing in the Concurrency Runtime. This function is deprecated because ETW tracing is now on...
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:332
std::shared_ptr< _Task_impl< _ReturnType > > _Type
Definition: ppltasks.h:1282
#define _THROW_NCEE(x, y)
Definition: xstddef:51
auto _IsValidTaskCtor(_Ty _Param, int, int, int, int) -> decltype(_Param(), std::true_type())
atomic_long _M_exceptionObserved
Definition: ppltasks.h:767
struct _Meta_at_< _Meta_list< _Types...>, _Idx, enable_if_t<(_Idx< sizeof...(_Types))> >:decltype(_Meta_at_impl< _Meta_repeat_n_c< _Idx, void * >>::_Eval(_Type_as_pointer< _Types >()...)){};template< class _List, class _Ty > struct _Meta_find_index_{};template< class _List, class _Ty > using _Meta_find_index=typename _Meta_find_index_< _List, _Ty >::type;constexpr auto _Meta_npos=static_cast< size_t >(-1);constexpr size_t _Meta_find_index_i_(bool const *const _Ptr, const size_t _Count, const size_t _Idx=0){return(_Idx >=_Count?_Meta_npos:_Ptr[_Idx]?_Idx:_Meta_find_index_i_(_Ptr, _Count, _Idx+1));}template< class _Ty > struct _Meta_find_index_< _Meta_list<>, _Ty >:integral_constant< size_t, _Meta_npos >{};template< class..._Types, class _Ty > struct _Meta_find_index_< _Meta_list< _Types...>, _Ty >{static constexpr bool _Bools[]={is_same< _Types, _Ty >::value...};using type=integral_constant< size_t, _Meta_find_index_i_(_Bools, sizeof...(_Types))>;};template< class _List, class _Ty > struct _Meta_find_unique_index_{};template< class _List, class _Ty > using _Meta_find_unique_index=typename _Meta_find_unique_index_< _List, _Ty >::type;constexpr size_t _Meta_find_unique_index_i_2(bool const *const _Ptr, const size_t _Count, const size_t _First){return(_First!=_Meta_npos &&_Meta_find_index_i_(_Ptr, _Count, _First+1)==_Meta_npos?_First:_Meta_npos);}constexpr size_t _Meta_find_unique_index_i_(bool const *const _Ptr, const size_t _Count){return(_Meta_find_unique_index_i_2(_Ptr, _Count, _Meta_find_index_i_(_Ptr, _Count)));}template< class _Ty > struct _Meta_find_unique_index_< _Meta_list<>, _Ty >:integral_constant< size_t, _Meta_npos >{};template< class..._Types, class _Ty > struct _Meta_find_unique_index_< _Meta_list< _Types...>, _Ty >{using type=integral_constant< size_t, _Meta_find_unique_index_i_(_Meta_find_index_< _Meta_list< _Types...>, _Ty >::_Bools, sizeof...(_Types))>;};template< class > struct _Meta_as_list_{};template< class _Ty > using _Meta_as_list=typename _Meta_as_list_< _Ty >::type;template< template< class > class _Template, class..._Types > struct _Meta_as_list_< _Template< _Types...> >{using type=_Meta_list< _Types...>;};template< class _Ty, _Ty..._Idxs > struct _Meta_as_list_< integer_sequence< _Ty, _Idxs...> >{using type=_Meta_list< integral_constant< _Ty, _Idxs >...>;};template< class _List > struct _Meta_as_integer_sequence_{};template< class _List > using _Meta_as_integer_sequence=typename _Meta_as_integer_sequence_< _List >::type;template< class _Ty, _Ty..._Idxs > struct _Meta_as_integer_sequence_< _Meta_list< integral_constant< _Ty, _Idxs >...> >{using type=integer_sequence< _Ty, _Idxs...>;};template< class...> struct _Meta_concat_{};template< class..._Types > using _Meta_concat=typename _Meta_concat_< _Types...>::type;template<> struct _Meta_concat_< _Meta_list<> >{using type=_Meta_list<>;};template< class..._Items1 > struct _Meta_concat_< _Meta_list< _Items1...> >{using type=_Meta_list< _Items1...>;};template< class..._Items1, class..._Items2 > struct _Meta_concat_< _Meta_list< _Items1...>, _Meta_list< _Items2...> >{using type=_Meta_list< _Items1..., _Items2...>;};template< class..._Items1, class..._Items2, class..._Items3 > struct _Meta_concat_< _Meta_list< _Items1...>, _Meta_list< _Items2...>, _Meta_list< _Items3...> >{using type=_Meta_list< _Items1..., _Items2..., _Items3...>;};template< class..._Items1, class..._Items2, class..._Items3, class..._Rest > struct _Meta_concat_< _Meta_list< _Items1...>, _Meta_list< _Items2...>, _Meta_list< _Items3...>, _Rest...>{using type=_Meta_concat< _Meta_list< _Items1..., _Items2..., _Items3...>, _Rest...>;};template< class _ListOfLists > using _Meta_join=_Meta_apply< _Meta_quote< _Meta_concat >, _ListOfLists >;template< class > struct _Meta_cartesian_product_{};template< class _ListOfLists > using _Meta_cartesian_product=typename _Meta_cartesian_product_< _ListOfLists >::type;template<> struct _Meta_cartesian_product_< _Meta_list<> >{using type=_Meta_list<>;};template< class..._Items > struct _Meta_cartesian_product_< _Meta_list< _Meta_list< _Items...> > >{using type=_Meta_list< _Meta_list< _Items >...>;};template< class..._Items, class..._Lists > struct _Meta_cartesian_product_< _Meta_list< _Meta_list< _Items...>, _Lists...> >{using type=_Meta_join< _Meta_list< _Meta_transform< _Meta_bind_back< _Meta_quote< _Meta_push_front >, _Items >, _Meta_cartesian_product< _Meta_list< _Lists...> > >...> >;};template< class..._Types > class variant;template< class _Ty > struct variant_size;template< class _Ty > struct variant_size< const _Ty >:variant_size< _Ty >::type{};template< class _Ty > struct variant_size< volatile _Ty >:variant_size< _Ty >::type{};template< class _Ty > struct variant_size< const volatile _Ty >:variant_size< _Ty >::type{};template< class _Ty > constexpr size_t variant_size_v=variant_size< _Ty >::value;template< class..._Types > struct variant_size< variant< _Types...> >:integral_constant< size_t, sizeof...(_Types)>{};template< size_t _Idx, class _Ty > struct variant_alternative;template< size_t _Idx, class _Ty > using variant_alternative_t=typename variant_alternative< _Idx, _Ty >::type;template< size_t _Idx, class _Ty > struct variant_alternative< _Idx, const _Ty >{using type=add_const_t< variant_alternative_t< _Idx, _Ty > >;};template< size_t _Idx, class _Ty > struct variant_alternative< _Idx, volatile _Ty >{using type=add_volatile_t< variant_alternative_t< _Idx, _Ty > >;};template< size_t _Idx, class _Ty > struct variant_alternative< _Idx, const volatile _Ty >{using type=add_cv_t< variant_alternative_t< _Idx, _Ty > >;};template< size_t _Idx, class..._Types > struct variant_alternative< _Idx, variant< _Types...> >{using type=_Meta_at_c< _Meta_list< _Types...>, _Idx >;};constexpr auto variant_npos=_Meta_npos;class bad_variant_access:public exception{public:bad_variant_access() _NOEXCEPT=default;virtual const char *__CLR_OR_THIS_CALL what() const _NOEXCEPT override{return("bad variant access");}protected:virtual void _Doraise() const {_RAISE(*this);}};struct _Variant_uses_allocator_t{};template< class _Ty, class=void > struct _Variant_item{remove_cv_t< _Ty > _Elem;template< class..._Types >constexpr explicit _Variant_item(_Types &&..._Args):_Elem(_STD forward< _Types >(_Args)...){}template< class _Alloc, class..._Types, enable_if_t< uses_allocator< _Ty, _Alloc >::value &&is_constructible< _Ty, allocator_arg_t, const _Alloc &, _Types...>::value, int >=0 >constexpr _Variant_item(_Variant_uses_allocator_t, const _Alloc &_Al, _Types &&..._Args):_Elem(allocator_arg, _Al, _STD forward< _Types >(_Args)...){}template< class _Alloc, class..._Types, enable_if_t< uses_allocator< _Ty, _Alloc >::value &&!is_constructible< _Ty, allocator_arg_t, const _Alloc &, _Types...>::value, int >=0 >constexpr _Variant_item(_Variant_uses_allocator_t, const _Alloc &_Al, _Types &&..._Args):_Elem(_STD forward< _Types >(_Args)..., _Al){}template< class _Alloc, class..._Types, enable_if_t<!uses_allocator< _Ty, _Alloc >::value, int >=0 >constexpr _Variant_item(_Variant_uses_allocator_t, const _Alloc &, _Types &&..._Args):_Elem(_STD forward< _Types >(_Args)...){}_CONSTEXPR14 _Ty &get()&{return(_Elem);}constexpr const _Ty &get() const &{return(_Elem);}_CONSTEXPR14 _Ty &&get()&&{return(_STD move(_Elem));}constexpr const _Ty &&get() const &&{return(_STD move(_Elem));}};template< bool _TrivialDestruction, class..._Types > class _Variant_storage_{};template< class..._Types > using _Variant_storage=_Variant_storage_< conjunction< is_trivially_destructible< _Variant_item< _Types > >...>::value, _Types...>;template< class _First, class..._Rest > class _Variant_storage_< true, _First, _Rest...>{public:static constexpr size_t _Size=1+sizeof...(_Rest);union{_Variant_item< _First > _Head;_Variant_storage< _Rest...> _Tail;};_Variant_storage_() _NOEXCEPT{}template< class..._Types >constexpr explicit _Variant_storage_(integral_constant< size_t, 0 >, _Types &&..._Args):_Head(_STD forward< _Types >(_Args)...){}template< size_t _Idx, class..._Types >constexpr explicit _Variant_storage_(integral_constant< size_t, _Idx >, _Types &&..._Args) _NOEXCEPT_OP((is_nothrow_constructible< _Variant_storage< _Rest...>, integral_constant< size_t, _Idx-1 >, _Types...>::value)):_Tail(integral_constant< size_t, _Idx-1 >{}, _STD forward< _Types >(_Args)...){}_Variant_storage_(_Variant_storage_ &&)=default;_Variant_storage_(const _Variant_storage_ &)=default;_Variant_storage_ &operator=(_Variant_storage_ &&)=default;_Variant_storage_ &operator=(const _Variant_storage_ &)=default;};template< class _First, class..._Rest > class _Variant_storage_< false, _First, _Rest...>{public:static constexpr size_t _Size=1+sizeof...(_Rest);union{_Variant_item< _First > _Head;_Variant_storage< _Rest...> _Tail;};~_Variant_storage_() _NOEXCEPT{}_Variant_storage_() _NOEXCEPT{}template< class..._Types >constexpr explicit _Variant_storage_(integral_constant< size_t, 0 >, _Types &&..._Args):_Head(_STD forward< _Types >(_Args)...){}template< size_t _Idx, class..._Types >constexpr explicit _Variant_storage_(integral_constant< size_t, _Idx >, _Types &&..._Args) _NOEXCEPT_OP((is_nothrow_constructible< _Variant_storage< _Rest...>, integral_constant< size_t, _Idx-1 >, _Types...>::value)):_Tail(integral_constant< size_t, _Idx-1 >{}, _STD forward< _Types >(_Args)...){}_Variant_storage_(_Variant_storage_ &&)=default;_Variant_storage_(const _Variant_storage_ &)=default;_Variant_storage_ &operator=(_Variant_storage_ &&)=default;_Variant_storage_ &operator=(const _Variant_storage_ &)=default;};template< size_t _Idx, class _Storage, enable_if_t< _Idx==0, int >=0 > constexpr decltype(auto) _Variant_raw_get(_Storage &&_Obj){return(_STD forward< _Storage >(_Obj)._Head);}template< size_t _Idx, class _Storage, enable_if_t< _Idx!=0, int >=0 > constexpr decltype(auto) _Variant_raw_get(_Storage &&_Obj){return(_Variant_raw_get< _Idx-1 >(_STD forward< _Storage >(_Obj)._Tail));}template< class _Storage, class _Fn > using _Variant_visit_raw_t=decltype(_STD declval< _Fn >()(integral_constant< size_t, 0 >{}, _Variant_raw_get< 0 >(_STD declval< _Storage >())));template< class _Storage, class _Fn, size_t _Idx > constexpr _Variant_visit_raw_t< _Storage, _Fn > _Variant_visit_raw_dispatch(_Storage &&_Obj, _Fn &&_Func){return(_STD forward< _Fn >(_Func)(integral_constant< size_t, _Idx >{}, _Variant_raw_get< _Idx >(_STD forward< _Storage >(_Obj))));}template< class _Storage, class _Fn, class _Indices > struct _Variant_raw_dispatch_table_;template< class _Storage, class _Fn > using _Variant_raw_dispatch_table=_Variant_raw_dispatch_table_< _Storage, _Fn, make_index_sequence< remove_reference_t< _Storage >::_Size > >;template< class _Storage, class _Fn, size_t..._Idxs > struct _Variant_raw_dispatch_table_< _Storage, _Fn, index_sequence< _Idxs...> >{using _Dispatch_t=_Variant_visit_raw_t< _Storage, _Fn >(*)(_Storage &&, _Fn &&);static constexpr _Dispatch_t _Array[]={&_Variant_visit_raw_dispatch< _Storage, _Fn, _Idxs >...};};template< class _Storage, class _Fn, size_t..._Idxs > constexpr typename _Variant_raw_dispatch_table_< _Storage, _Fn, index_sequence< _Idxs...> >::_Dispatch_t_Variant_raw_dispatch_table_< _Storage, _Fn, index_sequence< _Idxs...> >::_Array[];template< class _Storage, class _Fn, size_t..._Idxs > _CONSTEXPR14 _Variant_visit_raw_t< _Storage, _Fn > _Variant_visit_raw1(const size_t _Idx, _Storage &&_Obj, _Fn &&_Func, index_sequence< _Idxs...>){if(_Idx >=sizeof...(_Idxs)){_THROW_NCEE(bad_variant_access, _EMPTY_ARGUMENT);}constexpr auto &_Array=_Variant_raw_dispatch_table< _Storage, _Fn >::_Array;return(_Array[_Idx](_STD forward< _Storage >(_Obj), _STD forward< _Fn >(_Func)));}template< class _Storage, class _Fn > _CONSTEXPR14 _Variant_visit_raw_t< _Storage, _Fn > _Variant_visit_raw(const size_t _Idx, _Storage &&_Obj, _Fn &&_Func){return(_Variant_visit_raw1(_Idx, _STD forward< _Storage >(_Obj), _STD forward< _Fn >(_Func), make_index_sequence< remove_reference_t< _Storage >::_Size >{}));}template< size_t _Count > using _Variant_index_t=conditional_t<(_Count< static_cast< size_t >((numeric_limits< signed char >::max)())), signed char, conditional_t<(_Count< static_cast< size_t >((numeric_limits< short >::max)())), short, int > >;template< class..._Types > class _Variant_base:private _Variant_storage< _Types...>{public:using _Index_t=_Variant_index_t< sizeof...(_Types)>;static constexpr auto _Invalid_index=static_cast< _Index_t >(-1);_Index_t _Which;using _Storage_t=_Variant_storage< _Types...>;_CONSTEXPR14 _Storage_t &_Storage()&_NOEXCEPT{return(*this);}constexpr const _Storage_t &_Storage() const &_NOEXCEPT{return(*this);}_CONSTEXPR14 _Storage_t &&_Storage()&&_NOEXCEPT{return(_STD move(*this));}constexpr const _Storage_t &&_Storage() const &&_NOEXCEPT{return(_STD move(*this));}_Variant_base():_Storage_t{}, _Which{_Invalid_index}{}template< size_t _Idx, class..._UTypes, enable_if_t< is_constructible< _Variant_item< _Meta_at_c< _Meta_list< _Types...>, _Idx > >, _UTypes...>::value, int >=0 >constexpr explicit _Variant_base(in_place_index_t< _Idx >, _UTypes &&..._Args):_Storage_t(integral_constant< size_t, _Idx >{}, _STD forward< _UTypes >(_Args)...), _Which{static_cast< _Index_t >(_Idx)}{}constexpr bool valueless_by_exception() const _NOEXCEPT{return(_Which< 0);}constexpr size_t index() const _NOEXCEPT{return(static_cast< size_t >(_Which));}void _Set_index(const size_t _Idx){_Which=static_cast< _Index_t >(_Idx);}void _Reset() _NOEXCEPT{if(!this->valueless_by_exception()){_Reset1(_Conjunction_t< is_trivially_destructible< _Variant_item< _Types >>...>{});this->_Set_index(variant_npos);}}private:void _Reset1(true_type) _NOEXCEPT{}void _Reset1(false_type) _NOEXCEPT{_Variant_visit_raw(index(), _Storage(), [](auto, auto &_Obj){_Destroy_in_place(_Obj);});}};template< bool _AllTriviallyDestructible, class..._Types > struct _Variant_destroy_layer_;template< class..._Types > using _Variant_destroy_layer=_Variant_destroy_layer_< conjunction< is_trivially_destructible< _Variant_item< _Types > >...>::value, _Types...>;template< class..._Types > struct _Variant_destroy_layer_< true, _Types...>:_Variant_base< _Types...>{using _Variant_base< _Types...>::_Variant_base;};template< class..._Types > struct _Variant_destroy_layer_< false, _Types...>:_Variant_base< _Types...>{using _Variant_base< _Types...>::_Variant_base;~_Variant_destroy_layer_() _NOEXCEPT{this->_Reset();}};template< class..._Types > struct _Variant_construct_visitor{_Variant_base< _Types...> &_Self;template< class _Idx, class _Ty >void operator()(_Idx, _Ty &&_Source) const {_Construct_in_place(_Variant_raw_get< _Idx::value >(_Self._Storage()), _STD forward< _Ty >(_Source).get());_Self._Set_index(_Idx::value);}};template< class..._Types > struct _Variant_move_assign_visitor{_Variant_base< _Types...> &_Self;template< class _Idx, class _Ty >void operator()(_Idx, _Ty &&_Source) const {_Variant_raw_get< _Idx::value >(_Self._Storage()).get()=_STD forward< _Ty >(_Source).get();}};template< class..._Types > struct _Variant_direct_copy_assign_visitor{_Variant_destroy_layer< _Types...> &_Self;template< class _Idx, class _Ty >void operator()(_Idx, const _Ty &_Source) const {_Variant_raw_get< _Idx::value >(_Self._Storage()).get()=_Source.get();}};template< class..._Types > struct _Variant_indirect_copy_assign_visitor{_Variant_destroy_layer< _Types...> &_Self;template< class _Idx, class _Ty >void operator()(_Idx, const _Ty &_Source) const {auto _Temporary=_Source;_Self._Reset();_Construct_in_place(_Variant_raw_get< _Idx::value >(_Self._Storage()), _STD move(_Temporary));_Self._Set_index(_Idx::value);}};template< bool _UseTrivialSMFs, class..._Types > struct _Variant_copymove_layer_;template< class..._Types > using _Variant_copymove_layer=_Variant_copymove_layer_< conjunction< is_trivially_copyable< _Variant_item< _Types > >..., negation< is_reference< _Types > >...>::value, _Types...>;template< class..._Types > struct _Variant_copymove_layer_< true, _Types...>:_Variant_destroy_layer< _Types...>{using _Variant_destroy_layer< _Types...>::_Variant_destroy_layer;};template< class..._Types > struct _Variant_copymove_layer_< false, _Types...>:_Variant_destroy_layer< _Types...>{using _Variant_destroy_layer< _Types...>::_Variant_destroy_layer;_Variant_copymove_layer_()=default;_Variant_copymove_layer_(const _Variant_copymove_layer_ &_That){if(!_That.valueless_by_exception()){_Variant_visit_raw(_That.index(), _That._Storage(), _Variant_construct_visitor< _Types...>{*this});}}_Variant_copymove_layer_(_Variant_copymove_layer_ &&_That) _NOEXCEPT_OP(conjunction< is_nothrow_move_constructible< _Types >...>::value){if(!_That.valueless_by_exception()){_Variant_visit_raw(_That.index(), _STD move(_That)._Storage(), _Variant_construct_visitor< _Types...>{*this});}}_Variant_copymove_layer_ &operator=(const _Variant_copymove_layer_ &_That){if(this->_Which==_That._Which){if(!this->valueless_by_exception()){_Variant_visit_raw(_That.index(), _That._Storage(), _Variant_direct_copy_assign_visitor< _Types...>{*this});}}else{if(_That.valueless_by_exception()){this-> _Reset()
Definition: variant:942
_Ty _GetTaskType(task_completion_event< _Ty >, std::false_type)
_GetTaskType functions will retrieve task type T in task[T](Arg), for given constructor argument Arg ...
static std::shared_ptr< details::_ExceptionHolder > _ToExceptionHolder(const std::shared_ptr< details::_ExceptionHolder > &_ExHolder, const details::_TaskCreationCallstack &)
Definition: ppltasks.h:2507
_TaskTypeTraits< _FuncRetType >::_AsyncKind _AsyncKind
Definition: ppltasks.h:428
Definition: ppltasks.h:203
bool _IsCreated()
Definition: ppltasks.h:1642
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: ppltasks.h:3899
task_status wait() const
Waits for this task to reach a terminal state. It is possible for wait to execute the task inline...
Definition: ppltasks.h:3243
The tasks queued to the task_group or structured_task_group object completed successfully.
Definition: pplinterface.h:115
bool _IsTriggered() const
Test whether current event has been either Set, or Canceled.
Definition: ppltasks.h:2708
bool operator!=(const task< void > &_Rhs) const
Determines whether two task objects represent different internal tasks.
Definition: ppltasks.h:4245
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *terminate_handler)()
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplinterface.h:121
_In_ size_t _Out_opt_ int _In_z_ unsigned char const * _Src
Definition: mbstring.h:1039
_TypeSelectorNoAsync _AsyncKind
Definition: ppltasks.h:436
Definition: pplcancellation_token.h:106
_ContextCallback(const _ContextCallback &_Src)
Definition: ppltasks.h:543
Definition: ppltasks.h:1280
void _ScheduleContinuation(_ContinuationTaskHandleBase *_PTaskHandle)
Schedule the actual continuation. This will either schedule the function on the continuation task's i...
Definition: ppltasks.h:1835
task_options(task_continuation_context _ContinuationContext)
Task option that specify a continuation context. This is valid only for continuations (then) ...
Definition: ppltasks.h:1092
Definition: ppltasks.h:194
std::mutex _M_ContinuationsCritSec
Definition: ppltasks.h:2031
Definition: ppltasks.h:1312
_Ty _ArgType
Definition: ppltasks.h:389
bool _CancelWithExceptionHolder(const std::shared_ptr< _ExceptionHolder > &_ExHolder, bool _PropagatedFromAncestor)
Definition: ppltasks.h:1603
_TaskInternalState
Definition: ppltasks.h:1454
bool _StoreException(_ExHolderType _ExHolder, const details::_TaskCreationCallstack &_SetExceptionAddressHint=details::_TaskCreationCallstack()) const
Internal method that stores an exception in the task completion event. This is used internally by whe...
Definition: ppltasks.h:2471
__declspec(noinline) auto then(const _Function &_Func) const -> typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_TaskOfType
Adds a continuation task to this task.
Definition: ppltasks.h:3129
details::_Task_completion_event_impl< _Ty >::_TaskList _TaskList
Definition: ppltasks.h:2521
std::exception_ptr _M_stdException
Definition: ppltasks.h:770
std::function< _Unit_type(_Type)> _MakeTToUnitFunc(const std::function< void(_Type)> &_Func)
Definition: ppltasks.h:2311
#define false
Definition: stdbool.h:16
void Set(const _Type &_type)
Definition: ppltasks.h:624
bool is_apartment_aware() const
Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such ...
Definition: ppltasks.h:3322
_ContextCallback(_ContextCallback &&_Src)
Definition: ppltasks.h:548
#define or
Definition: iso646.h:15
auto _GetUnwrappedReturnType(_Ty _Arg, int) -> decltype(_GetUnwrappedType(_Arg))
_TaskCollection_t::_TaskProcHandle_t _UnrealizedChore_t
Definition: ppltasks.h:1286
static _ContextCallback _CaptureCurrent()
Definition: ppltasks.h:503
size_t _M_captureMethod
Definition: ppltasks.h:612
static _ThenImplOptions _CreateOptions(const task_options &_Task_Options, const task_continuation_context &_ContinuationContext, const scheduler_ptr &impl_scheduler)
Definition: ppltasks.h:1251
_TypeSelectorAsyncTask _AsyncOperationKindSelector(task< _Ty >)
void _RegisterTask(details::_Task_ptr< details::_Unit_type >::_Type _TaskParam)
Register a task with this event. This function is called when a task is constructed using a task_comp...
Definition: ppltasks.h:2720
Definition: ppltasks.h:2259
exception_ptr make_exception_ptr(_Ex _Except) _NOEXCEPT
Definition: exception:378
_Task_impl_base(_CancellationTokenState *_PTokenState, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1464
bool _IsPendingCancel()
Definition: ppltasks.h:1652
task & operator=(task &&_Other)
Replaces the contents of one task object with another.
Definition: ppltasks.h:3099
The task_continuation_context class allows you to specify where you would like a continuation to be e...
Definition: ppltasks.h:916
task(task &&_Other)
Constructs a task object.
Definition: ppltasks.h:3066
void _SetImpl(const typename details::_Task_ptr< _ReturnType >::_Type &_Impl)
Set the implementation of the task to be the supplied implementation.
Definition: ppltasks.h:3389
Represents a pointer to a scheduler. This class exists to allow the the specification of a shared lif...
Definition: pplinterface.h:47
bool _M_hasPresetCreationCallstack
Definition: ppltasks.h:1040
#define _CATCH_ALL
Definition: xstddef:28
_TaskCreationCallstack _M_pTaskCreationCallstack
Definition: ppltasks.h:2044
virtual ~_ContinuationTaskHandle()
Definition: ppltasks.h:3570
void _SetAsync(bool _Async=true)
Sets a property determining whether the task is apartment aware.
Definition: ppltasks.h:3407
_CancellationTokenRegistration * _M_pRegistration
Definition: ppltasks.h:2038
void _ScheduleTask(_UnrealizedChore_t *_PTaskHandle, _TaskInliningMode_t _InliningMode)
Helper function to schedule the task on the Task Collection.
Definition: ppltasks.h:1707
_Task_generator_oversubscriber _Task_generator_oversubscriber_t
Definition: pplwin.h:268
void set_continuation_context(task_continuation_context _ContinuationContext)
Sets the given continuation context in the options
Definition: ppltasks.h:1174
bool _CancelInternal() const
Cancels the task_completion_event.
Definition: ppltasks.h:2526
task_options(const task_options &_TaskOptions)
Task option copy constructor
Definition: ppltasks.h:1153
_Task_impl(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:2065
bool operator==(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:3338
std::vector< bool > Get()
Definition: ppltasks.h:648
_Function _M_function
Definition: ppltasks.h:3553
auto _VoidReturnTypeHelper(_Function _Func, int, int) -> decltype(_Func(std::declval< task< void >>()))
bool _M_fUnwrappedTask
Definition: ppltasks.h:2022
void rethrow_exception(_In_ exception_ptr _Ptr)
Definition: exception:371
bool _IsDone()
Definition: ppltasks.h:2244
Definition: ppltasks.h:370
bool _M_fFromAsync
Definition: ppltasks.h:2020
virtual _Task_ptr_base _GetTaskImplBase() const =0
_T atomic_increment(std::atomic< _T > &_Target)
Definition: pplinterface.h:252
_Check_return_ _In_z_ wchar_t const _Inout_opt_ _Deref_prepost_opt_z_ wchar_t ** _Context
Definition: corecrt_wstring.h:228
void _RegisterTask(const typename details::_Task_ptr< _ResultType >::_Type &_TaskParam)
Register a task with this event. This function is called when a task is constructed using a task_comp...
Definition: ppltasks.h:2573
static bool _IsValid(_In_opt_ _CancellationTokenState *_PToken)
Definition: pplcancellation_token.h:337
task_options(scheduler_ptr _Scheduler)
Task option that specify a scheduler
Definition: ppltasks.h:1141
_CRTIMP2 void __thiscall _Capture()
static task_continuation_context use_synchronous_execution()
Returns a task continuation context object that represents the synchronous execution context...
Definition: ppltasks.h:1017
#define _EMPTY_ARGUMENT
Definition: xstddef:77
_Boolarray operator||(const valarray< _Ty > &_Left, const _Ty &_Right)
Definition: valarray:670
void * _M_pContextCallback
Definition: ppltasks.h:611
Definition: ppltasks.h:354
void _CreateImpl(details::_CancellationTokenState *_Ct, scheduler_ptr _Scheduler)
Create an underlying task implementation.
Definition: ppltasks.h:3358
_In_ _Value
Definition: corecrt_wstdlib.h:65
std::shared_ptr< _ExceptionHolder > _M_exceptionHolder
Definition: ppltasks.h:2293
task_options(std::shared_ptr< _SchedType > _Scheduler)
Task option that specify a scheduler with shared lifetime
Definition: ppltasks.h:1117
_FunctionTypeTraits< _Function, _ReturnType >::_FuncRetType _RetTypeT
Definition: ppltasks.h:406
#define _T(x)
Definition: tchar.h:2427
void _Cancel(const std::shared_ptr< details::_ExceptionHolder > &_ExHolder) const
Cancel the task_completion_event with the exception holder provided. Any task created using this even...
Definition: ppltasks.h:2681
scheduler_ptr _Scheduler
Definition: ppltasks.h:1246
Definition: ppltasks.h:2774
void _TaskInitWithFunctor(const _Function &_Func)
Initializes a task using a lambda, function pointer or function object.
Definition: ppltasks.h:3776
task_group_status
Describes the execution status of a task_group or structured_task_group object. A value of this type ...
Definition: pplinterface.h:102
__declspec(noinline) bool set_exception(std
Propagates an exception to all tasks associated with this event.
Definition: ppltasks.h:2661
bool _IsStarted()
Definition: ppltasks.h:1647
void _TaskInitMaybeFunctor(_Ty &_Param, std::false_type)
Initializes a task using a non-callable object.
Definition: ppltasks.h:4375
auto _ReturnTypeHelper(_Type _Obj, _Function _Func, int, int) -> decltype(_Func(std::declval< task< _Type >>()))
constexpr _Ty && forward(typename remove_reference< _Ty >::type &_Arg) _NOEXCEPT
Definition: type_traits:1332
void _ValidateTaskConstructorArgs(const _Ty &_Param)
Definition: ppltasks.h:2759
task< _Ty > _ArgType
Definition: ppltasks.h:396
#define _CAPTURE_CALLSTACK()
Helper macro to determine how many stack frames need to be saved. When any number less or equal to 1 ...
Definition: ppltasks.h:118
#define _CRTIMP2
Definition: crtdefs.h:36
for(;0< _Count;)
Definition: algorithm:1944
Definition: ppltasks.h:497
void _Continue(std::true_type, details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3686
_ReturnType result_type
The type of the result an object of this class produces.
Definition: ppltasks.h:2888
static _Type _Make(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1283
bool set(_ResultType _Result) const
Sets the task completion event.
Definition: ppltasks.h:2368
Definition: pplcancellation_token.h:221
task_continuation_context _M_continuationContext
Definition: ppltasks.h:1293
std::function< void()> _M_InternalCancellation
Definition: ppltasks.h:2255
_Task_completion_event_impl()
Definition: ppltasks.h:2269
std::shared_ptr< details::_Task_completion_event_impl< _ResultType > > _M_Impl
Definition: ppltasks.h:2608
void set_cancellation_token(cancellation_token _Token)
Sets the given token in the options
Definition: ppltasks.h:1165
void _ClearStoredException() const
Internal method that observe and clear the exception stored in the task completion event...
Definition: ppltasks.h:2487
void _SetImpl(const details::_Task_ptr< details::_Unit_type >::_Type &_Impl)
Set the implementation of the task to be the supplied implementation.
Definition: ppltasks.h:4279
static void __cdecl _Bridge(void *_PData)
Definition: ppltasks.h:451
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: ppltasks.h:86
__declspec(noinline) bool set_exception(_E _Except) const
Definition: ppltasks.h:2414
bool _M_fIsCanceled
Definition: ppltasks.h:2295
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Resize(const wchar_t *, uintmax_t)
scheduler_ptr scheduler() const
Returns the scheduler for this task
Definition: ppltasks.h:3305
_TaskEventLogger & _M_logger
Definition: ppltasks.h:1349
_ContextCallback & operator=(_ContextCallback &&_Src)
Definition: ppltasks.h:564
#define _ASSERT(expr)
Definition: crtdbg.h:703
Definition: pplinterface.h:194
add_rvalue_reference< _Ty >::type declval() _NOEXCEPT
_ResultHolder< _ReturnType > _M_Result
Definition: ppltasks.h:2254
_ImplType _GetImplValue() const
Definition: pplcancellation_token.h:748
integral_constant< bool, true > true_type
Definition: xtr1common:41
bool _Cancel() const
Internal method to cancel the task_completion_event. Any task created using this event will be marked...
Definition: ppltasks.h:2439
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1349
_Diff _Count
Definition: algorithm:1941
Definition: ppltasks.h:227
static void __declspec(noreturn) __cdecl _NoCallOnDefaultTask_ErrorImpl()
Helper function for throwing an error for task functions that cannot be called from a default constru...
Definition: ppltasks.h:145
static void _AsyncInit(const typename _Task_ptr< _ReturnType >::_Type &_OuterTask, const task< _InternalReturnType > &_UnwrappedTask)
Definition: ppltasks.h:1976
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler())
_Type Get()
Definition: ppltasks.h:629
exception_ptr current_exception() _NOEXCEPT
Definition: exception:366
bool _HasCapturedContext() const
Definition: ppltasks.h:574
Helper object used for LWT invocation.
Definition: ppltasks.h:444
task_continuation_context _M_ContinuationContext
Definition: ppltasks.h:1227
std::atomic< long > atomic_long
Atomics
Definition: pplinterface.h:234
The task handle type used to create a 'continuation task'.
Definition: ppltasks.h:3546
void _Continue(std::true_type, details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3704
Definition: xtr1common:87
task_options(cancellation_token _Token, task_continuation_context _ContinuationContext)
Task option that specify a cancellation token and a continuation context. This is valid only for cont...
Definition: ppltasks.h:1104
void _SetTaskCreationCallstack(const _TaskCreationCallstack &_Callstack)
Definition: ppltasks.h:1693
_TypeSelectorNoAsync _AsyncKind
Definition: ppltasks.h:347
_Ty _Type
Definition: ppltasks.h:229
auto _IsTaskHelper(_Type _Obj, _Function _Func, int, int) -> decltype(_Func(std::declval< task< _Type >>()), std::true_type())
bool _M_taskPostEventStarted
Definition: ppltasks.h:1316
const std::shared_ptr< _ExceptionHolder > & _GetExceptionHolder()
Definition: ppltasks.h:1672
Definition: ppltasks.h:1458
bool is_apartment_aware() const
Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such ...
Definition: ppltasks.h:4221
_Ty _GetUnwrappedType(task< _Ty >)
The following type traits are used for the create_task function.
void _RunTaskContinuations()
Definition: ppltasks.h:1901
task & operator=(const task &_Other)
Replaces the contents of one task object with another.
Definition: ppltasks.h:3079
static void _RunTask(TaskProc_t _Proc, void *_Parameter, _TaskInliningMode _InliningMode)
Definition: pplwin.h:235
_Unit_type _NormalizedTaskRetType
Definition: ppltasks.h:348
bool _M_HasCancellationToken
Definition: ppltasks.h:1229
bool _HasUserException()
Definition: ppltasks.h:2274
void result_type
The type of the result an object of this class produces.
Definition: ppltasks.h:3906
~_ContextCallback()
Definition: ppltasks.h:510
static task_continuation_context use_default()
Creates the default task continuation context.
Definition: ppltasks.h:937
The base implementation of a first-class task. This class contains all the non-type specific implemen...
Definition: ppltasks.h:1452
void _FinalizeAndRunContinuations(_ReturnType _Result)
Definition: ppltasks.h:2174
_TaskCreationCallstack _GetTaskCreationCallstack()
Definition: ppltasks.h:1688
bool operator!=(const _Concurrent_queue_iterator< _C, _Ty > &_I, const _Concurrent_queue_iterator< _C, _U > &_J)
Definition: concurrent_queue.h:324
void _CreateImpl(details::_CancellationTokenState *_Ct, scheduler_ptr _Scheduler)
Create an underlying task implementation.
Definition: ppltasks.h:4253
void _SyncCancelAndPropagateException() const
Definition: ppltasks.h:3474
task_options(scheduler_interface &_Scheduler)
Task option that specify a scheduler reference
Definition: ppltasks.h:1129
const details::_Task_ptr< details::_Unit_type >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:4261
auto _Then(const _Function &_Func, details::_CancellationTokenState *_PTokenState, details::_TaskInliningMode_t _InliningMode=details::_ForceInline) const -> typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_TaskOfType
An internal version of then that takes additional flags and always execute the continuation inline by...
Definition: ppltasks.h:3426
Definition: ppltasks.h:4444
~_Holder()
Definition: ppltasks.h:466
virtual ~_ContinuationTaskHandleBase()
Definition: ppltasks.h:1306
Definition: pplcancellation_token.h:176
Definition: ppltasks.h:426
_FwdIt const _Ty _Val
Definition: algorithm:1938
bool set() const
Sets the task completion event.
Definition: ppltasks.h:2642
virtual void invoke() const
Definition: ppltasks.h:1409
void _CallInContext(_CallbackFunction _Func) const
Definition: ppltasks.h:594
std::function< void()> _M_func
Definition: ppltasks.h:477
_Result
Definition: corecrt_wconio.h:362
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3371
Definition: ppltasks.h:200
Definition: ppltasks.h:387
task_status wait() const
Waits for this task to reach a terminal state. It is possible for wait to execute the task inline...
Definition: ppltasks.h:4170
_ContinuationTaskHandleBase()
Definition: ppltasks.h:1301
_ContextCallback & operator=(const _ContextCallback &_Src)
Definition: ppltasks.h:554
void _RegisterCancellation(std::weak_ptr< _Task_impl_base > _WeakPtr)
Definition: ppltasks.h:1616
virtual ~_Task_impl()
Definition: ppltasks.h:2070
_TaskProcThunk(const std::function< void()> &_Callback)
Definition: ppltasks.h:446
static cancellation_token _FromImpl(_ImplType _Impl)
Definition: pplcancellation_token.h:753
_ContinuationTaskHandle(const typename details::_Task_ptr< _ReturnType >::_Type &_AncestorImpl, const typename details::_Task_ptr< _NormalizedContinuationReturnType >::_Type &_ContinuationImpl, const _Function &_Func, const task_continuation_context &_Context, details::_TaskInliningMode_t _InliningMode)
Definition: ppltasks.h:3555
long __cdecl _InterlockedCompareExchange(long volatile *, long, long)
static void _ScheduleFuncWithAutoInline(const std::function< void()> &_Func, _TaskInliningMode_t _InliningMode)
Schedule a functor with automatic inlining. Note that this is "fire and forget" scheduling, which cannot be waited on or canceled after scheduling. This schedule method will perform automatic inlining base on .
Definition: ppltasks.h:492
Definition: ppltasks.h:197
bool _TransitionedToStarted()
Definition: ppltasks.h:2203
#define true
Definition: stdbool.h:17
std::function< _RetTypeT __cdecl(_ArgTypeT)> _StdFuncT
Definition: ppltasks.h:407
Definition: ppltasks.h:196
The _PPLTaskHandle is the strong-typed task handle base. All user task functions need to be wrapped i...
Definition: ppltasks.h:1397
task_group_status task_status
A type that represents the terminal state of a task. Valid values are completed and canceled...
Definition: ppltasks.h:84
bool is_done() const
Determines if the task is completed.
Definition: ppltasks.h:4198
scheduler_ptr get_scheduler() const
Returns the scheduler
Definition: ppltasks.h:1214
constexpr const _Ty &() _Right
Definition: algorithm:3723
_Type _Result
Definition: ppltasks.h:634
Definition: ppltasks.h:139
Definition: ppltasks.h:460
bool _Cancel(_ExHolderType _ExHolder, const details::_TaskCreationCallstack &_SetExceptionAddressHint=details::_TaskCreationCallstack()) const
Internal method to cancel the task_completion_event with the exception provided. Any task created usi...
Definition: ppltasks.h:2450
Definition: ppltasks.h:1459
void _SetAsync(bool _Async=true)
Definition: ppltasks.h:1683
void _TaskInitNoFunctor(task_completion_event< void > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:4338
void _TaskInitMaybeFunctor(_Ty &_Param, std::false_type)
Initializes a task using a non-callable object.
Definition: ppltasks.h:3837
The cancellation_token class represents the ability to determine whether some operation has been requ...
Definition: pplcancellation_token.h:616
Callstack container, which is used to capture and preserve callstacks in ppltasks. Members of this class is examined by vc debugger, thus there will be no public access methods. Please note that names of this class should be kept stable for debugger examining.
Definition: ppltasks.h:156
_ReturnType _GetResult()
Definition: ppltasks.h:2249
__declspec(noinline)~_ExceptionHolder()
Definition: ppltasks.h:743
_ContinuationArgTypeHelper< _ReturnType, typename details::_FunctionTypeTraits< _Function, _ReturnType >::_Takes_task >::_ArgType _ArgTypeT
Definition: ppltasks.h:405
Definition: ppltasks.h:195