28 #if defined (__cplusplus_winrt)
33 #define _DBG_ONLY(X) X
36 #endif // #ifdef _DEBUG
38 #ifndef _PPLTASK_ASYNC_LOGGING
39 #define _PPLTASK_ASYNC_LOGGING 1
40 #endif // #ifndef _PPLTASK_ASYNC_LOGGING
42 #if _PPLTASK_ASYNC_LOGGING
43 #pragma detect_mismatch("_PPLTASK_ASYNC_LOGGING", "1")
45 #pragma detect_mismatch("_PPLTASK_ASYNC_LOGGING", "0")
46 #endif // #if _PPLTASK_ASYNC_LOGGING
48 #pragma pack(push,_CRT_PACKING)
51 #pragma warning(disable: 28197)
52 #pragma warning(disable: 4100) // Unreferenced formal parameter - needed for document generation
53 #pragma warning(disable: 4127) // constant express in if condition - we use it for meta programming
56 #pragma push_macro("new")
85 template <
typename _Type>
class task;
89 #ifndef PPL_TASK_SAVE_FRAME_COUNT
91 #define PPL_TASK_SAVE_FRAME_COUNT 10
93 #define PPL_TASK_SAVE_FRAME_COUNT 1
98 #define _EXPAND_STR(x) #x
99 #pragma detect_mismatch("ppltask_saved_frame_numbers", _EXPAND_STR(PPL_TASK_SAVE_FRAME_COUNT))
111 #if PPL_TASK_SAVE_FRAME_COUNT > 1
112 #if defined(__cplusplus_winrt) && !defined(_DEBUG)
113 #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!")
115 #define _CAPTURE_CALLSTACK() ::Concurrency::details::_TaskCreationCallstack::_CaptureMultiFramesCallstack(_ReturnAddress(), PPL_TASK_SAVE_FRAME_COUNT)
117 #define _CAPTURE_CALLSTACK() ::Concurrency::details::_TaskCreationCallstack::_CaptureSingleFrameCallstack(_ReturnAddress())
144 static void __declspec(noreturn) __cdecl _NoCallOnDefaultTask_ErrorImpl()
165 _M_SingleFrame =
nullptr;
182 if (_CaptureFrames > 1)
201 template<
typename _Ty>
213 template<
typename _Ty>
225 template <
typename _Ty>
231 template <
typename _Ty>
237 template <
typename _Ty>
242 #if defined(__cplusplus_winrt)
243 template <
typename _Type>
249 template <
typename _Type>
250 struct _Unhat<_Type^>
255 value struct _NonUserType {
public:
int _Dummy; };
257 template <
typename _Type,
bool _IsValueTypeOrRefType = __is_val
id_winrt_type(_Type)>
258 struct _ValueTypeOrRefType
260 typedef _NonUserType
_Value;
263 template <
typename _Type>
264 struct _ValueTypeOrRefType<_Type,
true>
269 template <
typename _T1,
typename _T2>
270 _T2 _ProgressTypeSelector(Windows::Foundation::IAsyncOperationWithProgress<_T1,_T2>^);
272 template <
typename _T1>
273 _T1 _ProgressTypeSelector(Windows::Foundation::IAsyncActionWithProgress<_T1>^);
275 template <
typename _Type>
276 struct _GetProgressType
278 typedef decltype(_ProgressTypeSelector(details::declval<_Type>()))
_Value;
281 template <typename _Type>
287 template <
typename _Ty>
292 template <
typename _T1,
typename _T2>
295 template <
typename _Ty>
299 struct _TaskTypeTraits
301 typedef typename _UnwrapTaskType<_Type>::_Type _TaskRetType;
303 typedef typename _NormalizeVoidToUnitType<_TaskRetType>::_Type _NormalizedTaskRetType;
305 static const
bool _IsAsyncTask = _IsAsync;
306 static const
bool _IsUnwrappedTaskOrAsync = _IsUnwrappedAsyncSelector<_AsyncKind>::
_Value;
309 template<typename _Type>
310 struct _TaskTypeTraits<_Type,
true >
312 typedef decltype(((_Type)
nullptr)->GetResults()) _TaskRetType;
313 typedef _TaskRetType _NormalizedTaskRetType;
316 static const
bool _IsAsyncTask = true;
317 static const
bool _IsUnwrappedTaskOrAsync = _IsUnwrappedAsyncSelector<_AsyncKind>::_Value;
321 template <
typename _Type>
324 static const bool _Value =
false;
327 template <
typename _Type,
bool _IsAsync = false>
334 static const
bool _IsAsyncTask =
false;
349 static const bool _IsAsyncTask =
false;
350 static const bool _IsUnwrappedTaskOrAsync =
false;
356 template <
typename _Function,
typename _Type>
auto _ReturnTypeHelper(_Type _Obj, _Function _Func,
int, ...) -> decltype(_Func(_Obj));
363 template <
typename _Function>
auto _VoidReturnTypeHelper(_Function _Func,
int, ...) -> decltype(_Func());
368 template<
typename _Function,
typename _ExpectedParameterType>
371 typedef decltype(
_ReturnTypeHelper(details::declval<_ExpectedParameterType>(),details::declval<_Function>(), 0, 0)) _FuncRetType;
377 template<typename _Function>
384 #ifndef _PPLTASKS_NO_STDFUNC
385 template<
typename _Ty,
typename _IsTaskType>
388 static_assert(std::is_same<_IsTaskType, std::false_type>::value,
"_IsTaskType template parameter must be std::true_type or std::false_type");
392 template<
typename _Ty>
399 template<
typename _Function,
typename _ReturnType>
403 #ifndef _PPLTASKS_NO_STDFUNC
406 typedef std::function<_RetTypeT __cdecl(_ArgTypeT)>
_StdFuncT;
424 template <
typename _TaskType,
typename _FuncRetType>
432 template<
typename _Ty>
436 static const bool _IsAsyncTask =
false;
437 static const bool _IsUnwrappedTaskOrAsync =
false;
518 _M_context._M_captureMethod = _S_captureDeferred;
522 _M_context._M_pContextCallback =
nullptr;
529 if(_M_context._M_captureMethod == _S_captureDeferred)
531 _M_context._M_pContextCallback =
nullptr;
533 if (_CaptureCurrent && _IsCurrentOriginSTA())
549 _M_context._M_pContextCallback = _Src._M_context._M_pContextCallback;
550 _Src._M_context._M_pContextCallback =
nullptr;
568 _Src._M_context._M_pContextCallback =
nullptr;
575 _ASSERTE(_M_context._M_captureMethod != _S_captureDeferred);
576 return (_M_context._M_pContextCallback !=
nullptr);
591 _CRTIMP2 void __thiscall _CallInContext(_CallbackFunction _Func,
bool _IgnoreDisconnect)
const;
595 _CallInContext(_Func,
false);
601 _CRTIMP2 void __thiscall _Assign(
void *_PContextCallback);
604 _CRTIMP2 static bool __cdecl _IsCurrentOriginSTA();
606 _CRTIMP2 void __thiscall _Capture();
614 static const size_t _S_captureDeferred = 1;
618 template<
typename _Type>
623 void Set(
const _Type& _type)
641 void Set(
const std::vector<bool>& _type)
643 _Result.resize(_type.size());
644 std::transform(_type.begin(), _type.end(), _Result.begin(), [](
bool _Val) {
return static_cast<char>(
_Val); });
649 std::vector<bool> _Ret(_Result.size());
657 #if defined (__cplusplus_winrt)
659 template<
typename _Type>
662 void Set(_Type^
const & _type)
669 return _M_Result.
Get();
680 template<
typename _Type>
681 struct _ResultHolder<
std::
vector<_Type^>>
683 void Set(
const std::vector<_Type^>& _type)
687 for (
auto _PTask = _type.begin(); _PTask != _type.end(); ++_PTask)
689 _Result.emplace_back(*_PTask);
693 std::vector<_Type^> Get()
696 std::vector<_Type^> _Return;
697 _Return.reserve(_Result.size());
699 for (
auto _PTask = _Result.begin(); _PTask != _Result.end(); ++_PTask)
701 _Return.push_back(_PTask->Get());
707 std::vector< ::Platform::Agile<_Type^> > _Result;
710 template<
typename _Type>
711 struct _ResultHolder<
std::
pair<_Type^, void*> >
713 void Set(
const std::pair<_Type^, size_t>& _type)
718 std::pair<_Type^, size_t> Get()
723 std::pair< ::Platform::Agile<_Type^>,
size_t> _M_Result;
738 _M_exceptionObserved(0), _M_stdException(_E), _M_stackTrace(_stackTrace)
745 if (_M_exceptionObserved == 0)
756 if (_M_exceptionObserved == 0)
779 #if defined (__cplusplus_winrt)
780 template<
typename _AsyncOperationType,
typename _CompletionHandlerType,
typename _Result>
784 ref struct _AsyncInfoImpl
abstract : Windows::Foundation::IAsyncOperation<_Result>
790 Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ _M_CompletedHandler;
792 _AsyncInfoImpl( _AsyncOperationType _AsyncInfo ) : _M_asyncInfo(_AsyncInfo) {}
795 virtual void Cancel() { _M_asyncInfo.
Get()->Cancel(); }
796 virtual void Close() { _M_asyncInfo.
Get()->Close(); }
798 virtual property Windows::Foundation::HResult ErrorCode
800 Windows::Foundation::HResult
get()
802 return _M_asyncInfo.
Get()->ErrorCode;
806 virtual property UINT Id
810 return _M_asyncInfo.
Get()->Id;
814 virtual property Windows::Foundation::AsyncStatus Status
816 Windows::Foundation::AsyncStatus
get()
818 return _M_asyncInfo.
Get()->Status;
822 virtual _Result GetResults() {
throw std::runtime_error(
"derived class must implement"); }
824 virtual property Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ Completed
826 Windows::Foundation::AsyncOperationCompletedHandler<_Result>^
get()
828 return _M_CompletedHandler;
831 void set(Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ _Value)
833 _M_CompletedHandler =
_Value;
834 _M_asyncInfo.
Get()->Completed =
ref new _CompletionHandlerType([&](_AsyncOperationType, Windows::Foundation::AsyncStatus _Status) {
835 _M_CompletedHandler->Invoke(
this, _Status);
844 template<
typename _Result,
typename _Progress>
845 ref struct _IAsyncOperationWithProgressToAsyncOperationConverter
sealed :
846 _AsyncInfoImpl<Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^,
847 Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_Result,_Progress>,
851 _IAsyncOperationWithProgressToAsyncOperationConverter(Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^ _Operation) :
852 _AsyncInfoImpl<
Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^,
853 Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_Result,_Progress>,
854 _Result>(_Operation) {}
857 virtual _Result GetResults()
override {
return _M_asyncInfo.
Get()->GetResults(); }
863 ref struct _IAsyncActionToAsyncOperationConverter
sealed :
864 _AsyncInfoImpl<Windows::Foundation::IAsyncAction^,
865 Windows::Foundation::AsyncActionCompletedHandler,
869 _IAsyncActionToAsyncOperationConverter(Windows::Foundation::IAsyncAction^ _Operation) :
870 _AsyncInfoImpl<
Windows::Foundation::IAsyncAction^,
871 Windows::Foundation::AsyncActionCompletedHandler,
872 details::_Unit_type>(_Operation) {}
878 _M_asyncInfo.
Get()->GetResults();
886 template<
typename _Progress>
887 ref struct _IAsyncActionWithProgressToAsyncOperationConverter
sealed :
888 _AsyncInfoImpl<Windows::Foundation::IAsyncActionWithProgress<_Progress>^,
889 Windows::Foundation::AsyncActionWithProgressCompletedHandler<_Progress>,
893 _IAsyncActionWithProgressToAsyncOperationConverter(Windows::Foundation::IAsyncActionWithProgress<_Progress>^ _Action) :
894 _AsyncInfoImpl<
Windows::Foundation::IAsyncActionWithProgress<_Progress>^,
895 Windows::Foundation::AsyncActionWithProgressCompletedHandler<_Progress>,
896 details::_Unit_type>(_Action) {}
901 _M_asyncInfo.
Get()->GetResults();
962 #if defined (__cplusplus_winrt)
998 static task_continuation_context use_current()
1000 return get_current_winrt_context();
1026 return _M_RunInline;
1044 _M_hasPresetCreationCallstack =
true;
1045 _M_presetCreationCallstack = _callstack;
1049 _M_hasPresetCreationCallstack =
false;
1071 _M_HasCancellationToken(false),
1072 _M_HasScheduler(false)
1081 _M_CancellationToken(_Token),
1083 _M_HasCancellationToken(true),
1084 _M_HasScheduler(false)
1094 _M_ContinuationContext(_ContinuationContext),
1095 _M_HasCancellationToken(false),
1096 _M_HasScheduler(false)
1105 _M_CancellationToken(_Token),
1106 _M_ContinuationContext(_ContinuationContext),
1107 _M_HasCancellationToken(true),
1108 _M_HasScheduler(false)
1115 template<
typename _SchedType>
1117 : _M_Scheduler(
std::
move(_Scheduler)),
1120 _M_HasCancellationToken(false),
1121 _M_HasScheduler(true)
1129 : _M_Scheduler(&_Scheduler),
1132 _M_HasCancellationToken(false),
1133 _M_HasScheduler(true)
1141 : _M_Scheduler(
std::
move(_Scheduler)),
1144 _M_HasCancellationToken(false),
1145 _M_HasScheduler(true)
1153 : _M_Scheduler(_TaskOptions.get_scheduler()),
1154 _M_CancellationToken(_TaskOptions.get_cancellation_token()),
1155 _M_ContinuationContext(_TaskOptions.get_continuation_context()),
1156 _M_HasCancellationToken(_TaskOptions.has_cancellation_token()),
1157 _M_HasScheduler(_TaskOptions.has_scheduler())
1166 _M_CancellationToken = _Token;
1167 _M_HasCancellationToken =
true;
1175 _M_ContinuationContext = _ContinuationContext;
1183 return _M_HasCancellationToken;
1191 return _M_CancellationToken;
1199 return _M_ContinuationContext;
1207 return _M_HasScheduler;
1215 return _M_Scheduler;
1242 _CreationStack(_Creation_stack), _InliningMode(_Inlining_mode) {}
1259 auto _CreationStack = _Task_Options_Int._M_hasPresetCreationCallstack ?
1262 return _ThenImplOptions(_TokenState, &_ContinuationContext, _Scheduler, _CreationStack,_InliningMode);
1275 struct _Task_impl_base;
1278 template<
typename _ReturnType>
1281 typedef std::shared_ptr<_Task_impl<_ReturnType>>
_Type;
1298 virtual _Task_ptr_base _GetTaskImplBase()
const = 0;
1308 #if _PPLTASK_ASYNC_LOGGING
1318 _CRTIMP2 void __thiscall _LogScheduleTask(
bool _isContinuation);
1321 _CRTIMP2 void __thiscall _LogCancelTask();
1324 _CRTIMP2 void __thiscall _LogTaskCompleted();
1330 _CRTIMP2 void __thiscall _LogTaskExecutionCompleted();
1333 _CRTIMP2 void __thiscall _LogWorkItemStarted();
1336 _CRTIMP2 void __thiscall _LogWorkItemCompleted();
1340 _M_scheduled =
false;
1341 _M_taskPostEventStarted =
false;
1362 inline void _LogCancelTask(_Task_impl_base *) {}
1363 struct _TaskEventLogger
1365 void _LogScheduleTask(
bool) {}
1366 void _LogCancelTask() {}
1367 void _LogWorkItemStarted() {}
1368 void _LogWorkItemCompleted() {}
1369 void _LogTaskExecutionStarted() {}
1370 void _LogTaskExecutionCompleted() {}
1371 void _LogTaskCompleted() {}
1372 _TaskEventLogger(_Task_impl_base *) {}
1374 struct _TaskWorkItemRAIILogger
1376 _TaskWorkItemRAIILogger(_TaskEventLogger &) {}
1395 template<
typename _ReturnType,
typename _DerivedTaskHandle,
typename _BaseTaskHandle>
1405 _M_pTask->_M_taskEventLogger._LogTaskCompleted();
1412 _ASSERTE((
bool)_M_pTask);
1413 if (!_M_pTask->_TransitionedToStarted())
1415 static_cast<const _DerivedTaskHandle *
>(
this)->_SyncCancelAndPropagateException();
1419 _M_pTask->_M_taskEventLogger._LogTaskExecutionStarted();
1423 static_cast<const _DerivedTaskHandle *
>(
this)->_Perform();
1425 _M_pTask->_Cancel(
true);
1427 _M_pTask->_Cancel(
true);
1431 _M_pTask->_M_taskEventLogger._LogTaskExecutionCompleted();
1464 : _M_TaskState(_Created),
1465 _M_fFromAsync(false), _M_fUnwrappedTask(false),
1466 _M_pRegistration(nullptr), _M_Continuations(nullptr), _M_TaskCollection(_Scheduler_arg),
1467 _M_taskEventLogger(this)
1470 _M_pTokenState = _PTokenState;
1471 _ASSERTE(_M_pTokenState !=
nullptr);
1473 _M_pTokenState->_Reference();
1478 _ASSERTE(_M_pTokenState !=
nullptr);
1481 _M_pTokenState->_Release();
1487 bool _DoWait =
true;
1489 if (_IsNonBlockingThread())
1493 if (!_IsCompleted() && !_IsCanceled())
1516 _M_TaskCollection._Wait();
1532 _M_TaskCollection._RunAndWait();
1541 _ASSERTE(_IsCanceled());
1544 if(!_HasUserException())
1549 _M_exceptionHolder->_RethrowUserException();
1556 if (_M_fUnwrappedTask)
1558 _M_TaskCollection._Wait();
1563 if (_HasUserException())
1565 _M_exceptionHolder->_RethrowUserException();
1567 else if (_IsCanceled())
1571 _ASSERTE(_IsCompleted());
1594 virtual bool _CancelAndRunContinuations(
bool _SynchronousCancel,
bool _UserException,
bool _PropagatedFromAncestor,
const std::shared_ptr<_ExceptionHolder>& _ExHolder) = 0;
1599 return _CancelAndRunContinuations(_SynchronousCancel,
false,
false, _M_exceptionHolder);
1605 return _CancelAndRunContinuations(
true,
true, _PropagatedFromAncestor, _ExHolder);
1611 _ASSERTE(!_HasUserException());
1612 return _CancelAndRunContinuations(
true,
true,
false, std::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack()));
1619 auto _CancellationCallback = [_WeakPtr](){
1622 auto _task = _WeakPtr.lock();
1623 if (_task !=
nullptr)
1624 _task->_Cancel(
false);
1628 _M_pTokenState->_RegisterCallback(_M_pRegistration);
1633 if (_M_pRegistration !=
nullptr)
1635 _M_pTokenState->_DeregisterCallback(_M_pRegistration);
1636 _M_pRegistration->_Release();
1637 _M_pRegistration =
nullptr;
1643 return (_M_TaskState == _Created);
1648 return (_M_TaskState == _Started);
1653 return (_M_TaskState == _PendingCancel);
1668 return static_cast<bool>(_M_exceptionHolder);
1673 _ASSERTE(_HasUserException());
1674 return _M_exceptionHolder;
1679 return _M_fFromAsync;
1684 _M_fFromAsync = _Async;
1689 return _M_pTaskCreationCallstack;
1694 _M_pTaskCreationCallstack = _Callstack;
1709 _M_TaskCollection._ScheduleTask(_PTaskHandle, _InliningMode);
1715 _ASSERTE(_IsCanceled());
1727 if (!_HasUserException())
1747 if (_HasUserException())
1751 _ImplBase->_CancelWithExceptionHolder(_GetExceptionHolder(),
true);
1757 _ImplBase->_Cancel(
true);
1765 _ASSERTE(!_ImplBase->_IsCanceled());
1766 return _ImplBase->_ScheduleContinuationTask(_PTaskHandle);
1770 delete _PTaskHandle;
1777 _M_taskEventLogger._LogScheduleTask(
true);
1836 enum { _Nothing, _Schedule, _Cancel, _CancelWithException } _Do = _Nothing;
1841 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
1846 else if (_IsCanceled())
1848 if (_HasUserException())
1850 _Do = _CancelWithException;
1860 _PTaskHandle->
_M_next = _M_Continuations;
1861 _M_Continuations = _PTaskHandle;
1880 delete _PTaskHandle;
1883 case _CancelWithException:
1887 _PTaskHandle->
_GetTaskImplBase()->_CancelWithExceptionHolder(_GetExceptionHolder(),
true);
1889 delete _PTaskHandle;
1905 _M_Continuations =
nullptr;
1911 _RunContinuation(_Cur);
1916 _CRTIMP2 static bool __cdecl _IsNonBlockingThread();
1918 #if defined (__cplusplus_winrt)
1919 template<
typename _ReturnType,
typename>
1935 _AsyncOp->Completed =
ref new Windows::Foundation::AsyncOperationCompletedHandler<_ReturnType>(
1938 if (_Status == Windows::Foundation::AsyncStatus::Canceled)
1940 _OuterTask->_Cancel(
true);
1942 else if (_Status == Windows::Foundation::AsyncStatus::Error)
1944 _OuterTask->_CancelWithException(
1945 std::make_exception_ptr(::Platform::Exception::ReCreateException(static_cast<int>(_Operation->ErrorCode.Value))));
1949 _ASSERTE(_Status == Windows::Foundation::AsyncStatus::Completed);
1953 _OuterTask->_FinalizeAndRunContinuations(_Operation->GetResults());
1968 const_cast<_Task_ptr<_ReturnType>::_Type &
>(_OuterTask).reset();
1970 _OuterTask->_SetUnwrappedAsyncOp(_AsyncOp);
1974 template<
typename _ReturnType,
typename _InternalReturnType>
1977 _ASSERTE(_OuterTask->_M_fUnwrappedTask && !_OuterTask->_IsCanceled());
1988 if (_AncestorTask.
_GetImpl()->_IsCompleted())
1990 _OuterTask->_FinalizeAndRunContinuations(_AncestorTask.
_GetImpl()->_GetResult());
1994 _ASSERTE(_AncestorTask.
_GetImpl()->_IsCanceled());
1995 if (_AncestorTask.
_GetImpl()->_HasUserException())
1999 _OuterTask->_CancelWithExceptionHolder(_AncestorTask.
_GetImpl()->_GetExceptionHolder(),
false);
2003 _OuterTask->_Cancel(
true);
2012 return _M_TaskCollection._GetScheduler();
2061 template<
typename _ReturnType>
2073 _DeregisterCancellation();
2076 virtual bool _CancelAndRunContinuations(
bool _SynchronousCancel,
bool _UserException,
bool _PropagatedFromAncestor,
const std::shared_ptr<_ExceptionHolder> & _ExceptionHolder_arg)
2078 enum { _Nothing, _RunContinuations, _Cancel } _Do = _Nothing;
2080 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2083 _ASSERTE(_SynchronousCancel && !_IsCompleted());
2085 _ASSERTE(!_IsCanceled() || _PropagatedFromAncestor);
2088 _ASSERTE(!_HasUserException());
2098 _M_exceptionHolder = _ExceptionHolder_arg;
2105 if (_IsCompleted() || _IsCanceled() || (_IsPendingCancel() && !_SynchronousCancel))
2107 _ASSERTE(!_IsCompleted() || !_HasUserException());
2110 _ASSERTE(!_SynchronousCancel || !_HasUserException());
2113 if (_SynchronousCancel)
2120 _Do = _RunContinuations;
2124 _ASSERTE(!_UserException);
2135 _M_TaskState = _PendingCancel;
2137 _M_taskEventLogger._LogCancelTask();
2145 if (_M_InternalCancellation)
2148 _M_InternalCancellation();
2150 _M_TaskCollection._Cancel();
2153 case _RunContinuations:
2156 _M_TaskCollection._Complete();
2158 if (_M_Continuations)
2175 _M_Result.Set(_Result);
2182 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2186 _ASSERTE(!_HasUserException() && !_IsCompleted());
2195 _M_TaskCollection._Complete();
2196 _RunTaskContinuations();
2204 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2206 _ASSERT(!_IsCanceled());
2207 if (_IsPendingCancel())
2210 _ASSERTE(_IsCreated());
2211 _M_TaskState = _Started;
2215 #if defined (__cplusplus_winrt)
2218 bool _DoCancel =
false;
2220 ::std::lock_guard<std::mutex> _LockHolder(_M_ContinuationsCritSec);
2222 if (_IsPendingCancel())
2224 _ASSERTE(!_IsCanceled());
2227 else if (!_IsCanceled() && !_IsCompleted())
2229 _M_TaskState = _Started;
2230 _M_InternalCancellation = [=] {
2245 return _IsCompleted() || _IsCanceled();
2250 return _M_Result.Get();
2257 template<
typename _ResultType>
2266 typedef std::vector<typename _Task_ptr<_ResultType>::_Type>
_TaskList;
2269 _M_fHasValue(false), _M_fIsCanceled(false)
2275 return _M_exceptionHolder !=
nullptr;
2280 for(
auto _TaskIt = _M_tasks.begin(); _TaskIt != _M_tasks.end(); ++_TaskIt )
2282 _ASSERTE(!_M_fHasValue && !_M_fIsCanceled);
2284 (*_TaskIt)->_Cancel(
true);
2300 return [=]() -> _Unit_type { _Func();
return _Unit_type(); };
2303 template <
typename _Type>
2306 return [=](
_Unit_type) -> _Type {
return _Func(); };
2309 template <
typename _Type>
2312 return [=](_Type _Obj) -> _Unit_type { _Func(_Obj);
return _Unit_type(); };
2338 template<
typename _ResultType>
2347 : _M_Impl(
std::
make_shared<details::_Task_completion_event_impl<_ResultType>>())
2367 bool set(_ResultType _Result)
const
2376 bool _RunContinuations =
false;
2378 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2380 if (!_IsTriggered())
2382 _M_Impl->_M_value.Set(_Result);
2383 _M_Impl->_M_fHasValue =
true;
2385 _Tasks.swap(_M_Impl->_M_tasks);
2386 _RunContinuations =
true;
2390 if (_RunContinuations)
2392 for(
auto _TaskIt = _Tasks.begin(); _TaskIt != _Tasks.end(); ++_TaskIt )
2395 if ((*_TaskIt)->_IsPendingCancel())
2396 (*_TaskIt)->_Cancel(
true);
2402 (*_TaskIt)->_FinalizeAndRunContinuations(_M_Impl->_M_value.Get());
2412 template<
typename _E>
2414 bool set_exception(_E _Except) const
2441 return _CancelInternal();
2448 template<
typename _ExHolderType>
2452 if(_StoreException(_ExHolder, _SetExceptionAddressHint))
2454 _Canceled = _CancelInternal();
2455 _ASSERTE(_Canceled);
2469 template<
typename _ExHolderType>
2472 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2473 if (!_IsTriggered() && !_M_Impl->_HasUserException())
2477 _M_Impl->_M_exceptionHolder = _ToExceptionHolder(_ExHolder, _SetExceptionAddressHint);
2488 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2489 if (_M_Impl->_M_exceptionHolder)
2492 _M_Impl->_M_exceptionHolder.reset();
2501 return _M_Impl->_M_fHasValue || _M_Impl->_M_fIsCanceled;
2513 return std::make_shared<details::_ExceptionHolder>(_ExceptionPtr, _SetExceptionAddressHint);
2517 template <
typename _Ty>
friend class task;
2529 _ASSERTE(!_M_Impl->_M_fHasValue);
2530 if (_M_Impl->_M_fIsCanceled)
2536 bool _Cancel =
false;
2538 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2539 _ASSERTE(!_M_Impl->_M_fHasValue);
2540 if (!_M_Impl->_M_fIsCanceled)
2542 _M_Impl->_M_fIsCanceled =
true;
2543 _Tasks.swap(_M_Impl->_M_tasks);
2548 bool _UserException = _M_Impl->_HasUserException();
2552 for(
auto _TaskIt = _Tasks.begin(); _TaskIt != _Tasks.end(); ++_TaskIt )
2557 (*_TaskIt)->_CancelWithExceptionHolder(_M_Impl->_M_exceptionHolder,
true);
2561 (*_TaskIt)->_Cancel(
true);
2574 enum { _Nothing, _Trigger, _Cancel } _Action = _Nothing;
2576 ::std::lock_guard<std::mutex> _LockHolder(_M_Impl->_M_taskListCritSec);
2579 if (_M_Impl->_HasUserException())
2583 else if (_M_Impl->_M_fHasValue)
2589 _M_Impl->_M_tasks.push_back(_TaskParam);
2596 _TaskParam->_FinalizeAndRunContinuations(_M_Impl->_M_value.Get());
2599 _TaskParam->_CancelWithExceptionHolder(_M_Impl->_M_exceptionHolder,
true);
2607 std::shared_ptr<details::_Task_completion_event_impl<_ResultType>>
_M_Impl;
2646 template<
typename _E>
2648 bool set_exception(_E _Except) const
2673 _M_unitEvent._Cancel();
2680 void _Cancel(
const std::shared_ptr<details::_ExceptionHolder>& _ExHolder)
const
2682 _M_unitEvent._Cancel(_ExHolder);
2692 return _M_unitEvent._StoreException(_ExHolder);
2701 _M_unitEvent._ClearStoredException();
2709 return _M_unitEvent._IsTriggered();
2713 template <
typename _Ty>
friend class task;
2721 _M_unitEvent._RegisterTask(_TaskParam);
2737 template<
typename _ReturnType,
typename _Ty>
2740 #if defined (__cplusplus_winrt)
2742 template<
typename _ReturnType,
typename _Ty>
2747 template<
typename _ReturnType,
typename _Ty>
2750 template<
typename _ReturnType,
typename _Ty>
2754 template<
typename _ReturnType,
typename _Ty>
2757 template<
typename _ReturnType,
typename _Ty>
2760 static_assert(std::is_same<decltype(_IsValidTaskCtor<_ReturnType, _Ty>(_Param,0,0,0,0)),
std::true_type>::value,
2761 #
if defined (__cplusplus_winrt)
2762 "incorrect argument for task constructor; must be a callable object, an asynchronous operation or a task_completion_event"
2764 "incorrect argument for task constructor; must be either a callable object or a task_completion_event"
2767 #if defined (__cplusplus_winrt)
2769 "incorrect template argument for task; consider using the return type of the async operation");
2775 #if defined (__cplusplus_winrt)
2779 template<
typename _Ty>
2780 static auto _IsValidCreateAsync(_Ty _Param,
int,
int,
int,
int) -> decltype(_Param(),
std::true_type());
2783 template<
typename _Ty>
2787 template<
typename _Ty>
2791 template<
typename _Ty>
2795 template<
typename _Ty>
2803 template<
typename _InpType,
typename _OutType>
2807 static auto _Perform(std::function<_OutType(_InpType)> _Func) -> decltype(_Func)
2813 template<
typename _OutType>
2817 static auto _Perform(std::function<_OutType(
void)> _Func) -> decltype(details::_MakeUnitToTFunc<_OutType>(_Func))
2819 return details::_MakeUnitToTFunc<_OutType>(_Func);
2823 template<
typename _InType>
2827 static auto _Perform(std::function<
void(_InType)> _Func) -> decltype(details::_MakeTToUnitFunc<_InType>(_Func))
2829 return details::_MakeTToUnitFunc<_InType>(_Func);
2845 template<
typename _RetType>
2849 static auto _Perform(std::function<_RetType(
void)> _Func) -> decltype(_Func)
2879 template<
typename _ReturnType>
2952 template<
typename _Ty>
2954 explicit
task(_Ty _Param)
2957 details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
3000 template<
typename _Ty>
3004 details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
3006 _CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
3080 if (
this != &_Other)
3082 _M_Impl = _Other._M_Impl;
3100 if (
this != &_Other)
3127 template<
typename _Function>
3129 auto then(const _Function& _Func) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
3139 #ifndef _PPLTASKS_NO_STDFUNC
3142 return _ThenImpl<_ReturnType>(_Func, _Options);
3170 template<
typename _Function>
3172 auto then(const _Function& _Func,
task_options _TaskOptions) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
3178 auto _ContinuationContext = _TaskOptions.get_continuation_context();
3181 #ifndef _PPLTASKS_NO_STDFUNC
3184 return _ThenImpl<_ReturnType>(_Func, _Options);
3216 template<
typename _Function>
3221 task_options _TaskOptions(_CancellationToken, _ContinuationContext);
3226 #ifndef _PPLTASKS_NO_STDFUNC
3229 return _ThenImpl<_ReturnType>(_Func, _Options);
3246 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3249 return _M_Impl->_Wait();
3264 _ReturnType
get()
const
3268 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3276 return _M_Impl->_GetResult();
3292 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3295 return _M_Impl->_IsDone();
3308 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3311 return _M_Impl->_GetScheduler();
3325 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3327 return _M_Impl->_IsApartmentAware();
3339 return (_M_Impl == _Rhs._M_Impl);
3359 _ASSERTE(_Ct !=
nullptr);
3363 _M_Impl->_RegisterCancellation(_M_Impl);
3379 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3408 _GetImpl()->_SetAsync(_Async);
3416 _GetImpl()->_SetTaskCreationCallstack(_callstack);
3424 template<
typename _Function>
3429 auto _Scheduler = _GetImpl()->_GetScheduler();
3436 #ifndef _PPLTASKS_NO_STDFUNC
3439 return _ThenImpl<_ReturnType>(_Func, _Options);
3444 template <
typename _Ty>
friend class task;
3448 template <
typename _InternalReturnType,
typename _Function,
typename _TypeSelection>
3450 details::_PPLTaskHandle<_ReturnType, _InitialTaskHandle<_InternalReturnType, _Function, _TypeSelection>, details::_UnrealizedChore_t>
3454 : details::_PPLTaskHandle<_ReturnType,
_InitialTaskHandle<_InternalReturnType, _Function, _TypeSelection>, details::_UnrealizedChore_t>::_PPLTaskHandle(_TaskImpl)
3455 , _M_function(_func)
3461 template <
typename _Func>
3470 _Init(_TypeSelection());
3475 this->_M_pTask->_Cancel(
true);
3498 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask, _LogWorkItemAndInvokeUserLambda(_M_function));
3501 #if defined (__cplusplus_winrt)
3509 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
ref new details::_IAsyncActionToAsyncOperationConverter(_LogWorkItemAndInvokeUserLambda(_M_function)));
3521 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
3522 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_InternalReturnType,_ProgressType>(_LogWorkItemAndInvokeUserLambda(_M_function)));
3530 void _Init(details::_TypeSelectorAsyncActionWithProgress)
const
3534 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
3535 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(_LogWorkItemAndInvokeUserLambda(_M_function)));
3544 template <
typename _InternalReturnType,
typename _ContinuationReturnType,
typename _Function,
typename _IsTaskBased,
typename _TypeSelection>
3547 _ContinuationTaskHandle<_InternalReturnType, _ContinuationReturnType, _Function, _IsTaskBased, _TypeSelection>, details::_ContinuationTaskHandleBase>
3557 : details::_PPLTaskHandle<typename details::_NormalizeVoidToUnitType<_ContinuationReturnType>::_Type,
3558 _ContinuationTaskHandle<_InternalReturnType, _ContinuationReturnType, _Function, _IsTaskBased, _TypeSelection>, details::_ContinuationTaskHandleBase>
3559 ::_PPLTaskHandle(_ContinuationImpl)
3560 , _M_ancestorTaskImpl(_AncestorImpl)
3561 , _M_function(_Func)
3563 this->_M_isTaskBasedContinuation = _IsTaskBased::value;
3564 this->_M_continuationContext = _Context;
3565 this->_M_continuationContext.
_Resolve(_AncestorImpl->_IsApartmentAware());
3566 this->_M_inliningMode = _InliningMode;
3571 template <
typename _Func,
typename _Arg>
3575 return _func(std::forward<_Arg>(_value));
3580 _Continue(_IsTaskBased(), _TypeSelection());
3585 if (_M_ancestorTaskImpl->_HasUserException())
3589 this->_M_pTask->_CancelWithExceptionHolder(_M_ancestorTaskImpl->_GetExceptionHolder(),
true);
3595 this->_M_pTask->_Cancel(
true);
3606 this->_M_pTask->_FinalizeAndRunContinuations(
3622 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3628 #if defined (__cplusplus_winrt)
3638 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3640 ref new details::_IAsyncActionToAsyncOperationConverter(
3656 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3658 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_ContinuationReturnType, _ProgressType>(_OpWithProgress));
3666 void _Continue(
std::false_type, details::_TypeSelectorAsyncActionWithProgress)
const
3668 typedef details::_FunctionTypeTraits<_Function, _InternalReturnType>::_FuncRetType _FuncOutputType;
3670 auto _OpWithProgress = _LogWorkItemAndInvokeUserLambda(_Continuation_func_transformer<_InternalReturnType, _FuncOutputType>::_Perform(_M_function), _M_ancestorTaskImpl->_GetResult());
3673 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3675 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(_OpWithProgress));
3689 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3690 this->_M_pTask->_FinalizeAndRunContinuations(
3707 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3708 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3709 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask)));
3712 #if defined (__cplusplus_winrt)
3724 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3725 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3726 ref new details::_IAsyncActionToAsyncOperationConverter(_LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3740 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3744 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3745 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_ContinuationReturnType, _ProgressType>(
3746 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3756 void _Continue(
std::true_type, details::_TypeSelectorAsyncActionWithProgress)
const
3759 task<_InternalReturnType> _ResultTask;
3760 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3764 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3765 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(
3766 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3774 template<
typename _InternalReturnType,
typename _Function>
3779 _M_Impl->_M_fFromAsync = _Async_type_traits::_IsAsyncTask;
3780 _M_Impl->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3781 _M_Impl->_M_taskEventLogger._LogScheduleTask(
false);
3782 _M_Impl->_ScheduleTask(
new _InitialTaskHandle<_InternalReturnType, _Function, typename _Async_type_traits::_AsyncKind>(_GetImpl(), _Func),
details::_NoInline);
3793 #if defined (__cplusplus_winrt)
3799 _M_Impl->_M_fFromAsync =
true;
3802 details::_Task_impl_base::_AsyncInit<_ReturnType, _ReturnType>(_M_Impl, _AsyncOp);
3810 _TaskInitAsyncOp(_AsyncOp);
3816 template<
typename _Progress>
3826 template<
typename _Function>
3829 _TaskInitWithFunctor<_ReturnType, _Function>(_Func);
3835 template<
typename _Ty>
3838 _TaskInitNoFunctor(_Param);
3844 template<
typename _InternalReturnType,
typename _Function>
3850 typedef typename _Async_type_traits::_TaskRetType _TaskType;
3857 if (_Options._PTokenState ==
nullptr)
3859 if (_Function_type_traits::_Takes_task::value)
3865 _Options._PTokenState = _GetImpl()->_M_pTokenState;
3870 _ContinuationTask._CreateImpl(_Options._PTokenState, _Options._Scheduler);
3872 _ContinuationTask._GetImpl()->_M_fFromAsync = (_GetImpl()->_M_fFromAsync || _Async_type_traits::_IsAsyncTask);
3873 _ContinuationTask._GetImpl()->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3874 _ContinuationTask._SetTaskCreationCallstack(_Options._CreationStack);
3876 _GetImpl()->_ScheduleContinuation(
new _ContinuationTaskHandle<_InternalReturnType, _TaskType, _Function, typename _Function_type_traits::_Takes_task, typename _Async_type_traits::_AsyncKind>(
3877 _GetImpl(), _ContinuationTask._GetImpl(), _Func, *_Options._PContinuationContext, _Options._InliningMode));
3879 return _ContinuationTask;
3966 template<
typename _Ty>
3970 details::_ValidateTaskConstructorArgs<void,_Ty>(_Param);
3972 _M_unitTask.
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
4004 task(
const task& _Other): _M_unitTask(_Other._M_unitTask){}
4031 task(task&& _Other) : _M_unitTask(
std::
move(_Other._M_unitTask)) {}
4044 task& operator=(
const task& _Other)
4046 if (
this != &_Other)
4048 _M_unitTask = _Other._M_unitTask;
4064 task& operator=(task&& _Other)
4066 if (
this != &_Other)
4068 _M_unitTask =
std::move(_Other._M_unitTask);
4097 template<
typename _Function>
4099 auto then(const _Function& _Func, task_options _TaskOptions = task_options()) const -> typename details::_ContinuationTypeTraits<_Function,
void>::_TaskOfType
4105 auto _ContinuationContext = _TaskOptions.get_continuation_context();
4108 #ifndef _PPLTASKS_NO_STDFUNC
4111 return _M_unitTask._ThenImpl<
void>(_Func, _Options);
4143 template<
typename _Function>
4148 task_options _TaskOptions(_CancellationToken, _ContinuationContext);
4153 #ifndef _PPLTASKS_NO_STDFUNC
4156 return _M_unitTask._ThenImpl<
void>(_Func, _Options);
4171 return _M_unitTask.wait();
4199 return _M_unitTask.is_done();
4210 return _M_unitTask.scheduler();
4222 return _M_unitTask.is_apartment_aware();
4254 _M_unitTask._CreateImpl(_Ct, _Scheduler);
4262 return _M_unitTask._M_Impl;
4267 if (!_M_unitTask._M_Impl)
4269 details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
4272 return _M_unitTask._M_Impl;
4280 _M_unitTask._SetImpl(_Impl);
4296 _M_unitTask._SetAsync(_Async);
4304 _M_unitTask._SetTaskCreationCallstack(_callstack);
4310 template<
typename _Function>
4316 auto _Scheduler = _ThenGetImpl()->_GetScheduler();
4323 #ifndef _PPLTASKS_NO_STDFUNC
4326 return _M_unitTask._ThenImpl<
void>(_Func, _Options);
4331 template <
typename _Ty>
friend class task;
4342 #if defined (__cplusplus_winrt)
4343 void _TaskInitNoFunctor(Windows::Foundation::IAsyncAction^ _AsyncAction)
4348 _M_unitTask._TaskInitAsyncOp(
ref new details::_IAsyncActionToAsyncOperationConverter(_AsyncAction));
4354 template<
typename _P>
4355 void _TaskInitNoFunctor(Windows::Foundation::IAsyncActionWithProgress<_P>^ _AsyncActionWithProgress)
4357 _M_unitTask._TaskInitAsyncOp(
ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_P>(_AsyncActionWithProgress));
4364 template<
typename _Function>
4367 _M_unitTask._TaskInitWithFunctor<
void, _Function>(_Func);
4373 template<
typename _Ty>
4376 _TaskInitNoFunctor(_Param);
4389 #if defined (__cplusplus_winrt)
4391 template<
typename _Ty>
4396 template<
typename _Ty,
typename _Progress>
4397 _Ty
_GetUnwrappedType(Windows::Foundation::IAsyncOperationWithProgress<_Ty, _Progress>^);
4399 template<
typename _Progress>
4400 void _GetUnwrappedType(Windows::Foundation::IAsyncActionWithProgress<_Progress>^);
4404 template<
typename _Ty>
4408 template<
typename _Ty>
4411 template<
typename _Ty>
4421 template<
typename _Ty>
4425 template<
typename _Ty>
4429 template<
typename _Ty>
4436 template<
typename _Ty>
4439 template<
typename _Ty>
4442 template<
typename _Ty>
4450 return __hr == 0x800706BA
4451 || __hr == 0x80010108
4452 || __hr == 0x89020001;
4484 template<
typename _Ty>
4486 auto create_task(_Ty _Param, task_options _TaskOptions = task_options()) -> task<typename details::_TaskTypeFromParam<_Ty>::_Type>
4488 static_assert(!std::is_same<
typename details::_TaskTypeFromParam<_Ty>::_Type,details::_BadArgType>::value,
4489 #
if defined (__cplusplus_winrt)
4490 "incorrect argument for create_task; can be a callable object, an asynchronous operation, or a task_completion_event"
4492 "incorrect argument for create_task; must be either a callable object or a task_completion_event"
4496 task<typename details::_TaskTypeFromParam<_Ty>::_Type> _CreatedTask(_Param, _TaskOptions);
4497 return _CreatedTask;
4531 template<
typename _ReturnType>
4533 task<_ReturnType> create_task(const task<_ReturnType>& _Task)
4535 task<_ReturnType> _CreatedTask(_Task);
4536 return _CreatedTask;
4539 #if defined (__cplusplus_winrt)
4542 template<
typename _Ty>
4543 task<_Ty> _To_task_helper(Windows::Foundation::IAsyncOperation<_Ty>^ _Op)
4545 return task<_Ty>(_Op);
4548 template<
typename _Ty,
typename _Progress>
4549 task<_Ty> _To_task_helper(Windows::Foundation::IAsyncOperationWithProgress<_Ty, _Progress>^ _Op)
4551 return task<_Ty>(_Op);
4554 inline task<void> _To_task_helper(Windows::Foundation::IAsyncAction^ _Op)
4556 return task<void>(_Op);
4559 template<
typename _Progress>
4560 task<void> _To_task_helper(Windows::Foundation::IAsyncActionWithProgress<_Progress>^ _Op)
4562 return task<void>(_Op);
4565 template<
typename _ProgressType>
4566 class _ProgressDispatcherBase
4570 virtual ~_ProgressDispatcherBase()
4574 virtual void _Report(
const _ProgressType&
_Val) = 0;
4577 template<
typename _ProgressType,
typename _ClassPtrType>
4578 class _ProgressDispatcher :
public _ProgressDispatcherBase<_ProgressType>
4582 virtual ~_ProgressDispatcher()
4586 _ProgressDispatcher(_ClassPtrType _Ptr) : _M_ptr(_Ptr)
4590 virtual void _Report(
const _ProgressType&
_Val)
4592 _M_ptr->_FireProgress(_Val);
4597 _ClassPtrType _M_ptr;
4613 template<
typename _ProgressType>
4614 class progress_reporter
4616 typedef std::shared_ptr<details::_ProgressDispatcherBase<_ProgressType>> _PtrType;
4627 void report(
const _ProgressType&
_Val)
const
4629 _M_dispatcher->_Report(_Val);
4632 template<
typename _ClassPtrType>
4633 static progress_reporter _CreateReporter(_ClassPtrType _Ptr)
4635 progress_reporter _Reporter;
4636 details::_ProgressDispatcherBase<_ProgressType> *_PDispatcher =
new details::_ProgressDispatcher<_ProgressType, _ClassPtrType>(_Ptr);
4637 _Reporter._M_dispatcher = _PtrType(_PDispatcher);
4640 progress_reporter() {}
4643 progress_reporter(details::_ProgressReporterCtorArgType);
4646 _PtrType _M_dispatcher;
4654 enum _AsyncStatusInternal
4659 _AsyncCompleted = 1,
4663 _AsyncCancelPending,
4672 enum _AsyncResultType
4674 SingleResult = 0x0001,
4675 MultipleResults = 0x0002
4682 struct _ZeroArgumentFunctor { };
4683 struct _OneArgumentFunctor { };
4684 struct _TwoArgumentFunctor { };
4693 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4694 _Arg1 _Arg1ClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4697 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4698 _Arg2 _Arg2ClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4700 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4701 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4703 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4704 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4710 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4711 _Arg1 _Arg1ClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4714 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4715 void _Arg2ClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4717 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4718 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4720 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4721 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)(_Arg1)
const);
4727 template<
typename _Class,
typename _ReturnType>
4728 void _Arg1ClassHelperThunk(_ReturnType (_Class::*)()
const);
4731 template<
typename _Class,
typename _ReturnType>
4732 void _Arg2ClassHelperThunk(_ReturnType (_Class::*)()
const);
4735 template<
typename _Class,
typename _ReturnType>
4736 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)()
const);
4738 template<
typename _Class,
typename _ReturnType>
4739 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)()
const);
4747 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4748 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4750 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4751 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4753 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4754 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4756 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4757 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4759 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4760 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4762 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4763 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4765 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4766 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4768 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4769 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4771 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4772 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4774 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4775 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4777 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4778 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4780 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4781 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4786 template<
typename _ReturnType,
typename _Arg1>
4787 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4789 template<
typename _ReturnType,
typename _Arg1>
4790 void _Arg2PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4792 template<
typename _ReturnType,
typename _Arg1>
4793 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4795 template<
typename _ReturnType,
typename _Arg1>
4796 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)(_Arg1));
4798 template<
typename _ReturnType,
typename _Arg1>
4799 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4801 template<
typename _ReturnType,
typename _Arg1>
4802 void _Arg2PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4804 template<
typename _ReturnType,
typename _Arg1>
4805 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4807 template<
typename _ReturnType,
typename _Arg1>
4808 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)(_Arg1));
4810 template<
typename _ReturnType,
typename _Arg1>
4811 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4813 template<
typename _ReturnType,
typename _Arg1>
4814 void _Arg2PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4816 template<
typename _ReturnType,
typename _Arg1>
4817 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4819 template<
typename _ReturnType,
typename _Arg1>
4820 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)(_Arg1));
4825 template<
typename _ReturnType>
4826 void _Arg1PFNHelperThunk(_ReturnType(__cdecl *)());
4828 template<
typename _ReturnType>
4829 void _Arg2PFNHelperThunk(_ReturnType(__cdecl *)());
4831 template<
typename _ReturnType>
4832 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)());
4834 template<
typename _ReturnType>
4835 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)());
4837 template<
typename _ReturnType>
4838 void _Arg1PFNHelperThunk(_ReturnType(__stdcall *)());
4840 template<
typename _ReturnType>
4841 void _Arg2PFNHelperThunk(_ReturnType(__stdcall *)());
4843 template<
typename _ReturnType>
4844 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)());
4846 template<
typename _ReturnType>
4847 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)());
4849 template<
typename _ReturnType>
4850 void _Arg1PFNHelperThunk(_ReturnType(__fastcall *)());
4852 template<
typename _ReturnType>
4853 void _Arg2PFNHelperThunk(_ReturnType(__fastcall *)());
4855 template<
typename _ReturnType>
4856 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)());
4858 template<
typename _ReturnType>
4859 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)());
4861 template<
typename _Ty>
4862 struct _FunctorArguments
4864 static const size_t _Count = 0;
4868 struct _FunctorArguments<_OneArgumentFunctor>
4870 static const size_t _Count = 1;
4874 struct _FunctorArguments<_TwoArgumentFunctor>
4876 static const size_t _Count = 2;
4879 template<
typename _Ty>
4880 struct _FunctorTypeTraits
4882 typedef decltype(_ArgumentCountHelper(&(_Ty::operator()))) _ArgumentCountType;
4883 static const
size_t _ArgumentCount = _FunctorArguments<_ArgumentCountType>::
_Count;
4885 typedef decltype(_ReturnTypeClassHelperThunk(&(_Ty::operator()))) _ReturnType;
4886 typedef decltype(_Arg1ClassHelperThunk(&(_Ty::operator()))) _Argument1Type;
4887 typedef decltype(_Arg2ClassHelperThunk(&(_Ty::operator()))) _Argument2Type;
4890 template<typename _Ty>
4891 struct _FunctorTypeTraits<_Ty *>
4893 typedef decltype(_ArgumentCountHelper(details::declval<_Ty*>())) _ArgumentCountType;
4894 static const
size_t _ArgumentCount = _FunctorArguments<_ArgumentCountType>::_Count;
4896 typedef decltype(_ReturnTypePFNHelperThunk(details::
declval<_Ty*>())) _ReturnType;
4897 typedef decltype(_Arg1PFNHelperThunk(details::
declval<_Ty*>())) _Argument1Type;
4898 typedef decltype(_Arg2PFNHelperThunk(details::
declval<_Ty*>())) _Argument2Type;
4901 template<typename _Ty>
4902 struct _ProgressTypeTraits
4904 static const bool _TakesProgress =
false;
4905 typedef void _ProgressType;
4908 template<
typename _Ty>
4909 struct _ProgressTypeTraits<progress_reporter<_Ty>>
4911 static const bool _TakesProgress =
true;
4912 typedef typename _Ty _ProgressType;
4916 template<typename _Ty, size_t _Count = _FunctorTypeTraits<_Ty>::_ArgumentCount>
4917 struct _CAFunctorOptions
4919 static const bool _TakesProgress =
false;
4920 static const bool _TakesToken =
false;
4921 typedef void _ProgressType;
4924 template<
typename _Ty>
4925 struct _CAFunctorOptions<_Ty, 1>
4929 typedef typename _FunctorTypeTraits<_Ty>::_Argument1Type _Argument1Type;
4933 static const bool _TakesProgress = _ProgressTypeTraits<_Argument1Type>::_TakesProgress;
4934 static const bool _TakesToken = !_TakesProgress;
4935 typedef typename _ProgressTypeTraits<_Argument1Type>::_ProgressType _ProgressType;
4938 template<
typename _Ty>
4939 struct _CAFunctorOptions<_Ty, 2>
4943 typedef typename _FunctorTypeTraits<_Ty>::_Argument1Type _Argument1Type;
4947 static const bool _TakesProgress =
true;
4948 static const bool _TakesToken =
true;
4949 typedef typename _ProgressTypeTraits<_Argument1Type>::_ProgressType _ProgressType;
4963 template<
typename _AsyncSelector,
typename _ReturnType>
4964 struct _SelectorTaskGenerator
4966 template<
typename _Function>
4967 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4969 task_options _taskOptinos(_Cts.get_token());
4971 return task<_ReturnType>(_Func(), _taskOptinos);
4974 template<
typename _Function>
4975 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4977 task_options _taskOptinos(_Cts.get_token());
4979 return task<_ReturnType>(_Func(_Cts.get_token()), _taskOptinos);
4982 template<
typename _Function,
typename _ProgressObject>
4983 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4985 task_options _taskOptinos(_Cts.get_token());
4987 return task<_ReturnType>(_Func(_Progress), _taskOptinos);
4990 template<
typename _Function,
typename _ProgressObject>
4991 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
4993 task_options _taskOptinos(_Cts.get_token());
4995 return task<_ReturnType>(_Func(_Progress, _Cts.get_token()), _taskOptinos);
4999 template<
typename _AsyncSelector>
5000 struct _SelectorTaskGenerator<_AsyncSelector, void>
5002 template<
typename _Function>
5003 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5005 task_options _taskOptinos(_Cts.get_token());
5007 return task<void>(_Func(), _taskOptinos);
5010 template<
typename _Function>
5011 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5013 task_options _taskOptinos(_Cts.get_token());
5015 return task<void>(_Func(_Cts.get_token()), _taskOptinos);
5018 template<
typename _Function,
typename _ProgressObject>
5019 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5021 task_options _taskOptinos(_Cts.get_token());
5023 return task<void>(_Func(_Progress), _taskOptinos);
5026 template<
typename _Function,
typename _ProgressObject>
5027 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5029 task_options _taskOptinos(_Cts.get_token());
5031 return task<void>(_Func(_Progress, _Cts.get_token()), _taskOptinos);
5038 template<
typename _ReturnType>
5039 struct _SelectorTaskGenerator<_TypeSelectorNoAsync, _ReturnType>
5042 #pragma warning(push)
5043 #pragma warning(disable: 4702)
5044 template<
typename _Function>
5045 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5047 task_options _taskOptinos(_Cts.get_token());
5049 return task<_ReturnType>( [=]() -> _ReturnType {
5055 #pragma warning(pop)
5057 template<
typename _Function>
5058 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5060 task_options _taskOptinos(_Cts.get_token());
5062 return task<_ReturnType>( [=]() -> _ReturnType {
5065 return _Func(_Cts.get_token());
5069 template<
typename _Function,
typename _ProgressObject>
5070 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5072 task_options _taskOptinos(_Cts.get_token());
5074 return task<_ReturnType>( [=]() -> _ReturnType {
5077 return _Func(_Progress);
5081 template<
typename _Function,
typename _ProgressObject>
5082 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5084 task_options _taskOptinos(_Cts.get_token());
5086 return task<_ReturnType>( [=]() -> _ReturnType {
5089 return _Func(_Progress, _Cts.get_token());
5095 struct _SelectorTaskGenerator<_TypeSelectorNoAsync, void>
5097 template<
typename _Function>
5098 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5100 task_options _taskOptinos(_Cts.get_token());
5102 return task<void>( [=]() {
5109 template<
typename _Function>
5110 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5112 task_options _taskOptinos(_Cts.get_token());
5114 return task<void>( [=]() {
5117 _Func(_Cts.get_token());
5121 template<
typename _Function,
typename _ProgressObject>
5122 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5124 task_options _taskOptinos(_Cts.get_token());
5126 return task<void>( [=]() {
5133 template<
typename _Function,
typename _ProgressObject>
5134 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5136 task_options _taskOptinos(_Cts.get_token());
5138 return task<void>( [=]() {
5141 _Func(_Progress, _Cts.get_token());
5149 template<
typename _ReturnType>
5150 struct _SelectorTaskGenerator<_TypeSelectorAsyncTask, _ReturnType>
5152 template<
typename _Function>
5153 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5158 template<
typename _Function>
5159 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5161 return _Func(_Cts.get_token());
5164 template<
typename _Function,
typename _ProgressObject>
5165 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5167 return _Func(_Progress);
5170 template<
typename _Function,
typename _ProgressObject>
5171 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5173 return _Func(_Progress, _Cts.get_token());
5178 struct _SelectorTaskGenerator<_TypeSelectorAsyncTask, void>
5180 template<
typename _Function>
5181 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5186 template<
typename _Function>
5187 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5189 return _Func(_Cts.get_token());
5192 template<
typename _Function,
typename _ProgressObject>
5193 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5195 return _Func(_Progress);
5198 template<
typename _Function,
typename _ProgressObject>
5199 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5201 return _Func(_Progress, _Cts.get_token());
5205 template<
typename _Generator,
bool _TakesToken,
bool TakesProgress>
5206 struct _TaskGenerator
5210 template<
typename _Generator>
5211 struct _TaskGenerator<_Generator, false, false>
5213 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5214 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5215 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5217 #ifndef _PPLTASKS_NO_STDFUNC
5218 typedef decltype(_Func()) _ReturnType;
5219 typedef
std::
function<_ReturnType __cdecl()> _StdFunction;
5220 return _Generator::_GenerateTask_0(_StdFunction(_Func), _Cts, _callstack);
5222 return _Generator::_GenerateTask_0(_Func, _Cts, _callstack);
5227 template<
typename _Generator>
5228 struct _TaskGenerator<_Generator, true, false>
5230 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5231 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5232 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5234 #ifndef _PPLTASKS_NO_STDFUNC
5235 typedef decltype(_Func(details::declval<cancellation_token>())) _ReturnType;
5236 return _Generator::_GenerateTask_1C(
std::
function<_ReturnType __cdecl(cancellation_token)>(_Func), _Cts, _callstack);
5238 return _Generator::_GenerateTask_1C(_Func, _Cts, _callstack);
5243 template<
typename _Generator>
5244 struct _TaskGenerator<_Generator, false, true>
5246 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5247 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5248 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5250 #ifndef _PPLTASKS_NO_STDFUNC
5251 typedef decltype(_Func(
details::declval<
const progress_reporter<_ProgressType>&>())) _ReturnType;
5252 return _Generator::_GenerateTask_1P(
std::
function<_ReturnType __cdecl(const progress_reporter<_ProgressType>&)>(_Func), progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5254 return _Generator::_GenerateTask_1P(_Func, progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5259 template<
typename _Generator>
5260 struct _TaskGenerator<_Generator, true, true>
5262 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5263 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5264 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5266 #ifndef _PPLTASKS_NO_STDFUNC
5267 typedef decltype(_Func(
details::declval<
const progress_reporter<_ProgressType>&>(), details::declval<cancellation_token>())) _ReturnType;
5268 return _Generator::_GenerateTask_2PC(
std::
function<_ReturnType __cdecl(const progress_reporter<_ProgressType>&, cancellation_token)>(_Func), progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5270 return _Generator::_GenerateTask_2PC(_Func, progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5296 template<
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken,
bool _TakesProgress>
5297 struct _AsyncAttributes
5301 template<
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken>
5302 struct _AsyncAttributes<_ProgressType, _ReturnType, _TaskTraits, _TakesToken, true>
5304 typedef Windows::Foundation::IAsyncOperationWithProgress<_ReturnType, _ProgressType> _AsyncBaseType;
5305 typedef Windows::Foundation::AsyncOperationProgressHandler<_ReturnType, _ProgressType> _ProgressDelegateType;
5306 typedef Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_ReturnType, _ProgressType> _CompletionDelegateType;
5307 typedef _ReturnType _ReturnType;
5308 typedef _ProgressType _ProgressType;
5309 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5310 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5311 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, true> _TaskGenerator;
5313 static const bool _TakesProgress =
true;
5314 static const bool _TakesToken = _TakesToken;
5317 template<
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken>
5318 struct _AsyncAttributes<_ProgressType, _ReturnType, _TaskTraits, _TakesToken, false>
5320 typedef Windows::Foundation::IAsyncOperation<_ReturnType> _AsyncBaseType;
5321 typedef _Zip _ProgressDelegateType;
5322 typedef Windows::Foundation::AsyncOperationCompletedHandler<_ReturnType> _CompletionDelegateType;
5323 typedef _ReturnType _ReturnType;
5324 typedef _ProgressType _ProgressType;
5325 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5326 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5327 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, false> _TaskGenerator;
5329 static const bool _TakesProgress =
false;
5330 static const bool _TakesToken = _TakesToken;
5333 template<
typename _ProgressType,
typename _TaskTraits,
bool _TakesToken>
5334 struct _AsyncAttributes<_ProgressType, void, _TaskTraits, _TakesToken, true>
5336 typedef Windows::Foundation::IAsyncActionWithProgress<_ProgressType> _AsyncBaseType;
5337 typedef Windows::Foundation::AsyncActionProgressHandler<_ProgressType> _ProgressDelegateType;
5338 typedef Windows::Foundation::AsyncActionWithProgressCompletedHandler<_ProgressType> _CompletionDelegateType;
5339 typedef void _ReturnType;
5340 typedef _ProgressType _ProgressType;
5341 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5342 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5343 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, true> _TaskGenerator;
5345 static const bool _TakesProgress =
true;
5346 static const bool _TakesToken = _TakesToken;
5349 template<
typename _ProgressType,
typename _TaskTraits,
bool _TakesToken>
5350 struct _AsyncAttributes<_ProgressType, void, _TaskTraits, _TakesToken, false>
5352 typedef Windows::Foundation::IAsyncAction _AsyncBaseType;
5353 typedef _Zip _ProgressDelegateType;
5354 typedef Windows::Foundation::AsyncActionCompletedHandler _CompletionDelegateType;
5355 typedef void _ReturnType;
5356 typedef _ProgressType _ProgressType;
5357 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5358 typedef _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5359 typedef _TaskGenerator<_SelectorTaskGenerator, _TakesToken, false> _TaskGenerator;
5361 static const bool _TakesProgress =
false;
5362 static const bool _TakesToken = _TakesToken;
5365 template<
typename _Function>
5366 struct _AsyncLambdaTypeTraits
5368 typedef typename _FunctorTypeTraits<_Function>::_ReturnType _ReturnType;
5369 typedef typename _FunctorTypeTraits<_Function>::_Argument1Type _Argument1Type;
5370 typedef typename _CAFunctorOptions<_Function>::_ProgressType _ProgressType;
5372 static const bool _TakesProgress = _CAFunctorOptions<_Function>::_TakesProgress;
5373 static const bool _TakesToken = _CAFunctorOptions<_Function>::_TakesToken;
5375 typedef _TaskTypeTraits<_ReturnType> _TaskTraits;
5376 typedef _AsyncAttributes<_ProgressType, typename _TaskTraits::_TaskRetType, _TaskTraits, _TakesToken, _TakesProgress> _AsyncAttributes;
5379 struct _AsyncAttributesTaskGenerator
5382 template<
typename _Function,
typename _ClassPtr,
typename _AsyncAttributesT>
5383 static task<typename _AsyncAttributesT::_ReturnType> _Generate_Task(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5385 return _AsyncAttributesT::_TaskGenerator::_GenerateTask<_Function, _ClassPtr, _AsyncAttributesT::_ProgressType>(_Func, _Ptr, _Cts, _callstack);
5396 template <
typename _Attributes, _AsyncResultType _ResultType = SingleResult >
5397 ref class _AsyncInfoBase
abstract : _Attributes::_AsyncBaseType
5402 _M_currentStatus(_AsyncStatusInternal::_AsyncCreated),
5404 _M_completeDelegate(nullptr),
5405 _M_CompleteDelegateAssigned(0),
5412 virtual typename _Attributes::_ReturnType GetResults()
5414 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5417 virtual property unsigned int Id
5421 _CheckValidStateForAsyncInfoCall();
5426 void set(
unsigned int id)
5428 _CheckValidStateForAsyncInfoCall();
5432 throw ::Platform::Exception::CreateException(E_INVALIDARG);
5434 else if (_M_currentStatus != _AsyncStatusInternal::_AsyncCreated)
5436 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5443 virtual property Windows::Foundation::AsyncStatus Status
5445 Windows::Foundation::AsyncStatus
get()
5447 _CheckValidStateForAsyncInfoCall();
5449 _AsyncStatusInternal _Current = _M_currentStatus;
5457 case _AsyncCancelPending:
5458 _Current = _AsyncCanceled;
5461 _Current = _AsyncStarted;
5467 return static_cast<Windows::Foundation::AsyncStatus
>(_Current);
5471 virtual property Windows::Foundation::HResult ErrorCode
5473 Windows::Foundation::HResult
get()
5475 _CheckValidStateForAsyncInfoCall();
5477 Windows::Foundation::HResult _Hr;
5478 _Hr.Value = _M_errorCode;
5483 virtual property typename _Attributes::_ProgressDelegateType^ Progress
5485 typename typename _Attributes::_ProgressDelegateType^
get()
5487 return _GetOnProgress();
5490 void set(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
5492 _PutOnProgress(_ProgressHandler);
5496 virtual void Cancel()
5498 if (_TransitionToState(_AsyncCancelPending))
5504 virtual void Close()
5506 if (_TransitionToState(_AsyncClosed))
5512 if (_M_currentStatus != _AsyncClosed)
5514 throw ::Platform::Exception::CreateException(E_ILLEGAL_STATE_CHANGE);
5519 virtual property typename _Attributes::_CompletionDelegateType^ Completed
5521 typename _Attributes::_CompletionDelegateType^
get()
5523 _CheckValidStateForDelegateCall();
5524 return _M_completeDelegate;
5527 void set(
typename _Attributes::_CompletionDelegateType^ _CompleteHandler)
5529 _CheckValidStateForDelegateCall();
5531 if (InterlockedIncrement(&_M_CompleteDelegateAssigned) == 1)
5534 _M_completeDelegate = _CompleteHandler;
5538 if (_IsTerminalState())
5545 throw ::Platform::Exception::CreateException(E_ILLEGAL_DELEGATE_ASSIGNMENT);
5556 if (_TransitionToState(_AsyncStarted))
5562 throw ::Platform::Exception::CreateException(E_ILLEGAL_STATE_CHANGE);
5567 void _FireCompletion()
5569 _TryTransitionToCompleted();
5572 if (_M_completeDelegate !=
nullptr && InterlockedIncrement(&_M_CallbackMade) == 1)
5574 _M_completeDelegateContext._CallInContext([=] {
5578 _M_completeDelegate((_Attributes::_AsyncBaseType^)
this, this->Status);
5579 _M_completeDelegate =
nullptr;
5581 catch(::Platform::Exception^ _ex)
5584 _M_completeDelegate =
nullptr;
5594 virtual typename _Attributes::_ProgressDelegateType^ _GetOnProgress()
5596 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5599 virtual void _PutOnProgress(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
5601 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5604 bool _TryTransitionToCompleted()
5606 return _TransitionToState(_AsyncStatusInternal::_AsyncCompleted);
5609 bool _TryTransitionToCancelled()
5611 return _TransitionToState(_AsyncStatusInternal::_AsyncCanceled);
5614 bool _TryTransitionToError(
const HRESULT error)
5617 return _TransitionToState(_AsyncStatusInternal::_AsyncError);
5623 inline void _CheckValidStateForDelegateCall()
5625 if (_M_currentStatus == _AsyncClosed)
5627 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5634 inline void _CheckValidStateForResultsCall()
5636 _AsyncStatusInternal _Current = _M_currentStatus;
5638 if (_Current == _AsyncError)
5640 throw ::Platform::Exception::CreateException(_M_errorCode);
5642 #pragma warning(push)
5643 #pragma warning(disable: 4127) // Conditional expression is constant
5645 if (_ResultType == SingleResult)
5646 #pragma warning(pop)
5648 if (_Current != _AsyncCompleted)
5650 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5654 else if (_Current != _AsyncStarted &&
5655 _Current != _AsyncCancelPending &&
5656 _Current != _AsyncCanceled &&
5657 _Current != _AsyncCompleted)
5659 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5666 inline bool _ContinueAsyncOperation()
5668 return (_M_currentStatus == _AsyncStarted);
5674 virtual void _OnStart() = 0;
5675 virtual void _OnClose() = 0;
5676 virtual void _OnCancel() = 0;
5684 inline void _CheckValidStateForAsyncInfoCall()
5686 _AsyncStatusInternal _Current = _M_currentStatus;
5687 if (_Current == _AsyncClosed)
5689 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5691 else if (_Current == _AsyncCreated)
5693 throw ::Platform::Exception::CreateException(E_ASYNC_OPERATION_NOT_STARTED);
5698 inline bool _TransitionToState(
const _AsyncStatusInternal _NewState)
5700 _AsyncStatusInternal _Current = _M_currentStatus;
5706 case _AsyncStatusInternal::_AsyncStarted:
5707 if (_Current != _AsyncCreated)
5712 case _AsyncStatusInternal::_AsyncCompleted:
5713 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5718 case _AsyncStatusInternal::_AsyncCancelPending:
5719 if (_Current != _AsyncStarted)
5724 case _AsyncStatusInternal::_AsyncCanceled:
5725 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5730 case _AsyncStatusInternal::_AsyncError:
5731 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5736 case _AsyncStatusInternal::_AsyncClosed:
5737 if (!_IsTerminalState(_Current))
5750 _AsyncStatusInternal _RetState =
static_cast<_AsyncStatusInternal
>(
5753 static_cast<LONG>(_Current)));
5758 return (_RetState == _Current);
5761 inline bool _IsTerminalState()
5763 return _IsTerminalState(_M_currentStatus);
5766 inline bool _IsTerminalState(_AsyncStatusInternal
status)
5768 return (status == _AsyncError ||
5769 status == _AsyncCanceled ||
5770 status == _AsyncCompleted ||
5771 status == _AsyncClosed);
5776 _ContextCallback _M_completeDelegateContext;
5777 typename _Attributes::_CompletionDelegateType^
volatile _M_completeDelegate;
5778 _AsyncStatusInternal
volatile _M_currentStatus;
5779 HRESULT
volatile _M_errorCode;
5781 long volatile _M_CompleteDelegateAssigned;
5782 long volatile _M_CallbackMade;
5794 template<
typename _Attributes,
bool _HasProgress, _AsyncResultType _ResultType = SingleResult >
5795 ref class __declspec(no_empty_identity_interface) _AsyncProgressBase
abstract : _AsyncInfoBase<_Attributes, _ResultType>
5799 template<
typename _Attributes, _AsyncResultType _ResultType>
5800 ref class __declspec(no_empty_identity_interface) _AsyncProgressBase<_Attributes, true, _ResultType>
abstract : _AsyncInfoBase<_Attributes, _ResultType>
5804 _AsyncProgressBase() : _AsyncInfoBase<_Attributes, _ResultType>(),
5805 _M_progressDelegate(nullptr)
5809 virtual typename _Attributes::_ProgressDelegateType^ _GetOnProgress()
override
5811 _CheckValidStateForDelegateCall();
5812 return _M_progressDelegate;
5815 virtual void _PutOnProgress(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
override
5817 _CheckValidStateForDelegateCall();
5818 _M_progressDelegate = _ProgressHandler;
5822 void _FireProgress(
const typename _Attributes::_ProgressType& _ProgressValue)
5824 if (_M_progressDelegate !=
nullptr)
5826 _M_progressDelegateContext._CallInContext([=] {
5829 _M_progressDelegate((_Attributes::_AsyncBaseType^)
this, _ProgressValue);
5831 catch(::Platform::Exception^ _ex)
5834 _M_progressDelegate =
nullptr;
5846 _ContextCallback _M_progressDelegateContext;
5847 typename _Attributes::_ProgressDelegateType^ _M_progressDelegate;
5853 template<
typename _Function>
5854 ref class _AsyncTaskGeneratorThunk
sealed : _AsyncProgressBase<typename _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes,
5855 _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes::_TakesProgress>
5859 typedef typename _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes _Attributes;
5860 typedef typename _Attributes::_AsyncBaseType _AsyncBaseType;
5862 _AsyncTaskGeneratorThunk(
const _Function& _Func,
const _TaskCreationCallstack &_callstack) : _M_func(_Func), _M_creationCallstack(_callstack)
5870 virtual typename _Attributes::_ReturnType GetResults()
override
5872 _CheckValidStateForResultsCall();
5873 return _M_task.get();
5883 virtual void _OnStart()
override
5889 _M_task = _AsyncAttributesTaskGenerator::_Generate_Task<_Function, _AsyncTaskGeneratorThunk<_Function>^, _Attributes>(_M_func,
this, _M_cts, _M_creationCallstack);
5890 _M_task.then([=](task<typename _Attributes::_ReturnType> _Antecedent) {
5895 catch (task_canceled&)
5897 _TryTransitionToCancelled();
5899 catch (::Platform::Exception^ _Ex)
5901 _TryTransitionToError(_Ex->HResult);
5905 _TryTransitionToError(E_FAIL);
5911 virtual void _OnCancel()
override
5916 virtual void _OnClose()
override
5922 task<typename _Attributes::_ReturnType> _M_task;
5923 cancellation_token_source _M_cts;
5924 _TaskCreationCallstack _M_creationCallstack;
5969 template<
typename _Function>
5971 details::_AsyncTaskGeneratorThunk<_Function> ^create_async(const _Function& _Func)
5973 static_assert(std::is_same<decltype(details::_IsValidCreateAsync(_Func,0,0,0,0)),
std::true_type>::value,
5974 "argument to create_async must be a callable object taking zero, one or two arguments");
5986 template<
typename _Type>
5989 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
5993 void _Resize(
size_t _Len,
bool _SkipVector =
false)
5998 _M_vector._Result.resize(_Len);
6002 task_completion_event<_Unit_type> _M_completed;
6003 _ResultHolder<std::vector<_Type> > _M_vector;
6004 _ResultHolder<_Type> _M_mergeVal;
6009 template<
typename _Type>
6010 struct _RunAllParam<
std::
vector<_Type> >
6012 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
6016 void _Resize(
size_t _Len,
bool _SkipVector =
false)
6022 _M_vector.resize(_Len);
6026 task_completion_event<_Unit_type> _M_completed;
6027 std::vector<_ResultHolder<std::vector<_Type> > > _M_vector;
6034 struct _RunAllParam<_Unit_type>
6036 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
6045 task_completion_event<_Unit_type> _M_completed;
6050 inline void _JoinAllTokens_Add(
const cancellation_token_source& _MergedSrc, _CancellationTokenState *_PJoinedTokenState)
6055 _T.register_callback( [=](){
6056 _MergedSrc.cancel();
6061 template<
typename _ElementType,
typename _Function,
typename _TaskType>
6062 void _WhenAllContinuationWrapper(_RunAllParam<_ElementType>* _PParam, _Function _Func, task<_TaskType>& _Task)
6064 if (_Task._GetImpl()->_IsCompleted())
6077 _ASSERTE(_Task._GetImpl()->_IsCanceled());
6078 if (_Task._GetImpl()->_HasUserException())
6081 if (!_PParam->_M_completed._Cancel(_Task._GetImpl()->_GetExceptionHolder()))
6083 atomic_exchange(_Task._GetImpl()->_GetExceptionHolder()->_M_exceptionObserved, 1l);
6088 _PParam->_M_completed._Cancel();
6098 template<
typename _ElementType,
typename _Iterator>
6101 static task<std::vector<_ElementType>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6103 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6105 auto _PParam =
new _RunAllParam<_ElementType>();
6106 cancellation_token_source _MergedSource;
6109 task_options _Options(_TaskOptions);
6110 _Options.set_cancellation_token(_MergedSource.get_token());
6111 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6113 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> {
6114 return _PParam->_M_vector.Get();
6120 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6121 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6125 size_t _TaskNum = 0;
6126 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6129 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6131 _PParam->_Resize(_TaskNum);
6135 if( _Begin == _End )
6143 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6145 if (_PTask->is_apartment_aware())
6147 _ReturnTask._SetAsync();
6150 _PTask->_Then([_PParam, _Index](task<_ElementType> _ResultTask) {
6153 typedef _ElementType _ElementTypeDev10;
6154 auto _PParamCopy = _PParam;
6155 auto _IndexCopy = _Index;
6156 auto _Func = [_PParamCopy, _IndexCopy, &_ResultTask](){
6157 _PParamCopy->_M_vector._Result[_IndexCopy] = _ResultTask._GetImpl()->_GetResult();
6160 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6171 template<
typename _ElementType,
typename _Iterator>
6172 struct _WhenAllImpl<
std::
vector<_ElementType>, _Iterator>
6174 static task<std::vector<_ElementType>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6176 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6178 auto _PParam =
new _RunAllParam<std::vector<_ElementType>>();
6179 cancellation_token_source _MergedSource;
6182 task_options _Options(_TaskOptions);
6183 _Options.set_cancellation_token(_MergedSource.get_token());
6184 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6186 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> {
6187 _ASSERTE(_PParam->_M_completeCount == _PParam->_M_numTasks);
6188 std::vector<_ElementType> _Result;
6189 for(
size_t _I = 0; _I < _PParam->_M_numTasks; _I++)
6191 const std::vector<_ElementType>& _Vec = _PParam->_M_vector[_I].Get();
6192 _Result.insert(_Result.end(), _Vec.begin(), _Vec.end());
6200 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6201 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6205 size_t _TaskNum = 0;
6206 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6209 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6211 _PParam->_Resize(_TaskNum);
6215 if( _Begin == _End )
6223 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6225 if (_PTask->is_apartment_aware())
6227 _ReturnTask._SetAsync();
6230 _PTask->_Then([_PParam, _Index](task<std::vector<_ElementType>> _ResultTask) {
6232 typedef _ElementType _ElementTypeDev10;
6233 auto _PParamCopy = _PParam;
6234 auto _IndexCopy = _Index;
6235 auto _Func = [_PParamCopy, _IndexCopy, &_ResultTask]() {
6236 _PParamCopy->_M_vector[_IndexCopy].Set(_ResultTask._GetImpl()->_GetResult());
6239 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6250 template<
typename _Iterator>
6251 struct _WhenAllImpl<void, _Iterator>
6253 static task<void> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6255 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6257 auto _PParam =
new _RunAllParam<_Unit_type>();
6258 cancellation_token_source _MergedSource;
6261 task_options _Options(_TaskOptions);
6262 _Options.set_cancellation_token(_MergedSource.get_token());
6263 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6265 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) {
6271 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6272 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6276 size_t _TaskNum = 0;
6277 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6280 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6282 _PParam->_Resize(_TaskNum);
6286 if( _Begin == _End )
6293 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6295 if (_PTask->is_apartment_aware())
6297 _ReturnTask._SetAsync();
6300 _PTask->_Then([_PParam](task<void> _ResultTask) {
6301 auto _Func = [](){};
6302 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6311 template<
typename _ReturnType>
6312 task<std::vector<_ReturnType>> _WhenAllVectorAndValue(
const task<std::vector<_ReturnType>>& _VectorTask,
const task<_ReturnType>& _ValueTask,
6313 bool _OutputVectorFirst)
6315 auto _PParam =
new _RunAllParam<_ReturnType>();
6316 cancellation_token_source _MergedSource;
6319 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _MergedSource.get_token());
6321 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ReturnType> {
6322 _ASSERTE(_PParam->_M_completeCount == 2);
6323 auto _Result = _PParam->_M_vector.Get();
6324 auto _mergeVal = _PParam->_M_mergeVal.Get();
6326 if (_OutputVectorFirst ==
true)
6328 _Result.push_back(_mergeVal);
6332 _Result.insert(_Result.begin(), _mergeVal);
6338 _JoinAllTokens_Add(_MergedSource, _VectorTask._GetImpl()->_M_pTokenState);
6339 _JoinAllTokens_Add(_MergedSource, _ValueTask._GetImpl()->_M_pTokenState);
6342 _PParam->_Resize(2,
true);
6344 if (_VectorTask.is_apartment_aware() || _ValueTask.is_apartment_aware())
6346 _ReturnTask._SetAsync();
6348 _VectorTask._Then([_PParam](task<std::vector<_ReturnType>> _ResultTask) {
6350 typedef _ReturnType _ReturnTypeDev10;
6351 auto _PParamCopy = _PParam;
6352 auto _Func = [_PParamCopy, &_ResultTask]() {
6353 auto _ResultLocal = _ResultTask._GetImpl()->_GetResult();
6354 _PParamCopy->_M_vector.Set(_ResultLocal);
6357 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6359 _ValueTask._Then([_PParam](task<_ReturnType> _ResultTask) {
6361 typedef _ReturnType _ReturnTypeDev10;
6362 auto _PParamCopy = _PParam;
6363 auto _Func = [_PParamCopy, &_ResultTask]() {
6364 auto _ResultLocal = _ResultTask._GetImpl()->_GetResult();
6365 _PParamCopy->_M_mergeVal.Set(_ResultLocal);
6368 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6398 template <
typename _Iterator>
6399 auto when_all(_Iterator _Begin, _Iterator _End,
const task_options& _TaskOptions = task_options())
6400 -> decltype (details::_WhenAllImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_TaskOptions, _Begin, _End))
6402 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6403 return details::_WhenAllImpl<_ElementType, _Iterator>::_Perform(_TaskOptions, _Begin, _End);
6431 template<
typename _ReturnType>
6432 task<std::vector<_ReturnType>>
operator&&(
const task<_ReturnType> & _Lhs,
const task<_ReturnType> & _Rhs)
6434 task<_ReturnType> _PTasks[2] = {_Lhs, _Rhs};
6435 return when_all(_PTasks, _PTasks+2);
6463 template<
typename _ReturnType>
6464 task<std::vector<_ReturnType>>
operator&&(
const task<std::vector<_ReturnType>> & _Lhs,
const task<_ReturnType> & _Rhs)
6466 return details::_WhenAllVectorAndValue(_Lhs, _Rhs,
true);
6494 template<
typename _ReturnType>
6495 task<std::vector<_ReturnType>>
operator&&(
const task<_ReturnType> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6497 return details::_WhenAllVectorAndValue(_Rhs, _Lhs,
false);
6525 template<
typename _ReturnType>
6526 task<std::vector<_ReturnType>>
operator&&(
const task<std::vector<_ReturnType>> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6528 task<std::vector<_ReturnType>> _PTasks[2] = {_Lhs, _Rhs};
6529 return when_all(_PTasks, _PTasks+2);
6557 inline task<void>
operator&&(
const task<void> & _Lhs,
const task<void> & _Rhs)
6559 task<void> _PTasks[2] = {_Lhs, _Rhs};
6560 return when_all(_PTasks, _PTasks+2);
6566 template <
typename _CompletionType>
6569 _RunAnyParam() : _M_exceptionRelatedToken(nullptr), _M_completeCount(0), _M_numTasks(0), _M_fHasExplicitToken(false)
6575 _M_exceptionRelatedToken->_Release();
6577 task_completion_event<_CompletionType> _M_Completed;
6578 cancellation_token_source _M_cancellationSource;
6579 _CancellationTokenState * _M_exceptionRelatedToken;
6582 bool _M_fHasExplicitToken;
6585 template<
typename _CompletionType,
typename _Function,
typename _TaskType>
6586 void _WhenAnyContinuationWrapper(_RunAnyParam<_CompletionType> * _PParam,
const _Function & _Func, task<_TaskType>& _Task)
6588 bool _IsTokenCanceled = !_PParam->_M_fHasExplicitToken && _Task._GetImpl()->_M_pTokenState !=
_CancellationTokenState::_None() && _Task._GetImpl()->_M_pTokenState->_IsCanceled();
6589 if (_Task._GetImpl()->_IsCompleted() && !_IsTokenCanceled)
6594 _PParam->_M_Completed._ClearStoredException();
6600 _ASSERTE(_Task._GetImpl()->_IsCanceled() || _IsTokenCanceled);
6601 if (_Task._GetImpl()->_HasUserException())
6603 if (!_IsTokenCanceled && _PParam->_M_Completed._StoreException(_Task._GetImpl()->_GetExceptionHolder()))
6606 _PParam->_M_exceptionRelatedToken = _Task._GetImpl()->_M_pTokenState;
6607 _ASSERTE(_PParam->_M_exceptionRelatedToken);
6611 _PParam->_M_exceptionRelatedToken->_Reference();
6617 atomic_exchange(_Task._GetImpl()->_GetExceptionHolder()->_M_exceptionObserved, 1l);
6624 if (!_PParam->_M_Completed._IsTriggered())
6627 if (!_PParam->_M_fHasExplicitToken)
6629 if (_PParam->_M_exceptionRelatedToken)
6631 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PParam->_M_exceptionRelatedToken);
6637 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _Task._GetImpl()->_M_pTokenState);
6641 _PParam->_M_Completed._Cancel();
6644 _PParam->_M_Completed._ClearStoredException();
6650 template<
typename _ElementType,
typename _Iterator>
6653 static task<std::pair<_ElementType, size_t>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6655 if( _Begin == _End )
6657 _THROW_NCEE(invalid_operation,
"when_any(begin, end) cannot be called on an empty container.");
6659 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6660 auto _PParam =
new _RunAnyParam<std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *>>();
6664 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PTokenState);
6665 _PParam->_M_fHasExplicitToken =
true;
6668 task_options _Options(_TaskOptions);
6669 _Options.set_cancellation_token(_PParam->_M_cancellationSource.get_token());
6670 task<std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _Options);
6673 auto _CancellationSource = _PParam->_M_cancellationSource;
6675 _PParam->_M_numTasks =
static_cast<size_t>(
std::distance(_Begin, _End));
6677 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6679 if (_PTask->is_apartment_aware())
6681 _Any_tasks_completed._SetAsync();
6684 _PTask->_Then([_PParam, _Index](task<_ElementType> _ResultTask) {
6685 auto _PParamCopy = _PParam;
6686 auto _IndexCopy = _Index;
6687 auto _Func = [&_ResultTask, _PParamCopy, _IndexCopy]() {
6688 _PParamCopy->_M_Completed.set(
std::make_pair(
std::make_pair(_ResultTask._GetImpl()->_GetResult(), _IndexCopy), _ResultTask._GetImpl()->_M_pTokenState));
6691 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6698 return _Any_tasks_completed._Then([=](std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *> _Result) -> std::pair<_ElementType, size_t> {
6699 _ASSERTE(_Result.second);
6702 _JoinAllTokens_Add(_CancellationSource, _Result.second);
6704 return _Result.first;
6709 template<
typename _Iterator>
6710 struct _WhenAnyImpl<void, _Iterator>
6712 static task<size_t> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6714 if( _Begin == _End )
6716 _THROW_NCEE(invalid_operation,
"when_any(begin, end) cannot be called on an empty container.");
6719 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6720 auto _PParam =
new _RunAnyParam<std::pair<size_t, _CancellationTokenState *>>();
6724 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PTokenState);
6725 _PParam->_M_fHasExplicitToken =
true;
6728 task_options _Options(_TaskOptions);
6729 _Options.set_cancellation_token(_PParam->_M_cancellationSource.get_token());
6730 task<std::pair<size_t, _CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _Options);
6733 auto _CancellationSource = _PParam->_M_cancellationSource;
6735 _PParam->_M_numTasks =
static_cast<size_t>(
std::distance(_Begin, _End));
6737 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6739 if (_PTask->is_apartment_aware())
6741 _Any_tasks_completed._SetAsync();
6744 _PTask->_Then([_PParam, _Index](task<void> _ResultTask) {
6745 auto _PParamCopy = _PParam;
6746 auto _IndexCopy = _Index;
6747 auto _Func = [&_ResultTask, _PParamCopy, _IndexCopy]() {
6748 _PParamCopy->_M_Completed.set(
std::make_pair(_IndexCopy, _ResultTask._GetImpl()->_M_pTokenState));
6750 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6757 return _Any_tasks_completed._Then([=](std::pair<size_t, _CancellationTokenState *> _Result) ->
size_t {
6758 _ASSERTE(_Result.second);
6761 _JoinAllTokens_Add(_CancellationSource, _Result.second);
6763 return _Result.first;
6789 template<
typename _Iterator>
6790 auto when_any(_Iterator _Begin, _Iterator _End,
const task_options& _TaskOptions = task_options())
6791 -> decltype (details::_WhenAnyImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_TaskOptions, _Begin, _End))
6793 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6794 return details::_WhenAnyImpl<_ElementType, _Iterator>::_Perform(_TaskOptions, _Begin, _End);
6821 template<
typename _Iterator>
6822 auto when_any(_Iterator _Begin, _Iterator _End, cancellation_token _CancellationToken)
6823 -> decltype (details::_WhenAnyImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End))
6825 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6826 return details::_WhenAnyImpl<_ElementType, _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End);
6855 template<
typename _ReturnType>
6856 task<_ReturnType>
operator||(
const task<_ReturnType> & _Lhs,
const task<_ReturnType> & _Rhs)
6858 auto _PParam =
new details::_RunAnyParam<std::pair<_ReturnType, size_t>>();
6860 task<std::pair<_ReturnType, size_t>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
6863 auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair<_ReturnType, size_t> _Ret) -> _ReturnType {
6864 _ASSERTE(_Ret.second);
6865 _JoinAllTokens_Add(_PParam->_M_cancellationSource, reinterpret_cast<details::_CancellationTokenState *>(_Ret.second));
6869 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
6871 _ReturnTask._SetAsync();
6874 _PParam->_M_numTasks = 2;
6875 auto _Continuation = [_PParam](task<_ReturnType> _ResultTask) {
6877 auto _PParamCopy = _PParam;
6878 auto _Func = [&_ResultTask, _PParamCopy]() {
6879 _PParamCopy->_M_Completed.set(
std::make_pair(_ResultTask._GetImpl()->_GetResult(),
reinterpret_cast<size_t>(_ResultTask._GetImpl()->_M_pTokenState)));
6881 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6916 template<
typename _ReturnType>
6917 task<std::vector<_ReturnType>>
operator||(
const task<std::vector<_ReturnType>> & _Lhs,
const task<_ReturnType> & _Rhs)
6919 auto _PParam =
new details::_RunAnyParam<std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *>>();
6921 task<std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
6925 auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *> _Ret) -> std::vector<_ReturnType> {
6926 _ASSERTE(_Ret.second);
6927 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second);
6931 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
6933 _ReturnTask._SetAsync();
6936 _PParam->_M_numTasks = 2;
6937 _Lhs._Then([_PParam](task<std::vector<_ReturnType>> _ResultTask) {
6939 auto _PParamCopy = _PParam;
6940 auto _Func = [&_ResultTask, _PParamCopy]() {
6941 auto _Result = _ResultTask._GetImpl()->_GetResult();
6942 _PParamCopy->_M_Completed.set(
std::make_pair(_Result, _ResultTask._GetImpl()->_M_pTokenState));
6944 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6948 _Rhs._Then([_PParam](task<_ReturnType> _ResultTask)
6951 typedef _ReturnType _ReturnTypeDev10;
6952 auto _PParamCopy = _PParam;
6953 auto _Func = [&_ResultTask, _PParamCopy]() {
6954 auto _Result = _ResultTask._GetImpl()->_GetResult();
6956 std::vector<_ReturnTypeDev10> _Vec;
6957 _Vec.push_back(_Result);
6958 _PParamCopy->_M_Completed.set(
std::make_pair(_Vec, _ResultTask._GetImpl()->_M_pTokenState));
6960 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6992 template<
typename _ReturnType>
6993 task<std::vector<_ReturnType>>
operator||(
const task<_ReturnType> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6995 return _Rhs || _Lhs;
7024 inline task<void>
operator||(
const task<void> & _Lhs,
const task<void> & _Rhs)
7026 auto _PParam =
new details::_RunAnyParam<std::pair<details::_Unit_type, details::_CancellationTokenState *>>();
7028 task<std::pair<details::_Unit_type, details::_CancellationTokenState *>> _Any_task_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
7031 auto _ReturnTask = _Any_task_completed._Then([=](std::pair<details::_Unit_type, details::_CancellationTokenState *> _Ret) {
7032 _ASSERTE(_Ret.second);
7033 details::_JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second);
7036 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
7038 _ReturnTask._SetAsync();
7041 _PParam->_M_numTasks = 2;
7042 auto _Continuation = [_PParam](task<void> _ResultTask)
mutable {
7044 auto _PParam1 = _PParam;
7045 auto _Func = [&_ResultTask, _PParam1]() {
7048 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
7057 template<
typename _Ty>
7058 task<_Ty> task_from_result(_Ty _Param,
const task_options& _TaskOptions = task_options())
7060 task_completion_event<_Ty> _Tce;
7062 return create_task(_Tce, _TaskOptions);
7065 inline task<void> task_from_result(
const task_options& _TaskOptions = task_options())
7067 task_completion_event<void> _Tce;
7069 return create_task(_Tce, _TaskOptions);
7072 template<
typename _TaskType,
typename _ExType>
7073 task<_TaskType> task_from_exception(_ExType _Exception,
const task_options& _TaskOptions = task_options())
7075 task_completion_event<_TaskType> _Tce;
7076 _Tce.set_exception(_Exception);
7077 return create_task(_Tce, _TaskOptions);
7090 task<bool> do_while(std::function<task<bool>(
void)> _Func)
7092 task<bool> _First = _Func();
7093 return _First.then([=](
bool _Guard) -> task<bool> {
7095 return do_while(_Func);
7105 #pragma pop_macro("new")
7106 #pragma warning(pop)
7109 #endif // _PPLTASKS_H
Definition: ppltasks.h:1037
_InitialTaskHandle(const typename details::_Task_ptr< _ReturnType >::_Type &_TaskImpl, const _Function &_func)
Definition: ppltasks.h:3453
Definition: xtr1common:22
std::shared_ptr< _ExceptionHolder > _M_exceptionHolder
Definition: ppltasks.h:2026
void _set_creation_callstack(const _TaskCreationCallstack &_callstack)
Definition: ppltasks.h:1042
void _RethrowUserException()
Definition: ppltasks.h:754
virtual ~_PPLTaskHandle()
Definition: ppltasks.h:1402
std::function< _Unit_type(void)> _MakeVoidToUnitFunc(const std::function< void(void)> &_Func)
Definition: ppltasks.h:2298
bool _IsCompleted()
Definition: ppltasks.h:1656
static _TaskCreationCallstack _CaptureSingleFrameCallstack(void *_SingleFrame)
Definition: ppltasks.h:169
_TaskCreationCallstack _M_presetCreationCallstack
Definition: ppltasks.h:1040
_Ty _Type
Definition: ppltasks.h:204
scheduler_ptr _M_Scheduler
Definition: ppltasks.h:1224
void _TaskInitMaybeFunctor(_Function &_Func, std::true_type)
Initializes a task using a callable object.
Definition: ppltasks.h:4365
Definition: ppltasks.h:400
_T atomic_exchange(std::atomic< _T > &_Target, _T _Value)
Definition: pplinterface.h:246
Definition: functional:67
void _Continue(std::false_type, details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3604
void _SyncCancelAndPropagateException() const
Definition: ppltasks.h:3583
task_options()
Default list of task creation options
Definition: ppltasks.h:1067
bool _M_HasScheduler
Definition: ppltasks.h:1229
std::function< _Unit_type(_Unit_type)> _MakeUnitToUnitFunc(const std::function< void(void)> &_Func)
Definition: ppltasks.h:2315
_ThenImplOptions(_CancellationTokenState *_Token_state, const task_continuation_context *_Continuation_context, scheduler_ptr _PScheduler, _TaskCreationCallstack _Creation_stack, _TaskInliningMode_t _Inlining_mode=_NoInline)
Definition: ppltasks.h:1239
This class describes an exception thrown when an invalid operation is performed that is not more accu...
Definition: pplinterface.h:132
Definition: ppltasks.h:1289
_CRTIMP2 void __thiscall _LogWorkItemStarted()
bool _HasUserException()
Definition: ppltasks.h:1666
Definition: ppltasks.h:1346
reference_wrapper< _Ty > ref(_Ty &_Val) _NOEXCEPT
Definition: type_traits:1617
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:4311
bool _M_scheduled
Definition: ppltasks.h:1314
void Set(const std::vector< bool > &_type)
Definition: ppltasks.h:641
std::shared_ptr< _Task_impl_base > _Task_ptr_base
Definition: ppltasks.h:1286
~_TaskWorkItemRAIILogger()
Definition: ppltasks.h:1354
_Holder(_TaskProcThunk *_PThunk)
Definition: ppltasks.h:461
bool _ForceInline() const
Definition: ppltasks.h:1024
bool _M_RunInline
Definition: ppltasks.h:1031
#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:3414
std::function< _Type(_Unit_type)> _MakeUnitToTFunc(const std::function< _Type(void)> &_Func)
Definition: ppltasks.h:2304
_ContinuationList _M_Continuations
Definition: ppltasks.h:2031
details::_Task_ptr< _ReturnType >::_Type _M_ancestorTaskImpl
Definition: ppltasks.h:3551
Definition: ppltasks.h:1237
_Ty _Type
Definition: ppltasks.h:234
void _Perform() const
Definition: ppltasks.h:3468
unsigned int _Count
Definition: xcomplex:668
auto _IsCallable(_Function _Func, int) -> decltype(_Func(), std::true_type())
std::vector< void * > _M_frames
Definition: ppltasks.h:161
_TaskCreationCallstack _M_stackTrace
Definition: ppltasks.h:775
scheduler_ptr _GetScheduler() const
Definition: ppltasks.h:2010
for(_CMPLX(_Ty) _Zv=_CMPLX(_Ty)(1);;_Tmp *=_Tmp)
Definition: xcomplex:673
const details::_Task_ptr< _ReturnType >::_Type & _ThenGetImpl() const
Definition: ppltasks.h:3375
~_Task_completion_event_impl()
Definition: ppltasks.h:2278
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:1349
_ContextCallback(bool _DeferCapture=false)
Definition: ppltasks.h:514
bool operator==(const _ContextCallback &_Rhs) const
Definition: ppltasks.h:581
const ::std::shared_ptr< scheduler_interface > & get_ambient_scheduler()
Definition: pplwin.h:88
void _LogTaskExecutionStarted()
Definition: ppltasks.h:1327
_Task_ptr_base _GetTaskImplBase() const
Definition: ppltasks.h:1436
void _RunContinuation(_ContinuationTaskHandleBase *_PTaskHandle)
Function executes a continuation. This function is recorded by a parent task implementation when a co...
Definition: ppltasks.h:1742
std::mutex _M_taskListCritSec
Definition: ppltasks.h:2290
details::_NormalizeVoidToUnitType< _ContinuationReturnType >::_Type _NormalizedContinuationReturnType
Definition: ppltasks.h:3549
task_options(cancellation_token _Token)
Task option that specify a cancellation token
Definition: ppltasks.h:1079
Definition: ppltasks.h:198
__declspec(noinline) static _TaskCreationCallstack _CaptureMultiFramesCallstack(void *_SingleFrame
_PPLTaskHandle(const typename _Task_ptr< _ReturnType >::_Type &_PTask)
Definition: ppltasks.h:1398
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:1248
_ContinuationTaskHandleBase * _M_next
Definition: ppltasks.h:1291
auto _FilterValidTaskType(_Ty _Param, int) -> decltype(_GetTaskType(_Param, _IsCallable(_Param, 0)))
#define _TRY_BEGIN
Definition: xstddef:60
#define _CATCH(x)
Definition: xstddef:61
bool _IsCanceled()
Definition: ppltasks.h:1661
task(const task &_Other)
Constructs a task object.
Definition: ppltasks.h:3038
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:188
_OutIt transform(_InIt _First, _InIt _Last, _OutIt _Dest, _Fn1 _Func)
Definition: algorithm:956
auto _VoidIsTaskHelper(_Function _Func, int, int) -> decltype(_Func(std::declval< task< void >>()), std::true_type())
task< details::_Unit_type > _M_unitTask
Definition: ppltasks.h:4380
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: ppltasks.h:2339
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:4302
Definition: exception:254
Definition: concrt.h:4305
#define _CATCH_END
Definition: xstddef:63
_Unit_type _Type
Definition: ppltasks.h:210
::Concurrency::details::_TaskCollection_t _M_TaskCollection
Definition: ppltasks.h:2040
task_completion_event()
Constructs a task_completion_event object.
Definition: ppltasks.h:2346
bool _M_fHasValue
Definition: ppltasks.h:2293
_Task_ptr< _ReturnType >::_Type _M_pTask
Definition: ppltasks.h:1441
__declspec(noinline) bool set_exception(std
Propagates an exception to all tasks associated with this event.
Definition: ppltasks.h:2427
_In_ int _Val
Definition: vcruntime_string.h:62
task< typename _TaskTypeTraits< typename _FunctionTypeTraits< _Function, _ReturnType >::_FuncRetType >::_TaskRetType > _TaskOfType
Definition: ppltasks.h:402
void _Init(details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3483
void _Resolve(bool _CaptureCurrent)
Definition: ppltasks.h:527
__declspec(noinline) explicit task(_Ty _Param)
Constructs a task object.
Definition: ppltasks.h:2953
cancellation_token _M_CancellationToken
Definition: ppltasks.h:1225
static task_continuation_context get_current_winrt_context()
Returns a task continuation context object that represents the current winrt thread context...
Definition: ppltasks.h:955
file_status status(const path &)
Definition: filesystem:3137
void reserve(size_type _Count)
Definition: vector:1031
_Function _M_function
Definition: ppltasks.h:3452
_CancellationTokenState * _PTokenState
Definition: ppltasks.h:1244
Definition: ppltasks.h:619
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:3397
bool operator==(const task< void > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:4232
std::vector< typename _Task_ptr< _ResultType >::_Type > _TaskList
Definition: ppltasks.h:2266
void _Perform() const
Definition: ppltasks.h:3578
void _TaskInitNoFunctor(task_completion_event< _ReturnType > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:3788
_Internal_task_options & _get_internal_task_options(task_options &_Options)
Definition: ppltasks.h:1266
Represents the allowed options for creating a task
Definition: ppltasks.h:1059
task()
Constructs a task object.
Definition: ppltasks.h:3929
The Concurrency namespace provides classes and functions that provide access to the Concurrency Runti...
Definition: agents.h:43
Definition: ppltasks.h:197
Definition: ppltasks.h:3449
bool _M_isTaskBasedContinuation
Definition: ppltasks.h:1293
Definition: ppltasks.h:4434
bool _Cancel(bool _SynchronousCancel)
Definition: ppltasks.h:1596
The implementation of a first-class task. This structure contains the task group used to execute the ...
Definition: ppltasks.h:1276
void _TaskRetType
Definition: ppltasks.h:345
_TaskEventLogger(_Task_impl_base *_task)
Definition: ppltasks.h:1338
void _SetAsync(bool _Async=true)
Sets a property determining whether the task is apartment aware.
Definition: ppltasks.h:4294
cancellation_token get_cancellation_token() const
Returns the cancellation token
Definition: ppltasks.h:1189
_TaskEventLogger _M_taskEventLogger
Definition: ppltasks.h:2045
size_t _CaptureFrames
Definition: ppltasks.h:179
_ExceptionHolder(const std::exception_ptr &_E, const _TaskCreationCallstack &_stackTrace)
Definition: ppltasks.h:737
Definition: ppltasks.h:1456
Definition: ppltasks.h:328
std::function< void __cdecl(void)> _CallbackFunction
Definition: ppltasks.h:498
static const bool _Value
Definition: ppltasks.h:216
_CancellationTokenState * _M_pTokenState
Definition: ppltasks.h:2034
_TaskInliningMode_t _M_inliningMode
Definition: ppltasks.h:1296
integral_constant< bool, false > false_type
Definition: xtr1common:41
bool _IsApartmentAware()
Definition: ppltasks.h:1677
void _Cancel() const
Cancel the task_completion_event. Any task created using this event will be marked as canceled if it ...
Definition: ppltasks.h:2671
Definition: ppltasks.h:1459
scheduler_ptr scheduler() const
Returns the scheduler for this task
Definition: ppltasks.h:4208
_Task_impl_base * _M_task
Definition: ppltasks.h:1313
Definition: pplinterface.h:224
auto _LogWorkItemAndInvokeUserLambda(_Func &&_func, _Arg &&_value) const -> decltype(_func(std::forward< _Arg >(_value)))
Definition: ppltasks.h:3572
_CRTIMP2 void __thiscall _CallInContext(_CallbackFunction _Func, bool _IgnoreDisconnect) const
task_completion_event< details::_Unit_type > _M_unitEvent
Definition: ppltasks.h:2725
bool _IsHRCOMDisconnected(int __hr)
Definition: ppltasks.h:4448
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: ppltasks.h:2625
_Internal_task_options()
Definition: ppltasks.h:1047
unsigned char _Unit_type
Definition: ppltasks.h:191
virtual ~_InitialTaskHandle()
Definition: ppltasks.h:3459
__declspec(noinline) bool set_exception(_E _Except) const
Definition: ppltasks.h:2647
bool _CancelWithException(const std::exception_ptr &_Exception)
Definition: ppltasks.h:1608
bool is_done() const
Determines if the task is completed.
Definition: ppltasks.h:3288
_Iter_diff_t< _InIt > distance(_InIt _First, _InIt _Last)
Definition: xutility:1124
Definition: ppltasks.h:322
_TaskProcThunk * _M_pThunk
Definition: ppltasks.h:470
bool has_scheduler() const
Indicates whether a scheduler n was specified by the user
Definition: ppltasks.h:1205
_TaskCreationCallstack()
Definition: ppltasks.h:163
bool _IsTriggered() const
Tests whether current event has been either Set, or Canceled.
Definition: ppltasks.h:2499
void _DeregisterCancellation()
Definition: ppltasks.h:1631
#define _REPORT_PPLTASK_UNOBSERVED_EXCEPTION()
Definition: pplwin.h:125
const details::_Task_ptr< details::_Unit_type >::_Type & _ThenGetImpl() const
Definition: ppltasks.h:4265
void _ScheduleContinuationTask(_ContinuationTaskHandleBase *_PTaskHandle)
Definition: ppltasks.h:1774
Definition: pplinterface.h:226
Definition: ppltasks.h:214
static std::shared_ptr< details::_ExceptionHolder > _ToExceptionHolder(std::exception_ptr _ExceptionPtr, const details::_TaskCreationCallstack &_SetExceptionAddressHint)
Definition: ppltasks.h:2511
details::_Internal_task_options _M_InternalTaskOptions
Definition: ppltasks.h:1227
task_status _Wait()
Definition: ppltasks.h:1485
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:2690
void * _M_SingleFrame
Definition: ppltasks.h:160
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:4286
void _TaskInitMaybeFunctor(_Function &_Func, std::true_type)
Initializes a task using a callable object.
Definition: ppltasks.h:3827
_TaskInliningMode_t _InliningMode
Definition: ppltasks.h:1247
_CRTIMP2 void __thiscall _LogWorkItemCompleted()
task()
Constructs a task object.
Definition: ppltasks.h:2911
Definition: ppltasks.h:731
void _Continue(std::false_type, details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3618
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:2076
shared_ptr< _Ty > make_shared(_Types &&..._Args)
Definition: memory:968
void _Init(details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3496
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
volatile _TaskInternalState _M_TaskState
Definition: ppltasks.h:2016
std::vector< char > _Result
Definition: ppltasks.h:654
_UnwrapTaskType< _Type >::_Type _TaskRetType
Definition: ppltasks.h:330
void _ClearStoredException() const
Internal method that observe and clear the exception stored in the task completion event...
Definition: ppltasks.h:2699
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:1476
auto _LogWorkItemAndInvokeUserLambda(_Func _func) const -> decltype(_func())
Definition: ppltasks.h:3462
_TaskCreationCallstack _CreationStack
Definition: ppltasks.h:1246
constexpr pair< typename _Unrefwrap< _Ty1 >::type, typename _Unrefwrap< _Ty2 >::type > make_pair(_Ty1 &&_Val1, _Ty2 &&_Val2)
Definition: utility:323
_ResultHolder< _ResultType > _M_value
Definition: ppltasks.h:2291
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:3845
bool has_cancellation_token() const
Indicates whether a cancellation token was specified by the user
Definition: ppltasks.h:1181
#define bool
Definition: stdbool.h:15
task_continuation_context get_continuation_context() const
Returns the continuation context
Definition: ppltasks.h:1197
_ContinuationTaskHandleBase * _ContinuationList
Definition: ppltasks.h:2028
union Concurrency::details::_ContextCallback::@91 _M_context
_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:3349
_TaskList _M_tasks
Definition: ppltasks.h:2289
__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:1281
#define _THROW_NCEE(x, y)
Definition: xstddef:78
auto _IsValidTaskCtor(_Ty _Param, int, int, int, int) -> decltype(_Param(), std::true_type())
atomic_long _M_exceptionObserved
Definition: ppltasks.h:766
_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:2506
_TaskTypeTraits< _FuncRetType >::_AsyncKind _AsyncKind
Definition: ppltasks.h:427
Definition: ppltasks.h:202
bool _IsCreated()
Definition: ppltasks.h:1641
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: ppltasks.h:3898
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:3242
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:2707
bool operator!=(const task< void > &_Rhs) const
Determines whether two task objects represent different internal tasks.
Definition: ppltasks.h:4244
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplinterface.h:121
_TypeSelectorNoAsync _AsyncKind
Definition: ppltasks.h:435
Definition: pplcancellation_token.h:106
_ContextCallback(const _ContextCallback &_Src)
Definition: ppltasks.h:542
Definition: ppltasks.h:1279
void _ScheduleContinuation(_ContinuationTaskHandleBase *_PTaskHandle)
Schedule the actual continuation. This will either schedule the function on the continuation task's i...
Definition: ppltasks.h:1834
task_options(task_continuation_context _ContinuationContext)
Task option that specify a continuation context. This is valid only for continuations (then) ...
Definition: ppltasks.h:1091
Definition: ppltasks.h:193
std::mutex _M_ContinuationsCritSec
Definition: ppltasks.h:2030
Definition: ppltasks.h:1311
_Ty _ArgType
Definition: ppltasks.h:388
bool _CancelWithExceptionHolder(const std::shared_ptr< _ExceptionHolder > &_ExHolder, bool _PropagatedFromAncestor)
Definition: ppltasks.h:1602
_TaskInternalState
Definition: ppltasks.h:1453
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:2470
__declspec(noinline) auto then(const _Function &_Func) const -> typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_TaskOfType
Adds a continuation task to this task.
Definition: ppltasks.h:3128
details::_Task_completion_event_impl< _Ty >::_TaskList _TaskList
Definition: ppltasks.h:2520
std::exception_ptr _M_stdException
Definition: ppltasks.h:769
std::function< _Unit_type(_Type)> _MakeTToUnitFunc(const std::function< void(_Type)> &_Func)
Definition: ppltasks.h:2310
#define false
Definition: stdbool.h:16
void Set(const _Type &_type)
Definition: ppltasks.h:623
bool is_apartment_aware() const
Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such ...
Definition: ppltasks.h:3321
_ContextCallback(_ContextCallback &&_Src)
Definition: ppltasks.h:547
#define or
Definition: iso646.h:15
auto _GetUnwrappedReturnType(_Ty _Arg, int) -> decltype(_GetUnwrappedType(_Arg))
_TaskCollection_t::_TaskProcHandle_t _UnrealizedChore_t
Definition: ppltasks.h:1285
static _ContextCallback _CaptureCurrent()
Definition: ppltasks.h:502
size_t _M_captureMethod
Definition: ppltasks.h:611
static _ThenImplOptions _CreateOptions(const task_options &_Task_Options, const task_continuation_context &_ContinuationContext, const scheduler_ptr &impl_scheduler)
Definition: ppltasks.h:1250
_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:2719
Definition: ppltasks.h:2258
exception_ptr make_exception_ptr(_Ex _Except) _NOEXCEPT
Definition: exception:371
_Task_impl_base(_CancellationTokenState *_PTokenState, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1463
bool _IsPendingCancel()
Definition: ppltasks.h:1651
task & operator=(task &&_Other)
Replaces the contents of one task object with another.
Definition: ppltasks.h:3098
The task_continuation_context class allows you to specify where you would like a continuation to be e...
Definition: ppltasks.h:915
task(task &&_Other)
Constructs a task object.
Definition: ppltasks.h:3065
void _SetImpl(const typename details::_Task_ptr< _ReturnType >::_Type &_Impl)
Set the implementation of the task to be the supplied implementation.
Definition: ppltasks.h:3388
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:1039
#define _CATCH_ALL
Definition: xstddef:62
_TaskCreationCallstack _M_pTaskCreationCallstack
Definition: ppltasks.h:2043
virtual ~_ContinuationTaskHandle()
Definition: ppltasks.h:3569
void _SetAsync(bool _Async=true)
Sets a property determining whether the task is apartment aware.
Definition: ppltasks.h:3406
_CancellationTokenRegistration * _M_pRegistration
Definition: ppltasks.h:2037
void _ScheduleTask(_UnrealizedChore_t *_PTaskHandle, _TaskInliningMode_t _InliningMode)
Helper function to schedule the task on the Task Collection.
Definition: ppltasks.h:1706
_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:1173
bool _CancelInternal() const
Cancels the task_completion_event.
Definition: ppltasks.h:2525
task_options(const task_options &_TaskOptions)
Task option copy constructor
Definition: ppltasks.h:1152
_Task_impl(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:2064
bool operator==(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:3337
std::vector< bool > Get()
Definition: ppltasks.h:647
_Function _M_function
Definition: ppltasks.h:3552
auto _VoidReturnTypeHelper(_Function _Func, int, int) -> decltype(_Func(std::declval< task< void >>()))
bool _M_fUnwrappedTask
Definition: ppltasks.h:2021
void rethrow_exception(_In_ exception_ptr _Ptr)
Definition: exception:364
bool _IsDone()
Definition: ppltasks.h:2243
Definition: ppltasks.h:369
bool _M_fFromAsync
Definition: ppltasks.h:2019
virtual _Task_ptr_base _GetTaskImplBase() const =0
_T atomic_increment(std::atomic< _T > &_Target)
Definition: pplinterface.h:252
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:2572
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:1140
_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:1016
#define _EMPTY_ARGUMENT
Definition: xstddef:82
_Boolarray operator||(const valarray< _Ty > &_Left, const _Ty &_Right)
Definition: valarray:670
void * _M_pContextCallback
Definition: ppltasks.h:610
Definition: ppltasks.h:353
void _CreateImpl(details::_CancellationTokenState *_Ct, scheduler_ptr _Scheduler)
Create an underlying task implementation.
Definition: ppltasks.h:3357
std::shared_ptr< _ExceptionHolder > _M_exceptionHolder
Definition: ppltasks.h:2292
task_options(std::shared_ptr< _SchedType > _Scheduler)
Task option that specify a scheduler with shared lifetime
Definition: ppltasks.h:1116
_FunctionTypeTraits< _Function, _ReturnType >::_FuncRetType _RetTypeT
Definition: ppltasks.h:405
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:2680
scheduler_ptr _Scheduler
Definition: ppltasks.h:1245
Definition: ppltasks.h:2773
void _TaskInitWithFunctor(const _Function &_Func)
Initializes a task using a lambda, function pointer or function object.
Definition: ppltasks.h:3775
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:2660
bool _IsStarted()
Definition: ppltasks.h:1646
void _TaskInitMaybeFunctor(_Ty &_Param, std::false_type)
Initializes a task using a non-callable object.
Definition: ppltasks.h:4374
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:1273
void _ValidateTaskConstructorArgs(const _Ty &_Param)
Definition: ppltasks.h:2758
task< _Ty > _ArgType
Definition: ppltasks.h:395
#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:117
#define _CRTIMP2
Definition: crtdefs.h:36
Definition: ppltasks.h:496
void _Continue(std::true_type, details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3685
_ReturnType result_type
The type of the result an object of this class produces.
Definition: ppltasks.h:2887
static _Type _Make(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1282
return(_PAIR_TYPE(_FwdIt)(_First, _First))
bool set(_ResultType _Result) const
Sets the task completion event.
Definition: ppltasks.h:2367
Definition: pplcancellation_token.h:221
task_continuation_context _M_continuationContext
Definition: ppltasks.h:1292
std::function< void()> _M_InternalCancellation
Definition: ppltasks.h:2254
_Task_completion_event_impl()
Definition: ppltasks.h:2268
std::shared_ptr< details::_Task_completion_event_impl< _ResultType > > _M_Impl
Definition: ppltasks.h:2607
void set_cancellation_token(cancellation_token _Token)
Sets the given token in the options
Definition: ppltasks.h:1164
void _ClearStoredException() const
Internal method that observe and clear the exception stored in the task completion event...
Definition: ppltasks.h:2486
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:4278
static void __cdecl _Bridge(void *_PData)
Definition: ppltasks.h:450
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: ppltasks.h:85
__declspec(noinline) bool set_exception(_E _Except) const
Definition: ppltasks.h:2413
bool _M_fIsCanceled
Definition: ppltasks.h:2294
_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:3304
_TaskEventLogger & _M_logger
Definition: ppltasks.h:1348
_ContextCallback & operator=(_ContextCallback &&_Src)
Definition: ppltasks.h:563
Definition: pplinterface.h:194
add_rvalue_reference< _Ty >::type declval() _NOEXCEPT
_ResultHolder< _ReturnType > _M_Result
Definition: ppltasks.h:2253
_ImplType _GetImplValue() const
Definition: pplcancellation_token.h:748
integral_constant< bool, true > true_type
Definition: xtr1common:40
bool _Cancel() const
Internal method to cancel the task_completion_event. Any task created using this event will be marked...
Definition: ppltasks.h:2438
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
Definition: ppltasks.h:226
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:144
static void _AsyncInit(const typename _Task_ptr< _ReturnType >::_Type &_OuterTask, const task< _InternalReturnType > &_UnwrappedTask)
Definition: ppltasks.h:1975
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler())
_Type Get()
Definition: ppltasks.h:628
exception_ptr current_exception() _NOEXCEPT
Definition: exception:359
bool _HasCapturedContext() const
Definition: ppltasks.h:573
Helper object used for LWT invocation.
Definition: ppltasks.h:443
task_continuation_context _M_ContinuationContext
Definition: ppltasks.h:1226
std::atomic< long > atomic_long
Atomics
Definition: pplinterface.h:234
The task handle type used to create a 'continuation task'.
Definition: ppltasks.h:3545
void _Continue(std::true_type, details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3703
Definition: xtr1common:86
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:1103
void _SetTaskCreationCallstack(const _TaskCreationCallstack &_Callstack)
Definition: ppltasks.h:1692
_TypeSelectorNoAsync _AsyncKind
Definition: ppltasks.h:346
_Ty _Type
Definition: ppltasks.h:228
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *unexpected_handler)()
auto _IsTaskHelper(_Type _Obj, _Function _Func, int, int) -> decltype(_Func(std::declval< task< _Type >>()), std::true_type())
bool _M_taskPostEventStarted
Definition: ppltasks.h:1315
const std::shared_ptr< _ExceptionHolder > & _GetExceptionHolder()
Definition: ppltasks.h:1671
Definition: ppltasks.h:1457
bool is_apartment_aware() const
Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such ...
Definition: ppltasks.h:4220
_Ty _GetUnwrappedType(task< _Ty >)
The following type traits are used for the create_task function.
void _RunTaskContinuations()
Definition: ppltasks.h:1900
task & operator=(const task &_Other)
Replaces the contents of one task object with another.
Definition: ppltasks.h:3078
static void _RunTask(TaskProc_t _Proc, void *_Parameter, _TaskInliningMode _InliningMode)
Definition: pplwin.h:235
_Unit_type _NormalizedTaskRetType
Definition: ppltasks.h:347
bool _M_HasCancellationToken
Definition: ppltasks.h:1228
bool _HasUserException()
Definition: ppltasks.h:2273
void result_type
The type of the result an object of this class produces.
Definition: ppltasks.h:3905
~_ContextCallback()
Definition: ppltasks.h:509
static task_continuation_context use_default()
Creates the default task continuation context.
Definition: ppltasks.h:936
The base implementation of a first-class task. This class contains all the non-type specific implemen...
Definition: ppltasks.h:1451
void _FinalizeAndRunContinuations(_ReturnType _Result)
Definition: ppltasks.h:2173
_TaskCreationCallstack _GetTaskCreationCallstack()
Definition: ppltasks.h:1687
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:4252
void _SyncCancelAndPropagateException() const
Definition: ppltasks.h:3473
task_options(scheduler_interface &_Scheduler)
Task option that specify a scheduler reference
Definition: ppltasks.h:1128
const details::_Task_ptr< details::_Unit_type >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:4260
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:3425
Definition: ppltasks.h:4443
~_Holder()
Definition: ppltasks.h:465
virtual ~_ContinuationTaskHandleBase()
Definition: ppltasks.h:1305
Definition: pplcancellation_token.h:176
Definition: ppltasks.h:425
bool set() const
Sets the task completion event.
Definition: ppltasks.h:2641
virtual void invoke() const
Definition: ppltasks.h:1408
void _CallInContext(_CallbackFunction _Func) const
Definition: ppltasks.h:593
std::function< void()> _M_func
Definition: ppltasks.h:476
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3370
Definition: ppltasks.h:199
Definition: ppltasks.h:386
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:4169
_ContinuationTaskHandleBase()
Definition: ppltasks.h:1300
_ContextCallback & operator=(const _ContextCallback &_Src)
Definition: ppltasks.h:553
_In_ int _Value
Definition: setjmp.h:173
void _RegisterCancellation(std::weak_ptr< _Task_impl_base > _WeakPtr)
Definition: ppltasks.h:1615
virtual ~_Task_impl()
Definition: ppltasks.h:2069
_TaskProcThunk(const std::function< void()> &_Callback)
Definition: ppltasks.h:445
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:3554
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:491
Definition: ppltasks.h:196
bool _TransitionedToStarted()
Definition: ppltasks.h:2202
#define true
Definition: stdbool.h:17
std::function< _RetTypeT __cdecl(_ArgTypeT)> _StdFuncT
Definition: ppltasks.h:406
Definition: ppltasks.h:195
The _PPLTaskHandle is the strong-typed task handle base. All user task functions need to be wrapped i...
Definition: ppltasks.h:1396
task_group_status task_status
A type that represents the terminal state of a task. Valid values are completed and canceled...
Definition: ppltasks.h:83
bool is_done() const
Determines if the task is completed.
Definition: ppltasks.h:4197
scheduler_ptr get_scheduler() const
Returns the scheduler
Definition: ppltasks.h:1213
constexpr const _Ty &() _Right
Definition: algorithm:3591
_Type _Result
Definition: ppltasks.h:633
Definition: ppltasks.h:138
Definition: ppltasks.h:459
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:2449
Definition: ppltasks.h:1458
void _SetAsync(bool _Async=true)
Definition: ppltasks.h:1682
void _TaskInitNoFunctor(task_completion_event< void > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:4337
void _TaskInitMaybeFunctor(_Ty &_Param, std::false_type)
Initializes a task using a non-callable object.
Definition: ppltasks.h:3836
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:155
_ReturnType _GetResult()
Definition: ppltasks.h:2248
__declspec(noinline)~_ExceptionHolder()
Definition: ppltasks.h:742
_ContinuationArgTypeHelper< _ReturnType, typename details::_FunctionTypeTraits< _Function, _ReturnType >::_Takes_task >::_ArgType _ArgTypeT
Definition: ppltasks.h:404
Definition: ppltasks.h:194