25 #if _MSC_FULL_VER < 160040219
26 #error ERROR: Visual Studio 2010 SP1 or later is required to build ppltasks
36 #if defined (__cplusplus_winrt)
40 #include <winapifamily.h>
41 #ifndef _UITHREADCTXT_SUPPORT
46 #include <winapifamily.h>
48 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
50 #define _UITHREADCTXT_SUPPORT 0
51 #elif WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
53 #define _UITHREADCTXT_SUPPORT 0
55 #define _UITHREADCTXT_SUPPORT 1
60 #define _UITHREADCTXT_SUPPORT 0
65 #if _UITHREADCTXT_SUPPORT
66 #include <uithreadctxt.h>
69 #pragma detect_mismatch("_PPLTASKS_WITH_WINRT", "1")
71 #pragma detect_mismatch("_PPLTASKS_WITH_WINRT", "0")
75 #define _DBG_ONLY(X) X
78 #endif // #ifdef _DEBUG
87 return copy_exception(_Except);
91 #ifndef _PPLTASK_ASYNC_LOGGING
92 #if _MSC_VER >= 1800 && defined(__cplusplus_winrt)
93 #define _PPLTASK_ASYNC_LOGGING 1 // Only enable async logging under dev12 winrt
95 #define _PPLTASK_ASYNC_LOGGING 0
100 #pragma pack(push,_CRT_PACKING)
102 #pragma warning(push)
103 #pragma warning(disable: 28197)
104 #pragma warning(disable: 4100) // Unreferenced formal parameter - needed for document generation
105 #pragma warning(disable: 4127) // constant express in if condition - we use it for meta programming
108 #pragma push_macro("new")
134 template <
typename _Type>
class task;
138 #ifndef PPL_TASK_SAVE_FRAME_COUNT
140 #define PPL_TASK_SAVE_FRAME_COUNT 10
142 #define PPL_TASK_SAVE_FRAME_COUNT 1
154 #if PPL_TASK_SAVE_FRAME_COUNT > 1
155 #if defined(__cplusplus_winrt) && !defined(_DEBUG)
156 #pragma message ("WARNING: Redefinning PPL_TASK_SAVE_FRAME_COUNT under Release build for non-desktop applications is not supported; only one frame will be captured!")
157 #define _CAPTURE_CALLSTACK() ::Concurrency::details::_TaskCreationCallstack::_CaptureSingleFrameCallstack(_ReturnAddress())
159 #define _CAPTURE_CALLSTACK() ::Concurrency::details::_TaskCreationCallstack::_CaptureMultiFramesCallstack(PPL_TASK_SAVE_FRAME_COUNT)
162 #define _CAPTURE_CALLSTACK() ::Concurrency::details::_TaskCreationCallstack::_CaptureSingleFrameCallstack(_ReturnAddress())
190 return ::Concurrency::details::_TaskCollection_t::_Is_cancellation_requested();
205 throw task_canceled();
225 _M_SingleFrame =
nullptr;
257 template<
typename _Ty>
269 template<
typename _T>
281 template <
typename _Ty>
287 template <
typename _Ty>
293 template <
typename _T>
298 #if defined(__cplusplus_winrt)
299 template <
typename _Type>
305 template <
typename _Type>
306 struct _Unhat<
_Type^>
311 value struct _NonUserType {
public:
int _Dummy; };
313 template <
typename _Type,
bool _IsValueTypeOrRefType = __is_val
id_winrt_type(_Type)>
314 struct _ValueTypeOrRefType
316 typedef _NonUserType
_Value;
319 template <
typename _Type>
325 template <
typename _T1,
typename _T2>
326 _T2 _ProgressTypeSelector(Windows::Foundation::IAsyncOperationWithProgress<_T1,_T2>^);
328 template <
typename _T1>
329 _T1 _ProgressTypeSelector(Windows::Foundation::IAsyncActionWithProgress<_T1>^);
331 template <
typename _Type>
332 struct _GetProgressType
334 typedef decltype(_ProgressTypeSelector(stdx::declval<_Type>()))
_Value;
337 template <typename
_Type>
343 template <
typename _T>
348 template <
typename _T1,
typename _T2>
351 template <
typename _T>
355 struct _TaskTypeTraits
359 typedef typename _NormalizeVoidToUnitType<_TaskRetType>::
_Type _NormalizedTaskRetType;
361 static const
bool _IsAsyncTask = _IsAsync;
362 static const
bool _IsUnwrappedTaskOrAsync = _IsUnwrappedAsyncSelector<_AsyncKind>::
_Value;
365 template<typename
_Type>
368 typedef decltype(((_Type)
nullptr)->GetResults()) _TaskRetType;
369 typedef _TaskRetType _NormalizedTaskRetType;
372 static const
bool _IsAsyncTask = true;
373 static const
bool _IsUnwrappedTaskOrAsync = _IsUnwrappedAsyncSelector<_AsyncKind>::_Value;
377 template <
typename _Type>
380 static const bool _Value =
false;
383 template <
typename _Type,
bool _IsAsync = false>
390 static const
bool _IsAsyncTask =
false;
405 static const bool _IsAsyncTask =
false;
406 static const bool _IsUnwrappedTaskOrAsync =
false;
409 template<
typename _Type>
416 template <
typename _Function,
typename _Type>
auto _ReturnTypeHelper(_Type t, _Function _Func,
int,
int) -> decltype(_Func(
_To_task(t)));
417 template <
typename _Function,
typename _Type>
auto _ReturnTypeHelper(_Type t, _Function _Func,
int, ...) -> decltype(_Func(t));
424 template <
typename _Function>
auto _VoidReturnTypeHelper(_Function _Func,
int, ...) -> decltype(_Func());
429 template<
typename _Function,
typename _ExpectedParameterType>
432 typedef decltype(
_ReturnTypeHelper(stdx::declval<_ExpectedParameterType>(),stdx::declval<_Function>(), 0, 0)) _FuncRetType;
438 template<typename _Function>
445 template<typename _Function, typename _ReturnType>
466 template <
typename _TaskType,
typename _FuncRetType>
478 static const bool _IsAsyncTask =
false;
479 static const bool _IsUnwrappedTaskOrAsync =
false;
542 #if defined (__cplusplus_winrt)
558 _ContextCallback(
bool _DeferCapture =
false)
562 _M_context._M_captureMethod = _S_captureDeferred;
566 _M_context._M_pContextCallback =
nullptr;
571 void _Resolve(
bool _CaptureCurrent)
573 if(_M_context._M_captureMethod == _S_captureDeferred)
575 _M_context._M_pContextCallback =
nullptr;
579 if (_IsCurrentOriginSTA())
583 #if _UITHREADCTXT_SUPPORT
587 HRESULT _Hr = CaptureUiThreadContext(&_M_context._M_pContextCallback);
590 _M_context._M_pContextCallback =
nullptr;
600 HRESULT _Hr = CoGetObjectContext(IID_IContextCallback, reinterpret_cast<void **>(&_M_context._M_pContextCallback));
603 _M_context._M_pContextCallback =
nullptr;
607 _ContextCallback(
const _ContextCallback&
_Src)
609 _Assign(_Src._M_context._M_pContextCallback);
612 _ContextCallback(_ContextCallback&&
_Src)
614 _M_context._M_pContextCallback =
_Src._M_context._M_pContextCallback;
615 _Src._M_context._M_pContextCallback =
nullptr;
618 _ContextCallback& operator=(
const _ContextCallback&
_Src)
623 _Assign(_Src._M_context._M_pContextCallback);
628 _ContextCallback& operator=(_ContextCallback&& _Src)
632 _M_context._M_pContextCallback = _Src._M_context._M_pContextCallback;
633 _Src._M_context._M_pContextCallback =
nullptr;
638 bool _HasCapturedContext()
const
640 _ASSERTE(_M_context._M_captureMethod != _S_captureDeferred);
641 return (_M_context._M_pContextCallback !=
nullptr);
644 void _CallInContext(_CallbackFunction _Func)
const
646 if (!_HasCapturedContext())
652 ComCallData callData;
653 ZeroMemory(&callData,
sizeof(callData));
654 callData.pUserDefined =
reinterpret_cast<void *
>(&_Func);
656 HRESULT _Hr = _M_context._M_pContextCallback->ContextCallback(&_Bridge, &callData, IID_ICallbackWithNoReentrancyToApplicationSTA, 5,
nullptr);
659 throw ::Platform::Exception::CreateException(_Hr);
664 bool operator==(
const _ContextCallback& _Rhs)
const
666 return (_M_context._M_pContextCallback == _Rhs._M_context._M_pContextCallback);
669 bool operator!=(
const _ContextCallback& _Rhs)
const
677 if (_M_context._M_captureMethod != _S_captureDeferred && _M_context._M_pContextCallback !=
nullptr)
679 _M_context._M_pContextCallback->Release();
683 void _Assign(IContextCallback *_PContextCallback)
685 _M_context._M_pContextCallback = _PContextCallback;
686 if (_M_context._M_captureMethod != _S_captureDeferred && _M_context._M_pContextCallback !=
nullptr)
688 _M_context._M_pContextCallback->AddRef();
692 static HRESULT __stdcall _Bridge(ComCallData *_PParam)
694 _CallbackFunction *pFunc =
reinterpret_cast<_CallbackFunction *
>(_PParam->pUserDefined);
700 static bool _IsCurrentOriginSTA()
703 APTTYPEQUALIFIER _AptTypeQualifier;
705 HRESULT hr = CoGetApartmentType(&_AptType, &_AptTypeQualifier);
714 case APTTYPE_MAINSTA:
726 IContextCallback *_M_pContextCallback;
727 size_t _M_captureMethod;
730 static const size_t _S_captureDeferred = 1;
788 template<
typename _Type>
791 void Set(
const _Type& _type)
804 #if defined (__cplusplus_winrt)
806 template<
typename _Type>
809 void Set(_Type^
const & _type)
816 return _M_Result.
Get();
827 template<
typename _Type>
828 struct _ResultHolder<
std::
vector<_Type^>>
830 void Set(
const std::vector<_Type^>& _type)
834 for (
auto _PTask = _type.begin(); _PTask != _type.end(); ++_PTask)
836 _Result.emplace_back(*_PTask);
840 std::vector<_Type^> Get()
843 std::vector<_Type^> _Return;
844 _Return.reserve(_Result.size());
846 for (
auto _PTask = _Result.begin(); _PTask != _Result.end(); ++_PTask)
848 _Return.push_back(_PTask->Get());
854 std::vector< ::Platform::Agile<_Type^> > _Result;
857 template<
typename _Type>
858 struct _ResultHolder<
std::
pair<_Type^, void*> >
860 void Set(
const std::pair<_Type^, size_t>& _type)
865 std::pair<_Type^, size_t> Get()
870 std::pair< ::Platform::Agile<_Type^>,
size_t> _M_Result;
883 #if defined (__cplusplus_winrt)
884 if (_M_winRTException !=
nullptr)
892 _M_exceptionObserved(0), _M_stdException(_E), _M_stackTrace(_stackTrace)
893 #
if defined (__cplusplus_winrt)
894 , _M_winRTException(nullptr)
899 #if defined (__cplusplus_winrt)
901 _M_exceptionObserved(0), _M_winRTException(_E), _M_stackTrace(_stackTrace)
909 if (_M_exceptionObserved == 0)
920 if (_M_exceptionObserved == 0)
925 #if defined (__cplusplus_winrt)
926 if (_M_winRTException !=
nullptr)
928 throw _M_winRTException;
940 #if defined (__cplusplus_winrt)
941 ::Platform::Exception^ _M_winRTException;
952 #if defined (__cplusplus_winrt)
953 template<
typename _AsyncOperationType,
typename _CompletionHandlerType,
typename _Result>
957 ref struct _AsyncInfoImpl
abstract : Windows::Foundation::IAsyncOperation<_Result>
963 Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ _M_CompletedHandler;
965 _AsyncInfoImpl( _AsyncOperationType _AsyncInfo ) : _M_asyncInfo(_AsyncInfo) {}
968 virtual void Cancel() { _M_asyncInfo.
Get()->Cancel(); }
969 virtual void Close() { _M_asyncInfo.
Get()->Close(); }
971 virtual property Windows::Foundation::HResult ErrorCode
973 Windows::Foundation::HResult
get()
975 return _M_asyncInfo.
Get()->ErrorCode;
979 virtual property UINT Id
983 return _M_asyncInfo.
Get()->Id;
987 virtual property Windows::Foundation::AsyncStatus Status
989 Windows::Foundation::AsyncStatus
get()
991 return _M_asyncInfo.
Get()->Status;
995 virtual _Result GetResults() {
throw std::runtime_error(
"derived class must implement"); }
997 virtual property Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ Completed
999 Windows::Foundation::AsyncOperationCompletedHandler<_Result>^
get()
1001 return _M_CompletedHandler;
1004 void set(Windows::Foundation::AsyncOperationCompletedHandler<_Result>^ value)
1006 _M_CompletedHandler = value;
1007 _M_asyncInfo.
Get()->Completed =
ref new _CompletionHandlerType([&](_AsyncOperationType, Windows::Foundation::AsyncStatus
status) {
1008 _M_CompletedHandler->Invoke(
this, status);
1017 template<
typename _Result,
typename _Progress>
1018 ref struct _IAsyncOperationWithProgressToAsyncOperationConverter
sealed :
1019 _AsyncInfoImpl<Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^,
1020 Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_Result,_Progress>,
1024 _IAsyncOperationWithProgressToAsyncOperationConverter(Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^ _Operation) :
1025 _AsyncInfoImpl<
Windows::Foundation::IAsyncOperationWithProgress<_Result,_Progress>^,
1026 Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_Result,_Progress>,
1027 _Result>(_Operation) {}
1030 virtual _Result GetResults()
override {
return _M_asyncInfo.
Get()->GetResults(); }
1036 ref struct _IAsyncActionToAsyncOperationConverter
sealed :
1037 _AsyncInfoImpl<Windows::Foundation::IAsyncAction^,
1038 Windows::Foundation::AsyncActionCompletedHandler,
1039 details::_Unit_type>
1042 _IAsyncActionToAsyncOperationConverter(Windows::Foundation::IAsyncAction^ _Operation) :
1043 _AsyncInfoImpl<
Windows::Foundation::IAsyncAction^,
1044 Windows::Foundation::AsyncActionCompletedHandler,
1045 details::_Unit_type>(_Operation) {}
1051 _M_asyncInfo.
Get()->GetResults();
1059 template<
typename _Progress>
1060 ref struct _IAsyncActionWithProgressToAsyncOperationConverter
sealed :
1061 _AsyncInfoImpl<Windows::Foundation::IAsyncActionWithProgress<_Progress>^,
1062 Windows::Foundation::AsyncActionWithProgressCompletedHandler<_Progress>,
1063 details::_Unit_type>
1066 _IAsyncActionWithProgressToAsyncOperationConverter(Windows::Foundation::IAsyncActionWithProgress<_Progress>^
_Action) :
1067 _AsyncInfoImpl<
Windows::Foundation::IAsyncActionWithProgress<_Progress>^,
1068 Windows::Foundation::AsyncActionWithProgressCompletedHandler<_Progress>,
1069 details::_Unit_type>(_Action) {}
1074 _M_asyncInfo.
Get()->GetResults();
1111 #if defined (__cplusplus_winrt)
1119 #if defined (__cplusplus_winrt)
1137 _Arbitrary._Resolve(
false);
1155 static task_continuation_context use_current()
1157 task_continuation_context _Current(
true);
1158 _Current._Resolve(
true);
1180 _M_hasPresetCreationCallstack =
true;
1181 _M_presetCreationCallstack = _callstack;
1185 _M_hasPresetCreationCallstack =
false;
1207 _M_HasCancellationToken(false),
1208 _M_HasScheduler(false)
1217 _M_CancellationToken(_Token),
1219 _M_HasCancellationToken(true),
1220 _M_HasScheduler(false)
1230 _M_ContinuationContext(_ContinuationContext),
1231 _M_HasCancellationToken(false),
1232 _M_HasScheduler(false)
1241 _M_CancellationToken(_Token),
1242 _M_ContinuationContext(_ContinuationContext),
1243 _M_HasCancellationToken(false),
1244 _M_HasScheduler(false)
1251 template<
typename _SchedType>
1253 : _M_Scheduler(
std::
move(_Scheduler)),
1256 _M_HasCancellationToken(false),
1257 _M_HasScheduler(true)
1265 : _M_Scheduler(&_Scheduler),
1268 _M_HasCancellationToken(false),
1269 _M_HasScheduler(true)
1277 : _M_Scheduler(
std::
move(_Scheduler)),
1280 _M_HasCancellationToken(false),
1281 _M_HasScheduler(true)
1289 : _M_Scheduler(_TaskOptions.get_scheduler()),
1290 _M_CancellationToken(_TaskOptions.get_cancellation_token()),
1291 _M_ContinuationContext(_TaskOptions.get_continuation_context()),
1292 _M_HasCancellationToken(_TaskOptions.has_cancellation_token()),
1293 _M_HasScheduler(_TaskOptions.has_scheduler())
1302 _M_CancellationToken = _Token;
1303 _M_HasCancellationToken =
true;
1311 _M_ContinuationContext = _ContinuationContext;
1319 return _M_HasCancellationToken;
1327 return _M_CancellationToken;
1335 return _M_ContinuationContext;
1343 return _M_HasScheduler;
1351 return _M_Scheduler;
1379 struct _Task_impl_base;
1382 template<
typename _ReturnType>
1385 typedef std::shared_ptr<_Task_impl<_ReturnType>>
_Type;
1402 virtual _Task_ptr_base _GetTaskImplBase()
const = 0;
1412 #if _PPLTASK_ASYNC_LOGGING
1414 const ::Platform::Guid _PPLTaskCausalityPlatformID(0x7A76B220, 0xA758, 0x4E6E, 0xB0, 0xE0, 0xD7, 0xC6, 0xD7, 0x4A, 0x88, 0xFE);
1416 __declspec(selectany) volatile
long _isCausalitySupported = 0;
1418 inline
bool _IsCausalitySupported()
1420 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
1421 if (_isCausalitySupported == 0)
1423 long _causality = 1;
1424 OSVERSIONINFOEX _osvi = {};
1425 _osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
1428 _osvi.dwMajorVersion = 6;
1429 _osvi.dwMinorVersion = 3;
1431 DWORDLONG _conditionMask = 0;
1432 VER_SET_CONDITION( _conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL );
1433 VER_SET_CONDITION( _conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL );
1435 if ( ::VerifyVersionInfo(&_osvi, VER_MAJORVERSION | VER_MINORVERSION, _conditionMask))
1440 _isCausalitySupported = _causality;
1441 return _causality == 2;
1444 return _isCausalitySupported == 2 ?
true :
false;
1451 struct _TaskEventLogger
1453 _Task_impl_base *_M_task;
1455 bool _M_taskPostEventStarted;
1458 void _LogScheduleTask(
bool _isContinuation)
1460 if (details::_IsCausalitySupported())
1462 ::Windows::Foundation::Diagnostics::AsyncCausalityTracer::TraceOperationCreation(::Windows::Foundation::Diagnostics::CausalityTraceLevel::Required, ::Windows::Foundation::Diagnostics::CausalitySource::Library,
1463 _PPLTaskCausalityPlatformID, reinterpret_cast<unsigned long long>(_M_task),
1464 _isContinuation ?
"Concurrency::PPLTask::ScheduleContinuationTask" :
"Concurrency::PPLTask::ScheduleTask", 0);
1465 _M_scheduled =
true;
1472 if (details::_IsCausalitySupported())
1474 ::Windows::Foundation::Diagnostics::AsyncCausalityTracer::TraceOperationRelation(::Windows::Foundation::Diagnostics::CausalityTraceLevel::Important, ::Windows::Foundation::Diagnostics::CausalitySource::Library,
1475 _PPLTaskCausalityPlatformID, reinterpret_cast<unsigned long long>(_M_task), ::Windows::Foundation::Diagnostics::CausalityRelation::Cancel);
1481 void _LogTaskCompleted();
1484 void _LogTaskExecutionStarted() { }
1487 void _LogTaskExecutionCompleted()
1489 if (_M_taskPostEventStarted && details::_IsCausalitySupported())
1491 ::Windows::Foundation::Diagnostics::AsyncCausalityTracer::TraceSynchronousWorkCompletion(::Windows::Foundation::Diagnostics::CausalityTraceLevel::Required, ::Windows::Foundation::Diagnostics::CausalitySource::Library,
1492 ::Windows::Foundation::Diagnostics::CausalitySynchronousWork::CompletionNotification);
1497 void _LogWorkItemStarted()
1499 if (details::_IsCausalitySupported())
1501 ::Windows::Foundation::Diagnostics::AsyncCausalityTracer::TraceSynchronousWorkStart(::Windows::Foundation::Diagnostics::CausalityTraceLevel::Required, ::Windows::Foundation::Diagnostics::CausalitySource::Library,
1502 _PPLTaskCausalityPlatformID, reinterpret_cast<unsigned long long>(_M_task), ::Windows::Foundation::Diagnostics::CausalitySynchronousWork::Execution);
1507 void _LogWorkItemCompleted()
1509 if (details::_IsCausalitySupported())
1511 ::Windows::Foundation::Diagnostics::AsyncCausalityTracer::TraceSynchronousWorkCompletion(::Windows::Foundation::Diagnostics::CausalityTraceLevel::Required, ::Windows::Foundation::Diagnostics::CausalitySource::Library,
1512 ::Windows::Foundation::Diagnostics::CausalitySynchronousWork::Execution);
1514 ::Windows::Foundation::Diagnostics::AsyncCausalityTracer::TraceSynchronousWorkStart(::Windows::Foundation::Diagnostics::CausalityTraceLevel::Required, ::Windows::Foundation::Diagnostics::CausalitySource::Library,
1515 _PPLTaskCausalityPlatformID, reinterpret_cast<unsigned long long>(_M_task), ::Windows::Foundation::Diagnostics::CausalitySynchronousWork::CompletionNotification);
1516 _M_taskPostEventStarted =
true;
1520 _TaskEventLogger(_Task_impl_base *_task): _M_task(_task)
1522 _M_scheduled =
false;
1523 _M_taskPostEventStarted =
false;
1528 struct _TaskWorkItemRAIILogger
1530 _TaskEventLogger &_M_logger;
1531 _TaskWorkItemRAIILogger(_TaskEventLogger &_taskHandleLogger): _M_logger(_taskHandleLogger)
1533 _M_logger._LogWorkItemStarted();
1536 ~_TaskWorkItemRAIILogger()
1538 _M_logger._LogWorkItemCompleted();
1540 _TaskWorkItemRAIILogger &operator =(
const _TaskWorkItemRAIILogger &);
1577 template<
typename _ReturnType,
typename _DerivedTaskHandle,
typename _BaseTaskHandle>
1587 _M_pTask->_M_taskEventLogger._LogTaskCompleted();
1595 if (!_M_pTask->_TransitionedToStarted())
1597 static_cast<const _DerivedTaskHandle *
>(
this)->_SyncCancelAndPropagateException();
1601 _M_pTask->_M_taskEventLogger._LogTaskExecutionStarted();
1605 static_cast<const _DerivedTaskHandle *
>(
this)->_Perform();
1609 _M_pTask->_Cancel(
true);
1613 _M_pTask->_Cancel(
true);
1615 #if defined (__cplusplus_winrt)
1616 catch(::Platform::Exception^ _E)
1618 _M_pTask->_CancelWithException(_E);
1625 _M_pTask->_M_taskEventLogger._LogTaskExecutionCompleted();
1658 : _M_TaskState(_Created),
1659 _M_fFromAsync(false), _M_fUnwrappedTask(false),
1660 _M_pRegistration(nullptr), _M_Continuations(nullptr), _M_TaskCollection(_Scheduler_arg),
1661 _M_taskEventLogger(this)
1664 _M_pTokenState = _PTokenState;
1665 _ASSERTE(_M_pTokenState !=
nullptr);
1667 _M_pTokenState->_Reference();
1672 _ASSERTE(_M_pTokenState !=
nullptr);
1675 _M_pTokenState->_Release();
1681 bool _DoWait =
true;
1683 #if defined (__cplusplus_winrt)
1684 if (_IsNonBlockingThread())
1688 if (!_IsCompleted() && !_IsCanceled())
1711 _M_TaskCollection._Wait();
1728 _M_TaskCollection._RunAndWait();
1743 #if defined (__cplusplus_winrt)
1744 catch(::Platform::Exception^ _E)
1747 if(!_HasUserException())
1749 _CancelWithException(_E);
1752 _M_exceptionHolder->_RethrowUserException();
1758 if(!_HasUserException())
1763 _M_exceptionHolder->_RethrowUserException();
1770 if (_M_fUnwrappedTask)
1772 _M_TaskCollection._Wait();
1777 if (_HasUserException())
1779 _M_exceptionHolder->_RethrowUserException();
1781 else if (_IsCanceled())
1808 virtual bool _CancelAndRunContinuations(
bool _SynchronousCancel,
bool _UserException,
bool _PropagatedFromAncestor,
const std::shared_ptr<_ExceptionHolder>& _ExHolder) = 0;
1813 return _CancelAndRunContinuations(_SynchronousCancel,
false,
false, _M_exceptionHolder);
1819 return _CancelAndRunContinuations(
true,
true, _PropagatedFromAncestor, _ExHolder);
1822 #if defined (__cplusplus_winrt)
1823 bool _CancelWithException(::Platform::Exception^ _Exception)
1827 return _CancelAndRunContinuations(
true,
true,
false, std::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack()));
1835 return _CancelAndRunContinuations(
true,
true,
false, std::make_shared<_ExceptionHolder>(_Exception, _GetTaskCreationCallstack()));
1842 auto _CancellationCallback = [_WeakPtr](){
1845 auto _task = _WeakPtr.lock();
1846 if (_task !=
nullptr)
1847 _task->_Cancel(
false);
1851 _M_pTokenState->_RegisterCallback(_M_pRegistration);
1856 if (_M_pRegistration !=
nullptr)
1858 _M_pTokenState->_DeregisterCallback(_M_pRegistration);
1859 _M_pRegistration->_Release();
1860 _M_pRegistration =
nullptr;
1866 return (_M_TaskState == _Created);
1871 return (_M_TaskState == _Started);
1876 return (_M_TaskState == _PendingCancel);
1891 return static_cast<bool>(_M_exceptionHolder);
1897 return _M_exceptionHolder;
1902 return _M_fFromAsync;
1912 return _M_pTaskCreationCallstack;
1917 _M_pTaskCreationCallstack = _Callstack;
1933 _M_TaskCollection._ScheduleTask(_PTaskHandle, _InliningMode);
1969 if (_HasUserException())
1973 _ImplBase->_CancelWithExceptionHolder(_GetExceptionHolder(),
true);
1979 _ImplBase->_Cancel(
true);
1987 _ASSERTE(!_ImplBase->_IsCanceled());
1988 return _ImplBase->_ScheduleContinuationTask(_PTaskHandle);
1992 delete _PTaskHandle;
1999 _M_taskEventLogger._LogScheduleTask(
true);
2032 auto _PTaskHandle1 = _PTaskHandle;
2037 #if defined (__cplusplus_winrt)
2038 catch(::Platform::Exception^ _E)
2040 _TaskImplPtr->_CancelWithException(_E);
2069 enum { _Nothing, _Schedule, _Cancel, _CancelWithException } _Do = _Nothing;
2079 else if (_IsCanceled())
2081 if (_HasUserException())
2083 _Do = _CancelWithException;
2093 _PTaskHandle->
_M_next = _M_Continuations;
2094 _M_Continuations = _PTaskHandle;
2113 delete _PTaskHandle;
2116 case _CancelWithException:
2120 _PTaskHandle->
_GetTaskImplBase()->_CancelWithExceptionHolder(_GetExceptionHolder(),
true);
2122 delete _PTaskHandle;
2138 _M_Continuations =
nullptr;
2144 _RunContinuation(_Cur);
2149 #if defined (__cplusplus_winrt)
2150 static bool _IsNonBlockingThread()
2153 APTTYPEQUALIFIER _AptTypeQualifier;
2155 HRESULT hr = CoGetApartmentType(&_AptType, &_AptTypeQualifier);
2164 case APTTYPE_MAINSTA:
2168 switch(_AptTypeQualifier)
2174 case APTTYPEQUALIFIER_NA_ON_STA:
2175 case APTTYPEQUALIFIER_NA_ON_MAINSTA:
2183 #if _UITHREADCTXT_SUPPORT
2186 if (SUCCEEDED(CaptureUiThreadContext(
nullptr)))
2195 template<
typename _ReturnType,
typename>
2211 _AsyncOp->Completed =
ref new Windows::Foundation::AsyncOperationCompletedHandler<_ReturnType>(
2214 if (_Status == Windows::Foundation::AsyncStatus::Canceled)
2216 _OuterTask->_Cancel(
true);
2218 else if (_Status == Windows::Foundation::AsyncStatus::Error)
2220 _OuterTask->_CancelWithException(::Platform::Exception::ReCreateException(static_cast<int>(_Operation->ErrorCode.Value)));
2224 _ASSERTE(_Status == Windows::Foundation::AsyncStatus::Completed);
2225 _OuterTask->_FinalizeAndRunContinuations(_Operation->GetResults());
2235 _OuterTask->_SetUnwrappedAsyncOp(_AsyncOp);
2239 template<
typename _ReturnType,
typename _InternalReturnType>
2242 _ASSERTE(_OuterTask->_M_fUnwrappedTask && !_OuterTask->_IsCanceled());
2253 if (_AncestorTask.
_GetImpl()->_IsCompleted())
2255 _OuterTask->_FinalizeAndRunContinuations(_AncestorTask.
_GetImpl()->_GetResult());
2260 if (_AncestorTask.
_GetImpl()->_HasUserException())
2264 _OuterTask->_CancelWithExceptionHolder(_AncestorTask.
_GetImpl()->_GetExceptionHolder(),
false);
2268 _OuterTask->_Cancel(
true);
2277 return _M_TaskCollection._GetScheduler();
2317 #if _PPLTASK_ASYNC_LOGGING
2322 ::Windows::Foundation::AsyncStatus _State;
2323 if (_M_task->_IsCompleted())
2324 _State = ::Windows::Foundation::AsyncStatus::Completed;
2325 else if (_M_task->_HasUserException())
2326 _State = ::Windows::Foundation::AsyncStatus::Error;
2328 _State = ::Windows::Foundation::AsyncStatus::Canceled;
2330 if (details::_IsCausalitySupported())
2332 ::Windows::Foundation::Diagnostics::AsyncCausalityTracer::TraceOperationCompletion(::Windows::Foundation::Diagnostics::CausalityTraceLevel::Required, ::Windows::Foundation::Diagnostics::CausalitySource::Library,
2333 _PPLTaskCausalityPlatformID, reinterpret_cast<unsigned long long>(_M_task), _State);
2348 template<
typename _ReturnType>
2349 struct _Task_impl :
public _Task_impl_base
2351 #if defined (__cplusplus_winrt)
2353 #endif // defined(__cplusplus_winrt)
2357 #if defined (__cplusplus_winrt)
2358 _M_unwrapped_async_op =
nullptr;
2366 _DeregisterCancellation();
2369 virtual bool _CancelAndRunContinuations(
bool _SynchronousCancel,
bool _UserException,
bool _PropagatedFromAncestor,
const std::shared_ptr<_ExceptionHolder> & _ExceptionHolder_arg)
2371 enum { _Nothing, _RunContinuations, _Cancel } _Do = _Nothing;
2376 _ASSERTE(_SynchronousCancel && !_IsCompleted());
2378 _ASSERTE(!_IsCanceled() || _PropagatedFromAncestor);
2391 _M_exceptionHolder = _ExceptionHolder_arg;
2398 if (_IsCompleted() || _IsCanceled() || (_IsPendingCancel() && !_SynchronousCancel))
2400 _ASSERTE(!_IsCompleted() || !_HasUserException());
2403 _ASSERTE(!_SynchronousCancel || !_HasUserException());
2406 if (_SynchronousCancel)
2413 _Do = _RunContinuations;
2428 _M_TaskState = _PendingCancel;
2430 _M_taskEventLogger._LogCancelTask();
2438 #if defined (__cplusplus_winrt)
2439 if (_M_unwrapped_async_op !=
nullptr)
2442 _M_unwrapped_async_op->Cancel();
2445 _M_TaskCollection._Cancel();
2448 case _RunContinuations:
2451 _M_TaskCollection._Complete();
2453 if (_M_Continuations)
2467 _M_Result.Set(_Result);
2478 _ASSERTE(!_HasUserException() && !_IsCompleted());
2487 _M_TaskCollection._Complete();
2488 _RunTaskContinuations();
2499 if (_IsPendingCancel())
2503 _M_TaskState = _Started;
2507 #if defined (__cplusplus_winrt)
2508 void _SetUnwrappedAsyncOp(_AsyncOperationType^ _AsyncOp)
2512 if (_IsPendingCancel())
2519 _M_unwrapped_async_op = _AsyncOp;
2527 return _IsCompleted() || _IsCanceled();
2532 return _M_Result.Get();
2536 #if defined (__cplusplus_winrt)
2537 _AsyncOperationType^ _M_unwrapped_async_op;
2541 template<
typename _ResultType>
2553 _M_fHasValue(false), _M_fIsCanceled(false)
2559 return _M_exceptionHolder !=
nullptr;
2564 for(
auto _TaskIt = _M_tasks.begin(); _TaskIt != _M_tasks.end(); ++_TaskIt )
2566 _ASSERTE(!_M_fHasValue && !_M_fIsCanceled);
2568 (*_TaskIt)->_Cancel(
true);
2584 return [=]() -> _Unit_type { _Func();
return _Unit_type(); };
2587 template <
typename _Type>
2590 return [=](
_Unit_type) -> _Type {
return _Func(); };
2593 template <
typename _Type>
2596 return [=](_Type t) -> _Unit_type { _Func(t);
return _Unit_type(); };
2622 template<
typename _ResultType>
2631 : _M_Impl(
std::
make_shared<details::_Task_completion_event_impl<_ResultType>>())
2651 bool set(_ResultType _Result)
const
2660 bool _RunContinuations =
false;
2664 if (!_IsTriggered())
2666 _M_Impl->_M_value.Set(_Result);
2667 _M_Impl->_M_fHasValue =
true;
2669 _Tasks.swap(_M_Impl->_M_tasks);
2670 _RunContinuations =
true;
2674 if (_RunContinuations)
2676 for(
auto _TaskIt = _Tasks.begin(); _TaskIt != _Tasks.end(); ++_TaskIt )
2679 if ((*_TaskIt)->_IsPendingCancel())
2680 (*_TaskIt)->_Cancel(
true);
2686 (*_TaskIt)->_FinalizeAndRunContinuations(_M_Impl->_M_value.Get());
2689 if (_M_Impl->_HasUserException())
2691 _M_Impl->_M_exceptionHolder.reset();
2699 template<
typename _E>
2701 bool set_exception(_E _Except) const
2728 return _CancelInternal();
2735 template<
typename _ExHolderType>
2739 if(_StoreException(_ExHolder, _SetExceptionAddressHint))
2741 _Canceled = _CancelInternal();
2756 template<
typename _ExHolderType>
2760 if (!_IsTriggered() && !_M_Impl->_HasUserException())
2764 _M_Impl->_M_exceptionHolder = _ToExceptionHolder(_ExHolder, _SetExceptionAddressHint);
2775 return _M_Impl->_M_fHasValue || _M_Impl->_M_fIsCanceled;
2787 return std::make_shared<details::_ExceptionHolder>(_ExceptionPtr, _SetExceptionAddressHint);
2791 template <
typename T>
friend class task;
2804 if (_M_Impl->_M_fIsCanceled)
2810 bool _Cancel =
false;
2814 if (!_M_Impl->_M_fIsCanceled)
2816 _M_Impl->_M_fIsCanceled =
true;
2817 _Tasks.swap(_M_Impl->_M_tasks);
2822 bool _UserException = _M_Impl->_HasUserException();
2826 for(
auto _TaskIt = _Tasks.begin(); _TaskIt != _Tasks.end(); ++_TaskIt )
2831 (*_TaskIt)->_CancelWithExceptionHolder(_M_Impl->_M_exceptionHolder,
true);
2835 (*_TaskIt)->_Cancel(
true);
2851 if(_M_Impl->_HasUserException())
2853 _TaskParam->_CancelWithExceptionHolder(_M_Impl->_M_exceptionHolder,
true);
2855 else if (_M_Impl->_M_fHasValue)
2857 _TaskParam->_FinalizeAndRunContinuations(_M_Impl->_M_value.Get());
2861 _M_Impl->_M_tasks.push_back(_TaskParam);
2865 std::shared_ptr<details::_Task_completion_event_impl<_ResultType>>
_M_Impl;
2904 template<
typename _E>
2906 bool set_exception(_E _Except) const
2931 _M_unitEvent._Cancel();
2938 void _Cancel(
const std::shared_ptr<details::_ExceptionHolder>& _ExHolder)
const
2940 _M_unitEvent._Cancel(_ExHolder);
2950 return _M_unitEvent._StoreException(_ExHolder);
2958 return _M_unitEvent._IsTriggered();
2962 template <
typename T>
friend class task;
2970 _M_unitEvent._RegisterTask(_TaskParam);
2986 template<
typename _ReturnType,
typename _Ty>
2989 #if defined (__cplusplus_winrt)
2991 template<
typename _ReturnType,
typename _Ty>
2996 template<
typename _ReturnType,
typename _Ty>
2999 template<
typename _ReturnType,
typename _Ty>
3003 template<
typename _ReturnType,
typename _Ty>
3006 template<
typename _ReturnType,
typename _Ty>
3009 static_assert(std::is_same<decltype(_IsValidTaskCtor<_ReturnType>(_Param,0,0,0,0)),
std::true_type>::value,
3010 #
if defined (__cplusplus_winrt)
3011 "incorrect argument for task constructor; can be a callable object, an asynchronous operation, or a task_completion_event"
3013 "incorrect argument for task constructor; can be a callable object or a task_completion_event"
3016 #if defined (__cplusplus_winrt)
3018 "incorrect template argument for task; consider using the return type of the async operation");
3022 #if defined (__cplusplus_winrt)
3026 template<
typename _Ty>
3027 static auto _IsValidCreateAsync(_Ty _Param,
int,
int,
int,
int) -> decltype(_Param(),
std::true_type());
3030 template<
typename _Ty>
3034 template<
typename _Ty>
3035 static auto _IsValidCreateAsync(_Ty _Param,
int,
int, ...) -> decltype(_Param(details::_ProgressReporterCtorArgType()),
std::true_type());
3038 template<
typename _Ty>
3042 template<
typename _Ty>
3050 template<
typename _InpType,
typename _OutType>
3054 static auto _Perform(std::function<_OutType(_InpType)> _Func) -> decltype(_Func)
3060 template<
typename _OutType>
3064 static auto _Perform(std::function<_OutType(
void)> _Func) -> decltype(details::_MakeUnitToTFunc<_OutType>(_Func))
3066 return details::_MakeUnitToTFunc<_OutType>(_Func);
3070 template<
typename _InType>
3074 static auto _Perform(std::function<
void(_InType)> _Func) -> decltype(details::_MakeTToUnitFunc<_InType>(_Func))
3076 return details::_MakeTToUnitFunc<_InType>(_Func);
3092 template<
typename _RetType>
3096 static auto _Perform(std::function<_RetType(
void)> _Func) -> decltype(_Func)
3126 template<
typename _ReturnType>
3199 template<
typename _Ty>
3201 explicit
task(_Ty _Param)
3204 details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
3247 template<
typename _Ty>
3251 details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
3253 _CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
3327 if (
this != &_Other)
3329 _M_Impl = _Other._M_Impl;
3347 if (
this != &_Other)
3374 template<
typename _Function>
3376 auto then(const _Function& _Func) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
3380 return _ThenImpl<_ReturnType, _Function>(_Func, _TaskOptions);
3407 template<
typename _Function>
3409 auto then(const _Function& _Func,
task_options _TaskOptions) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
3412 return _ThenImpl<_ReturnType, _Function>(_Func, _TaskOptions);
3443 template<
typename _Function>
3447 task_options _TaskOptions(_CancellationToken, _ContinuationContext);
3449 return _ThenImpl<_ReturnType, _Function>(_Func, _TaskOptions);
3465 throw invalid_operation(
"wait() cannot be called on a default constructed task.");
3468 return _M_Impl->_Wait();
3483 _ReturnType
get()
const
3487 throw invalid_operation(
"get() cannot be called on a default constructed task.");
3495 return _M_Impl->_GetResult();
3511 throw invalid_operation(
"is_done() cannot be called on a default constructed task.");
3514 return _M_Impl->_IsDone();
3527 throw invalid_operation(
"scheduler() cannot be called on a default constructed task.");
3530 return _M_Impl->_GetScheduler();
3544 throw invalid_operation(
"is_apartment_aware() cannot be called on a default constructed task.");
3546 return _M_Impl->_IsApartmentAware();
3558 return (_M_Impl == _Rhs._M_Impl);
3582 _M_Impl->_RegisterCancellation(_M_Impl);
3617 _GetImpl()->_SetAsync(
_Async);
3625 _GetImpl()->_SetTaskCreationCallstack(_callstack);
3633 template<
typename _Function>
3638 auto _Scheduler = _GetImpl()->_GetScheduler();
3644 template <
typename T>
friend class task;
3648 template <
typename _InternalReturnType,
typename _Function,
typename _TypeSelection>
3650 details::_PPLTaskHandle<_ReturnType, _InitialTaskHandle<_InternalReturnType, _Function, _TypeSelection>, details::_UnrealizedChore_t>
3654 : details::_PPLTaskHandle<_ReturnType,
_InitialTaskHandle<_InternalReturnType, _Function, _TypeSelection>, details::_UnrealizedChore_t>::_PPLTaskHandle(_TaskImpl)
3655 , _M_function(_func)
3661 template <
typename _Func>
3670 _Init(_TypeSelection());
3675 this->_M_pTask->_Cancel(
true);
3698 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask, _LogWorkItemAndInvokeUserLambda(_M_function));
3701 #if defined (__cplusplus_winrt)
3709 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
ref new details::_IAsyncActionToAsyncOperationConverter(_LogWorkItemAndInvokeUserLambda(_M_function)));
3721 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
3722 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_InternalReturnType,_ProgressType>(_LogWorkItemAndInvokeUserLambda(_M_function)));
3730 void _Init(details::_TypeSelectorAsyncActionWithProgress)
const
3734 details::_Task_impl_base::_AsyncInit<_ReturnType, _InternalReturnType>(this->_M_pTask,
3735 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(_LogWorkItemAndInvokeUserLambda(_M_function)));
3744 template <
typename _InternalReturnType,
typename _ContinuationReturnType,
typename _Function,
typename _IsTaskBased,
typename _TypeSelection>
3747 _ContinuationTaskHandle<_InternalReturnType, _ContinuationReturnType, _Function, _IsTaskBased, _TypeSelection>, details::_ContinuationTaskHandleBase>
3757 : details::_PPLTaskHandle<typename details::_NormalizeVoidToUnitType<_ContinuationReturnType>::_Type,
3758 _ContinuationTaskHandle<_InternalReturnType, _ContinuationReturnType, _Function, _IsTaskBased, _TypeSelection>, details::_ContinuationTaskHandleBase>
3759 ::_PPLTaskHandle(_ContinuationImpl)
3760 , _M_ancestorTaskImpl(_AncestorImpl)
3761 , _M_function(_Func)
3763 this->_M_isTaskBasedContinuation = _IsTaskBased::value;
3764 this->_M_continuationContext = _Context;
3765 this->_M_continuationContext.
_Resolve(_AncestorImpl->_IsApartmentAware());
3766 this->_M_inliningMode = _InliningMode;
3771 template <
typename _Func,
typename _Arg>
3775 return _func(std::forward<_Arg>(_value));
3780 _Continue(_IsTaskBased(), _TypeSelection());
3785 if (_M_ancestorTaskImpl->_HasUserException())
3789 this->_M_pTask->_CancelWithExceptionHolder(_M_ancestorTaskImpl->_GetExceptionHolder(),
true);
3795 this->_M_pTask->_Cancel(
true);
3806 this->_M_pTask->_FinalizeAndRunContinuations(
3822 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3828 #if defined (__cplusplus_winrt)
3838 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3840 ref new details::_IAsyncActionToAsyncOperationConverter(
3856 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3858 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_ContinuationReturnType, _ProgressType>(_OpWithProgress));
3866 void _Continue(
std::false_type, details::_TypeSelectorAsyncActionWithProgress)
const
3868 typedef details::_FunctionTypeTraits<_Function, _InternalReturnType>::_FuncRetType _FuncOutputType;
3870 auto _OpWithProgress = _LogWorkItemAndInvokeUserLambda(_Continuation_func_transformer<_InternalReturnType, _FuncOutputType>::_Perform(_M_function), _M_ancestorTaskImpl->_GetResult());
3873 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(
3875 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(_OpWithProgress));
3889 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3890 this->_M_pTask->_FinalizeAndRunContinuations(
3907 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3908 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3909 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask)));
3912 #if defined (__cplusplus_winrt)
3924 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3925 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3926 ref new details::_IAsyncActionToAsyncOperationConverter(_LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3940 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3944 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3945 ref new details::_IAsyncOperationWithProgressToAsyncOperationConverter<_ContinuationReturnType, _ProgressType>(
3946 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3956 void _Continue(
std::true_type, details::_TypeSelectorAsyncActionWithProgress)
const
3959 task<_InternalReturnType> _ResultTask;
3960 _ResultTask._SetImpl(
std::move(_M_ancestorTaskImpl));
3964 details::_Task_impl_base::_AsyncInit<_NormalizedContinuationReturnType, _ContinuationReturnType>(this->_M_pTask,
3965 ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_ProgressType>(
3966 _LogWorkItemAndInvokeUserLambda(_M_function,
std::move(_ResultTask))));
3974 template<
typename _InternalReturnType,
typename _Function>
3979 _M_Impl->_M_fFromAsync = _Async_type_traits::_IsAsyncTask;
3980 _M_Impl->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3981 _M_Impl->_M_taskEventLogger._LogScheduleTask(
false);
3982 _M_Impl->_ScheduleTask(
new _InitialTaskHandle<_InternalReturnType, _Function, typename _Async_type_traits::_AsyncKind>(_GetImpl(), _Func),
details::_NoInline);
3993 #if defined (__cplusplus_winrt)
3999 _M_Impl->_M_fFromAsync =
true;
4005 details::_Task_impl_base::_AsyncInit<_ReturnType, _ReturnType>(_M_Impl, _AsyncOp);
4013 _TaskInitAsyncOp(_AsyncOp);
4019 template<
typename _Progress>
4029 template<
typename _Function>
4032 _TaskInitWithFunctor<_ReturnType, _Function>(_Func);
4038 template<
typename _Ty>
4041 _TaskInitNoFunctor(_Param);
4044 template<
typename _InternalReturnType,
typename _Function>
4049 throw invalid_operation(
"then() cannot be called on a default constructed task.");
4053 auto _Scheduler = _TaskOptions.has_scheduler() ? _TaskOptions.get_scheduler() : _GetImpl()->_GetScheduler();
4055 return _ThenImpl<_InternalReturnType, _Function>(_Func, _PTokenState, _TaskOptions.get_continuation_context(), _Scheduler, _CreationStack);
4061 template<
typename _InternalReturnType,
typename _Function>
4067 throw invalid_operation(
"then() cannot be called on a default constructed task.");
4072 typedef typename _Async_type_traits::_TaskRetType _TaskType;
4079 if (_PTokenState ==
nullptr)
4081 if (_Function_type_traits::_Takes_task::value)
4087 _PTokenState = _GetImpl()->_M_pTokenState;
4092 _ContinuationTask._CreateImpl(_PTokenState, _Scheduler);
4094 _ContinuationTask._GetImpl()->_M_fFromAsync = (_GetImpl()->_M_fFromAsync || _Async_type_traits::_IsAsyncTask);
4095 _ContinuationTask._GetImpl()->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
4096 _ContinuationTask._SetTaskCreationCallstack(_CreationStack);
4098 _GetImpl()->_ScheduleContinuation(
new _ContinuationTaskHandle<_InternalReturnType, _TaskType, _Function, typename _Function_type_traits::_Takes_task, typename _Async_type_traits::_AsyncKind>(
4099 _GetImpl(), _ContinuationTask._GetImpl(), _Func, _ContinuationContext, _InliningMode));
4101 return _ContinuationTask;
4188 template<
typename _Ty>
4192 details::_ValidateTaskConstructorArgs<void,_Ty>(_Param);
4194 _M_unitTask.
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
4226 task(
const task& _Other): _M_unitTask(_Other._M_unitTask){}
4253 task(task&& _Other) : _M_unitTask(
std::
move(_Other._M_unitTask)) {}
4266 task& operator=(
const task& _Other)
4268 if (
this != &_Other)
4270 _M_unitTask = _Other._M_unitTask;
4286 task& operator=(task&& _Other)
4288 if (
this != &_Other)
4290 _M_unitTask =
std::move(_Other._M_unitTask);
4319 template<
typename _Function>
4321 auto then(const _Function& _Func, task_options _TaskOptions = task_options()) const -> typename details::_ContinuationTypeTraits<_Function,
void>::_TaskOfType
4324 return _M_unitTask._ThenImpl<
void, _Function>(_Func, _TaskOptions);
4355 template<
typename _Function>
4359 task_options _TaskOptions(_CancellationToken, _ContinuationContext);
4361 return _M_unitTask._ThenImpl<
void, _Function>(_Func, _TaskOptions);
4375 return _M_unitTask.wait();
4403 return _M_unitTask.is_done();
4414 return _M_unitTask.scheduler();
4426 return _M_unitTask.is_apartment_aware();
4458 _M_unitTask._CreateImpl(_Ct, _Scheduler);
4466 return _M_unitTask._M_Impl;
4474 _M_unitTask._SetImpl(_Impl);
4490 _M_unitTask._SetAsync(
_Async);
4498 _M_unitTask._SetTaskCreationCallstack(_callstack);
4504 template<
typename _Function>
4509 auto _Scheduler = _GetImpl()->_GetScheduler();
4515 template <
typename T>
friend class task;
4526 #if defined (__cplusplus_winrt)
4527 void _TaskInitNoFunctor(Windows::Foundation::IAsyncAction^ _AsyncAction)
4532 _M_unitTask._TaskInitAsyncOp(
ref new details::_IAsyncActionToAsyncOperationConverter(_AsyncAction));
4538 template<
typename _P>
4539 void _TaskInitNoFunctor(Windows::Foundation::IAsyncActionWithProgress<_P>^ _AsyncActionWithProgress)
4541 _M_unitTask._TaskInitAsyncOp(
ref new details::_IAsyncActionWithProgressToAsyncOperationConverter<_P>(_AsyncActionWithProgress));
4548 template<
typename _Function>
4551 _M_unitTask._TaskInitWithFunctor<
void, _Function>(_Func);
4557 template<
typename _T>
4560 _TaskInitNoFunctor(_Param);
4573 #if defined (__cplusplus_winrt)
4575 template<
typename _Ty>
4580 template<
typename _Ty,
typename _Progress>
4581 _Ty
_GetUnwrappedType(Windows::Foundation::IAsyncOperationWithProgress<_Ty, _Progress>^);
4583 template<
typename _Progress>
4584 void _GetUnwrappedType(Windows::Foundation::IAsyncActionWithProgress<_Progress>^);
4588 template<
typename _Ty>
4592 template<
typename _Ty>
4595 template<
typename _Ty>
4605 template<
typename _Ty>
4609 template<
typename _Ty>
4613 template<
typename _Ty>
4620 template<
typename _Ty>
4623 template<
typename _Ty>
4626 template<
typename _Ty>
4661 template<typename _Ty>
4666 #
if defined (__cplusplus_winrt)
4667 "incorrect argument for create_task; can be a callable object, an asynchronous operation, or a task_completion_event"
4669 "incorrect argument for create_task; can be a callable object or a task_completion_event"
4674 return _CreatedTask;
4708 template<
typename _ReturnType>
4710 task<_ReturnType> create_task(const
task<_ReturnType>& _Task)
4713 return _CreatedTask;
4716 #if defined (__cplusplus_winrt)
4719 template<
typename _T>
4720 task<_T> _To_task_helper(Windows::Foundation::IAsyncOperation<_T>^ op)
4725 template<
typename _T,
typename _Progress>
4726 task<_T> _To_task_helper(Windows::Foundation::IAsyncOperationWithProgress<_T, _Progress>^ op)
4728 return task<_T>(op);
4731 inline task<void> _To_task_helper(Windows::Foundation::IAsyncAction^ op)
4733 return task<void>(op);
4736 template<
typename _Progress>
4737 task<void> _To_task_helper(Windows::Foundation::IAsyncActionWithProgress<_Progress>^ op)
4739 return task<void>(op);
4742 template<
typename _ProgressType>
4743 class _ProgressDispatcherBase
4747 virtual ~_ProgressDispatcherBase()
4751 virtual void _Report(
const _ProgressType&
_Val) = 0;
4754 template<
typename _ProgressType,
typename _ClassPtrType>
4755 class _ProgressDispatcher :
public _ProgressDispatcherBase<_ProgressType>
4759 virtual ~_ProgressDispatcher()
4763 _ProgressDispatcher(_ClassPtrType _Ptr) : _M_ptr(_Ptr)
4767 virtual void _Report(
const _ProgressType&
_Val)
4769 _M_ptr->_FireProgress(_Val);
4774 _ClassPtrType _M_ptr;
4776 class _ProgressReporterCtorArgType{};
4791 template<
typename _ProgressType>
4792 class progress_reporter
4794 typedef std::shared_ptr<details::_ProgressDispatcherBase<_ProgressType>> _PtrType;
4805 void report(
const _ProgressType&
_Val)
const
4807 _M_dispatcher->_Report(_Val);
4810 template<
typename _ClassPtrType>
4811 static progress_reporter _CreateReporter(_ClassPtrType _Ptr)
4813 progress_reporter _Reporter;
4814 details::_ProgressDispatcherBase<_ProgressType> *_PDispatcher =
new details::_ProgressDispatcher<_ProgressType, _ClassPtrType>(_Ptr);
4815 _Reporter._M_dispatcher = _PtrType(_PDispatcher);
4818 progress_reporter() {}
4821 progress_reporter(details::_ProgressReporterCtorArgType);
4823 _PtrType _M_dispatcher;
4831 enum _AsyncStatusInternal
4836 _AsyncCompleted = 1,
4840 _AsyncCancelPending,
4849 enum _AsyncResultType
4851 SingleResult = 0x0001,
4852 MultipleResults = 0x0002
4859 struct _ZeroArgumentFunctor { };
4860 struct _OneArgumentFunctor { };
4861 struct _TwoArgumentFunctor { };
4870 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4871 _Arg1 _Arg1ClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4874 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4875 _Arg2 _Arg2ClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4877 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4878 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4880 template<
typename _Class,
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4881 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)(_Arg1, _Arg2)
const);
4887 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4888 _Arg1 _Arg1ClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4891 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4892 void _Arg2ClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4894 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4895 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)(_Arg1)
const);
4897 template<
typename _Class,
typename _ReturnType,
typename _Arg1>
4898 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)(_Arg1)
const);
4904 template<
typename _Class,
typename _ReturnType>
4905 void _Arg1ClassHelperThunk(_ReturnType (_Class::*)()
const);
4908 template<
typename _Class,
typename _ReturnType>
4909 void _Arg2ClassHelperThunk(_ReturnType (_Class::*)()
const);
4912 template<
typename _Class,
typename _ReturnType>
4913 _ReturnType _ReturnTypeClassHelperThunk(_ReturnType (_Class::*)()
const);
4915 template<
typename _Class,
typename _ReturnType>
4916 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType (_Class::*)()
const);
4924 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4925 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4927 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4928 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4930 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4931 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4933 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4934 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)(_Arg1, _Arg2));
4936 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4937 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4939 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4940 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4942 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4943 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4945 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4946 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)(_Arg1, _Arg2));
4948 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4949 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4951 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4952 _Arg2 _Arg2PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4954 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4955 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4957 template<
typename _ReturnType,
typename _Arg1,
typename _Arg2>
4958 _TwoArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)(_Arg1, _Arg2));
4963 template<
typename _ReturnType,
typename _Arg1>
4964 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4966 template<
typename _ReturnType,
typename _Arg1>
4967 void _Arg2PFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4969 template<
typename _ReturnType,
typename _Arg1>
4970 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)(_Arg1));
4972 template<
typename _ReturnType,
typename _Arg1>
4973 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)(_Arg1));
4975 template<
typename _ReturnType,
typename _Arg1>
4976 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4978 template<
typename _ReturnType,
typename _Arg1>
4979 void _Arg2PFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4981 template<
typename _ReturnType,
typename _Arg1>
4982 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)(_Arg1));
4984 template<
typename _ReturnType,
typename _Arg1>
4985 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)(_Arg1));
4987 template<
typename _ReturnType,
typename _Arg1>
4988 _Arg1 _Arg1PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4990 template<
typename _ReturnType,
typename _Arg1>
4991 void _Arg2PFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4993 template<
typename _ReturnType,
typename _Arg1>
4994 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)(_Arg1));
4996 template<
typename _ReturnType,
typename _Arg1>
4997 _OneArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)(_Arg1));
5002 template<
typename _ReturnType>
5003 void _Arg1PFNHelperThunk(_ReturnType(__cdecl *)());
5005 template<
typename _ReturnType>
5006 void _Arg2PFNHelperThunk(_ReturnType(__cdecl *)());
5008 template<
typename _ReturnType>
5009 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__cdecl *)());
5011 template<
typename _ReturnType>
5012 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__cdecl *)());
5014 template<
typename _ReturnType>
5015 void _Arg1PFNHelperThunk(_ReturnType(__stdcall *)());
5017 template<
typename _ReturnType>
5018 void _Arg2PFNHelperThunk(_ReturnType(__stdcall *)());
5020 template<
typename _ReturnType>
5021 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__stdcall *)());
5023 template<
typename _ReturnType>
5024 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__stdcall *)());
5026 template<
typename _ReturnType>
5027 void _Arg1PFNHelperThunk(_ReturnType(__fastcall *)());
5029 template<
typename _ReturnType>
5030 void _Arg2PFNHelperThunk(_ReturnType(__fastcall *)());
5032 template<
typename _ReturnType>
5033 _ReturnType _ReturnTypePFNHelperThunk(_ReturnType(__fastcall *)());
5035 template<
typename _ReturnType>
5036 _ZeroArgumentFunctor _ArgumentCountHelper(_ReturnType(__fastcall *)());
5038 template<
typename _T>
5039 struct _FunctorArguments
5041 static const size_t _Count = 0;
5045 struct _FunctorArguments<_OneArgumentFunctor>
5047 static const size_t _Count = 1;
5051 struct _FunctorArguments<_TwoArgumentFunctor>
5053 static const size_t _Count = 2;
5056 template<
typename _T>
5057 struct _FunctorTypeTraits
5059 typedef decltype(_ArgumentCountHelper(&(_T::operator()))) _ArgumentCountType;
5060 static const
size_t _ArgumentCount = _FunctorArguments<_ArgumentCountType>::
_Count;
5062 typedef decltype(_ReturnTypeClassHelperThunk(&(
_T::operator()))) _ReturnType;
5063 typedef decltype(_Arg1ClassHelperThunk(&(
_T::operator()))) _Argument1Type;
5064 typedef decltype(_Arg2ClassHelperThunk(&(
_T::operator()))) _Argument2Type;
5067 template<typename
_T>
5068 struct _FunctorTypeTraits<
_T *>
5070 typedef decltype(_ArgumentCountHelper(stdx::declval<_T*>())) _ArgumentCountType;
5071 static const
size_t _ArgumentCount = _FunctorArguments<_ArgumentCountType>::_Count;
5073 typedef decltype(_ReturnTypePFNHelperThunk(
stdx::
declval<_T*>())) _ReturnType;
5074 typedef decltype(_Arg1PFNHelperThunk(
stdx::
declval<_T*>())) _Argument1Type;
5075 typedef decltype(_Arg2PFNHelperThunk(
stdx::
declval<_T*>())) _Argument2Type;
5078 template<typename _T>
5079 struct _ProgressTypeTraits
5081 static const bool _TakesProgress =
false;
5082 typedef void _ProgressType;
5085 template<
typename _T>
5086 struct _ProgressTypeTraits<progress_reporter<_T>>
5088 static const bool _TakesProgress =
true;
5089 typedef typename _T _ProgressType;
5093 template<typename _T, size_t count = _FunctorTypeTraits<_T>::_ArgumentCount>
5094 struct _CAFunctorOptions
5096 static const bool _TakesProgress =
false;
5097 static const bool _TakesToken =
false;
5098 typedef void _ProgressType;
5101 template<
typename _T>
5102 struct _CAFunctorOptions<_T, 1>
5106 typedef typename _FunctorTypeTraits<_T>::_Argument1Type _Argument1Type;
5110 static const bool _TakesProgress = _ProgressTypeTraits<_Argument1Type>::_TakesProgress;
5111 static const bool _TakesToken = !_TakesProgress;
5112 typedef typename _ProgressTypeTraits<_Argument1Type>::_ProgressType _ProgressType;
5115 template<
typename _T>
5116 struct _CAFunctorOptions<_T, 2>
5120 typedef typename _FunctorTypeTraits<_T>::_Argument1Type _Argument1Type;
5124 static const bool _TakesProgress =
true;
5125 static const bool _TakesToken =
true;
5126 typedef typename _ProgressTypeTraits<_Argument1Type>::_ProgressType _ProgressType;
5140 template<
typename _AsyncSelector,
typename _ReturnType>
5141 struct _SelectorTaskGenerator
5143 template<
typename _Function>
5144 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5146 task_options _taskOptinos(_Cts.get_token());
5148 return task<_ReturnType>(_Func(), _taskOptinos);
5151 template<
typename _Function>
5152 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5154 task_options _taskOptinos(_Cts.get_token());
5156 return task<_ReturnType>(_Func(_Cts.get_token()), _taskOptinos);
5159 template<
typename _Function,
typename _ProgressObject>
5160 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5162 task_options _taskOptinos(_Cts.get_token());
5164 return task<_ReturnType>(_Func(_Progress), _taskOptinos);
5167 template<
typename _Function,
typename _ProgressObject>
5168 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5170 task_options _taskOptinos(_Cts.get_token());
5172 return task<_ReturnType>(_Func(_Progress, _Cts.get_token()), _taskOptinos);
5176 template<
typename _AsyncSelector>
5177 struct _SelectorTaskGenerator<_AsyncSelector, void>
5179 template<
typename _Function>
5180 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5182 task_options _taskOptinos(_Cts.get_token());
5184 return task<void>(_Func(), _taskOptinos);
5187 template<
typename _Function>
5188 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5190 task_options _taskOptinos(_Cts.get_token());
5192 return task<void>(_Func(_Cts.get_token()), _taskOptinos);
5195 template<
typename _Function,
typename _ProgressObject>
5196 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5198 task_options _taskOptinos(_Cts.get_token());
5200 return task<void>(_Func(_Progress), _taskOptinos);
5203 template<
typename _Function,
typename _ProgressObject>
5204 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5206 task_options _taskOptinos(_Cts.get_token());
5208 return task<void>(_Func(_Progress, _Cts.get_token()), _taskOptinos);
5215 template<
typename _ReturnType>
5216 struct _SelectorTaskGenerator<_TypeSelectorNoAsync, _ReturnType>
5219 #pragma warning(push)
5220 #pragma warning(disable: 4702)
5221 template<
typename _Function>
5222 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5224 task_options _taskOptinos(_Cts.get_token());
5226 return task<_ReturnType>( [=]() -> _ReturnType {
5232 #pragma warning(pop)
5234 template<
typename _Function>
5235 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5237 task_options _taskOptinos(_Cts.get_token());
5239 return task<_ReturnType>( [=]() -> _ReturnType {
5242 return _Func(_Cts.get_token());
5246 template<
typename _Function,
typename _ProgressObject>
5247 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5249 task_options _taskOptinos(_Cts.get_token());
5251 return task<_ReturnType>( [=]() -> _ReturnType {
5254 return _Func(_Progress);
5258 template<
typename _Function,
typename _ProgressObject>
5259 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5261 task_options _taskOptinos(_Cts.get_token());
5263 return task<_ReturnType>( [=]() -> _ReturnType {
5266 return _Func(_Progress, _Cts.get_token());
5272 struct _SelectorTaskGenerator<_TypeSelectorNoAsync, void>
5274 template<
typename _Function>
5275 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5277 task_options _taskOptinos(_Cts.get_token());
5279 return task<void>( [=]() {
5286 template<
typename _Function>
5287 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5289 task_options _taskOptinos(_Cts.get_token());
5291 return task<void>( [=]() {
5294 _Func(_Cts.get_token());
5298 template<
typename _Function,
typename _ProgressObject>
5299 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5301 task_options _taskOptinos(_Cts.get_token());
5303 return task<void>( [=]() {
5310 template<
typename _Function,
typename _ProgressObject>
5311 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5313 task_options _taskOptinos(_Cts.get_token());
5315 return task<void>( [=]() {
5318 _Func(_Progress, _Cts.get_token());
5326 template<
typename _ReturnType>
5327 struct _SelectorTaskGenerator<_TypeSelectorAsyncTask, _ReturnType>
5329 template<
typename _Function>
5330 static task<_ReturnType> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5335 template<
typename _Function>
5336 static task<_ReturnType> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5338 return _Func(_Cts.get_token());
5341 template<
typename _Function,
typename _ProgressObject>
5342 static task<_ReturnType> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5344 return _Func(_Progress);
5347 template<
typename _Function,
typename _ProgressObject>
5348 static task<_ReturnType> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5350 return _Func(_Progress, _Cts.get_token());
5355 struct _SelectorTaskGenerator<_TypeSelectorAsyncTask, void>
5357 template<
typename _Function>
5358 static task<void> _GenerateTask_0(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5363 template<
typename _Function>
5364 static task<void> _GenerateTask_1C(
const _Function& _Func, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5366 return _Func(_Cts.get_token());
5369 template<
typename _Function,
typename _ProgressObject>
5370 static task<void> _GenerateTask_1P(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5372 return _Func(_Progress);
5375 template<
typename _Function,
typename _ProgressObject>
5376 static task<void> _GenerateTask_2PC(
const _Function& _Func,
const _ProgressObject& _Progress, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5378 return _Func(_Progress, _Cts.get_token());
5382 template<
typename _Generator,
bool _TakesToken,
bool TakesProgress>
5383 struct _TaskGenerator
5387 template<
typename _Generator>
5388 struct _TaskGenerator<_Generator, false, false>
5390 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5391 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5392 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5394 return _Generator::_GenerateTask_0(_Func, _Cts, _callstack);
5398 template<
typename _Generator>
5399 struct _TaskGenerator<_Generator, true, false>
5401 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5402 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5403 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5405 return _Generator::_GenerateTask_1C(_Func, _Cts, _callstack);
5409 template<
typename _Generator>
5410 struct _TaskGenerator<_Generator, false, true>
5412 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5413 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5414 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5416 return _Generator::_GenerateTask_1P(_Func, progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5420 template<
typename _Generator>
5421 struct _TaskGenerator<_Generator, true, true>
5423 template<
typename _Function,
typename _ClassPtr,
typename _ProgressType>
5424 static auto _GenerateTask(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5425 -> decltype(_Generator::_GenerateTask_0(_Func, _Cts, _callstack))
5427 return _Generator::_GenerateTask_2PC(_Func, progress_reporter<_ProgressType>::_CreateReporter(_Ptr), _Cts, _callstack);
5453 template<
typename _Function,
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken,
bool _TakesProgress>
5454 struct _AsyncAttributes
5458 template<
typename _Function,
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken>
5459 struct _AsyncAttributes<_Function, _ProgressType, _ReturnType, _TaskTraits, _TakesToken, true>
5461 typedef typename Windows::Foundation::IAsyncOperationWithProgress<_ReturnType, _ProgressType> _AsyncBaseType;
5462 typedef typename Windows::Foundation::AsyncOperationProgressHandler<_ReturnType, _ProgressType> _ProgressDelegateType;
5463 typedef typename Windows::Foundation::AsyncOperationWithProgressCompletedHandler<_ReturnType, _ProgressType> _CompletionDelegateType;
5464 typedef typename _ReturnType _ReturnType;
5465 typedef typename _ProgressType _ProgressType;
5466 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5467 typedef typename _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5468 typedef typename _TaskGenerator<_SelectorTaskGenerator, _TakesToken, true> _TaskGenerator;
5470 static const bool _TakesProgress =
true;
5471 static const bool _TakesToken = _TakesToken;
5473 template<
typename _Function,
typename _ClassPtr>
5474 static task<_ReturnType> _Generate_Task(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5476 return _TaskGenerator::_GenerateTask<_Function, _ClassPtr, _ProgressType>(_Func, _Ptr, _Cts, _callstack);
5480 template<
typename _Function,
typename _ProgressType,
typename _ReturnType,
typename _TaskTraits,
bool _TakesToken>
5481 struct _AsyncAttributes<_Function, _ProgressType, _ReturnType, _TaskTraits, _TakesToken, false>
5483 typedef typename Windows::Foundation::IAsyncOperation<_ReturnType> _AsyncBaseType;
5484 typedef _Zip _ProgressDelegateType;
5485 typedef typename Windows::Foundation::AsyncOperationCompletedHandler<_ReturnType> _CompletionDelegateType;
5486 typedef typename _ReturnType _ReturnType;
5487 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5488 typedef typename _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5489 typedef typename _TaskGenerator<_SelectorTaskGenerator, _TakesToken, false> _TaskGenerator;
5491 static const bool _TakesProgress =
false;
5492 static const bool _TakesToken = _TakesToken;
5494 template<
typename _Function,
typename _ClassPtr>
5495 static task<_ReturnType> _Generate_Task(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5497 return _TaskGenerator::_GenerateTask<_Function, _ClassPtr, _ProgressType>(_Func, _Ptr, _Cts, _callstack);
5501 template<
typename _Function,
typename _ProgressType,
typename _TaskTraits,
bool _TakesToken>
5502 struct _AsyncAttributes<_Function, _ProgressType, void, _TaskTraits, _TakesToken, true>
5504 typedef typename Windows::Foundation::IAsyncActionWithProgress<_ProgressType> _AsyncBaseType;
5505 typedef typename Windows::Foundation::AsyncActionProgressHandler<_ProgressType> _ProgressDelegateType;
5506 typedef typename Windows::Foundation::AsyncActionWithProgressCompletedHandler<_ProgressType> _CompletionDelegateType;
5507 typedef void _ReturnType;
5508 typedef typename _ProgressType _ProgressType;
5509 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5510 typedef typename _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5511 typedef typename _TaskGenerator<_SelectorTaskGenerator, _TakesToken, true> _TaskGenerator;
5513 static const bool _TakesProgress =
true;
5514 static const bool _TakesToken = _TakesToken;
5516 template<
typename _Function,
typename _ClassPtr>
5517 static task<_ReturnType> _Generate_Task(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5519 return _TaskGenerator::_GenerateTask<_Function, _ClassPtr, _ProgressType>(_Func, _Ptr, _Cts, _callstack);
5523 template<
typename _Function,
typename _ProgressType,
typename _TaskTraits,
bool _TakesToken>
5524 struct _AsyncAttributes<_Function, _ProgressType, void, _TaskTraits, _TakesToken, false>
5526 typedef typename Windows::Foundation::IAsyncAction _AsyncBaseType;
5527 typedef _Zip _ProgressDelegateType;
5528 typedef typename Windows::Foundation::AsyncActionCompletedHandler _CompletionDelegateType;
5529 typedef void _ReturnType;
5530 typedef typename _TaskTraits::_AsyncKind _AsyncKind;
5531 typedef typename _SelectorTaskGenerator<_AsyncKind, _ReturnType> _SelectorTaskGenerator;
5532 typedef typename _TaskGenerator<_SelectorTaskGenerator, _TakesToken, false> _TaskGenerator;
5534 static const bool _TakesProgress =
false;
5535 static const bool _TakesToken = _TakesToken;
5537 template<
typename _Function,
typename _ClassPtr>
5538 static task<_ReturnType> _Generate_Task(
const _Function& _Func, _ClassPtr _Ptr, cancellation_token_source _Cts,
const _TaskCreationCallstack & _callstack)
5540 return _TaskGenerator::_GenerateTask<_Function, _ClassPtr, _ProgressType>(_Func, _Ptr, _Cts, _callstack);
5544 template<
typename _Function>
5545 struct _AsyncLambdaTypeTraits
5547 typedef typename _FunctorTypeTraits<_Function>::_ReturnType _ReturnType;
5548 typedef typename _FunctorTypeTraits<_Function>::_Argument1Type _Argument1Type;
5549 typedef typename _CAFunctorOptions<_Function>::_ProgressType _ProgressType;
5551 static const bool _TakesProgress = _CAFunctorOptions<_Function>::_TakesProgress;
5552 static const bool _TakesToken = _CAFunctorOptions<_Function>::_TakesToken;
5554 typedef typename _TaskTypeTraits<_ReturnType> _TaskTraits;
5555 typedef typename _AsyncAttributes<_Function, _ProgressType, typename _TaskTraits::_TaskRetType, _TaskTraits, _TakesToken, _TakesProgress> _AsyncAttributes;
5565 template <
typename _Attributes, _AsyncResultType resultType = SingleResult >
5566 ref class _AsyncInfoBase
abstract : _Attributes::_AsyncBaseType
5571 _M_currentStatus(_AsyncStatusInternal::_AsyncCreated),
5573 _M_completeDelegate(nullptr),
5574 _M_CompleteDelegateAssigned(0),
5581 virtual typename _Attributes::_ReturnType GetResults()
5583 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5586 virtual property unsigned int Id
5590 _CheckValidStateForAsyncInfoCall();
5595 void set(
unsigned int id)
5597 _CheckValidStateForAsyncInfoCall();
5601 throw ::Platform::Exception::CreateException(E_INVALIDARG);
5603 else if (_M_currentStatus != _AsyncStatusInternal::_AsyncCreated)
5605 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5612 virtual property Windows::Foundation::AsyncStatus Status
5614 Windows::Foundation::AsyncStatus
get()
5616 _CheckValidStateForAsyncInfoCall();
5618 _AsyncStatusInternal _Current = _M_currentStatus;
5626 case _AsyncCancelPending:
5627 _Current = _AsyncCanceled;
5630 _Current = _AsyncStarted;
5636 return static_cast<Windows::Foundation::AsyncStatus
>(_Current);
5640 virtual property Windows::Foundation::HResult ErrorCode
5642 Windows::Foundation::HResult
get()
5644 _CheckValidStateForAsyncInfoCall();
5646 Windows::Foundation::HResult _Hr;
5647 _Hr.Value = _M_errorCode;
5652 virtual property typename _Attributes::_ProgressDelegateType^ Progress
5654 typename typename _Attributes::_ProgressDelegateType^
get()
5656 return _GetOnProgress();
5659 void set(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
5661 _PutOnProgress(_ProgressHandler);
5665 virtual void Cancel()
5667 if (_TransitionToState(_AsyncCancelPending))
5673 virtual void Close()
5675 if (_TransitionToState(_AsyncClosed))
5681 if (_M_currentStatus != _AsyncClosed)
5683 throw ::Platform::Exception::CreateException(E_ILLEGAL_STATE_CHANGE);
5688 virtual property typename _Attributes::_CompletionDelegateType^ Completed
5690 typename _Attributes::_CompletionDelegateType^
get()
5692 _CheckValidStateForDelegateCall();
5693 return _M_completeDelegate;
5696 void set(
typename _Attributes::_CompletionDelegateType^ _CompleteHandler)
5698 _CheckValidStateForDelegateCall();
5700 if (InterlockedIncrement(&_M_CompleteDelegateAssigned) == 1)
5703 _M_completeDelegate = _CompleteHandler;
5707 if (_IsTerminalState())
5714 throw ::Platform::Exception::CreateException(E_ILLEGAL_DELEGATE_ASSIGNMENT);
5725 if (_TransitionToState(_AsyncStarted))
5731 throw ::Platform::Exception::CreateException(E_ILLEGAL_STATE_CHANGE);
5736 void _FireCompletion()
5738 _TryTransitionToCompleted();
5741 if (_M_completeDelegate !=
nullptr && InterlockedIncrement(&_M_CallbackMade) == 1)
5743 _M_completeDelegateContext._CallInContext([=] {
5744 _M_completeDelegate((_Attributes::_AsyncBaseType^)
this, this->Status);
5745 _M_completeDelegate =
nullptr;
5750 virtual typename _Attributes::_ProgressDelegateType^ _GetOnProgress()
5752 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5755 virtual void _PutOnProgress(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
5757 throw ::Platform::Exception::CreateException(E_UNEXPECTED);
5760 bool _TryTransitionToCompleted()
5762 return _TransitionToState(_AsyncStatusInternal::_AsyncCompleted);
5765 bool _TryTransitionToCancelled()
5767 return _TransitionToState(_AsyncStatusInternal::_AsyncCanceled);
5770 bool _TryTransitionToError(
const HRESULT error)
5773 return _TransitionToState(_AsyncStatusInternal::_AsyncError);
5779 inline void _CheckValidStateForDelegateCall()
5781 if (_M_currentStatus == _AsyncClosed)
5783 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5790 inline void _CheckValidStateForResultsCall()
5792 _AsyncStatusInternal _Current = _M_currentStatus;
5794 if (_Current == _AsyncError)
5796 throw ::Platform::Exception::CreateException(_M_errorCode);
5798 #pragma warning(push)
5799 #pragma warning(disable: 4127) // Conditional expression is constant
5801 if (resultType == SingleResult)
5802 #pragma warning(pop)
5804 if (_Current != _AsyncCompleted)
5806 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5810 else if (_Current != _AsyncStarted &&
5811 _Current != _AsyncCancelPending &&
5812 _Current != _AsyncCanceled &&
5813 _Current != _AsyncCompleted)
5815 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5822 inline bool _ContinueAsyncOperation()
5824 return (_M_currentStatus == _AsyncStarted);
5830 virtual void _OnStart() = 0;
5831 virtual void _OnClose() = 0;
5832 virtual void _OnCancel() = 0;
5840 inline void _CheckValidStateForAsyncInfoCall()
5842 _AsyncStatusInternal _Current = _M_currentStatus;
5843 if (_Current == _AsyncClosed)
5845 throw ::Platform::Exception::CreateException(E_ILLEGAL_METHOD_CALL);
5847 else if (_Current == _AsyncCreated)
5849 throw ::Platform::Exception::CreateException(E_ASYNC_OPERATION_NOT_STARTED);
5854 inline bool _TransitionToState(
const _AsyncStatusInternal _NewState)
5856 _AsyncStatusInternal _Current = _M_currentStatus;
5862 case _AsyncStatusInternal::_AsyncStarted:
5863 if (_Current != _AsyncCreated)
5868 case _AsyncStatusInternal::_AsyncCompleted:
5869 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5874 case _AsyncStatusInternal::_AsyncCancelPending:
5875 if (_Current != _AsyncStarted)
5880 case _AsyncStatusInternal::_AsyncCanceled:
5881 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5886 case _AsyncStatusInternal::_AsyncError:
5887 if (_Current != _AsyncStarted && _Current != _AsyncCancelPending)
5892 case _AsyncStatusInternal::_AsyncClosed:
5893 if (!_IsTerminalState(_Current))
5906 _AsyncStatusInternal _RetState =
static_cast<_AsyncStatusInternal
>(
5909 static_cast<LONG>(_Current)));
5914 return (_RetState == _Current);
5917 inline bool _IsTerminalState()
5919 return _IsTerminalState(_M_currentStatus);
5922 inline bool _IsTerminalState(_AsyncStatusInternal
status)
5924 return (status == _AsyncError ||
5925 status == _AsyncCanceled ||
5926 status == _AsyncCompleted ||
5927 status == _AsyncClosed);
5932 _ContextCallback _M_completeDelegateContext;
5933 typename _Attributes::_CompletionDelegateType^
volatile _M_completeDelegate;
5934 _AsyncStatusInternal
volatile _M_currentStatus;
5935 HRESULT
volatile _M_errorCode;
5937 long volatile _M_CompleteDelegateAssigned;
5938 long volatile _M_CallbackMade;
5945 template<
typename _Attributes,
bool _HasProgress, _AsyncResultType _ResultType = SingleResult >
5946 ref class _AsyncProgressBase
abstract : _AsyncInfoBase<_Attributes, _ResultType>
5950 template<
typename _Attributes, _AsyncResultType _ResultType>
5951 ref class _AsyncProgressBase<_Attributes, true, _ResultType>
abstract : _AsyncInfoBase<_Attributes, _ResultType>
5955 _AsyncProgressBase() : _AsyncInfoBase<_Attributes, _ResultType>(),
5956 _M_progressDelegate(nullptr)
5960 virtual typename _Attributes::_ProgressDelegateType^ _GetOnProgress()
override
5962 _CheckValidStateForDelegateCall();
5963 return _M_progressDelegate;
5966 virtual void _PutOnProgress(
typename _Attributes::_ProgressDelegateType^ _ProgressHandler)
override
5968 _CheckValidStateForDelegateCall();
5969 _M_progressDelegate = _ProgressHandler;
5973 void _FireProgress(
const typename _Attributes::_ProgressType& _ProgressValue)
5975 if (_M_progressDelegate !=
nullptr)
5977 _M_progressDelegateContext._CallInContext([=] {
5978 _M_progressDelegate((_Attributes::_AsyncBaseType^)
this, _ProgressValue);
5985 _ContextCallback _M_progressDelegateContext;
5986 typename _Attributes::_ProgressDelegateType^ _M_progressDelegate;
5989 template<
typename _Attributes, _AsyncResultType _ResultType = SingleResult>
5990 ref class _AsyncBaseProgressLayer
abstract : _AsyncProgressBase<_Attributes, _Attributes::_TakesProgress, _ResultType>
6001 template<
typename _Attributes,
typename _ReturnType>
6002 ref class _AsyncTaskThunkBase
abstract : _AsyncBaseProgressLayer<_Attributes>
6006 virtual _ReturnType GetResults()
override
6008 _CheckValidStateForResultsCall();
6009 return _M_task.get();
6014 typedef task<_ReturnType> _TaskType;
6016 _AsyncTaskThunkBase(
const _TaskType& _Task)
6021 _AsyncTaskThunkBase()
6027 virtual void _OnStart()
override
6029 _M_task.then( [=](_TaskType _Antecedent) {
6034 catch(task_canceled&)
6036 _TryTransitionToCancelled();
6038 catch(::Platform::Exception^ _Ex)
6040 _TryTransitionToError(_Ex->HResult);
6044 _TryTransitionToError(E_FAIL);
6053 cancellation_token_source _M_cts;
6056 template<
typename _Attributes>
6057 ref class _AsyncTaskThunk : _AsyncTaskThunkBase<_Attributes, typename _Attributes::_ReturnType>
6061 _AsyncTaskThunk(
const _TaskType& _Task) :
6062 _AsyncTaskThunkBase(_Task)
6072 virtual void _OnClose()
override
6076 virtual void _OnCancel()
override
6085 template<
typename _Function>
6086 ref class _AsyncTaskGeneratorThunk
sealed : _AsyncTaskThunk<typename _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes>
6090 typedef typename _AsyncLambdaTypeTraits<_Function>::_AsyncAttributes _Attributes;
6091 typedef typename _AsyncTaskThunk<_Attributes> _Base;
6092 typedef typename _Attributes::_AsyncBaseType _AsyncBaseType;
6094 _AsyncTaskGeneratorThunk(
const _Function& _Func,
const _TaskCreationCallstack &_callstack) : _M_func(_Func), _M_creationCallstack(_callstack)
6107 virtual void _OnStart()
override
6113 _M_task = _Attributes::_Generate_Task(_M_func,
this, _M_cts, _M_creationCallstack);
6117 virtual void _OnCancel()
override
6123 _TaskCreationCallstack _M_creationCallstack;
6168 template<
typename _Function>
6170 details::_AsyncTaskGeneratorThunk<_Function> ^create_async(const _Function& _Func)
6172 static_assert(std::is_same<decltype(details::_IsValidCreateAsync(_Func,0,0,0,0)),
std::true_type>::value,
6173 "argument to create_async must be a callable object taking zero, one or two arguments");
6182 template<
typename _Type>
6185 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
6189 void _Resize(
size_t _Len,
bool _SkipVector =
false)
6194 _M_vector._Result.resize(_Len);
6198 task_completion_event<_Unit_type> _M_completed;
6199 _ResultHolder<std::vector<_Type> > _M_vector;
6200 _ResultHolder<_Type> _M_mergeVal;
6205 template<
typename _Type>
6206 struct _RunAllParam<
std::
vector<_Type> >
6208 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
6212 void _Resize(
size_t _Len,
bool _SkipVector =
false)
6218 _M_vector.resize(_Len);
6222 task_completion_event<_Unit_type> _M_completed;
6223 std::vector<_ResultHolder<std::vector<_Type> > > _M_vector;
6230 struct _RunAllParam<_Unit_type>
6232 _RunAllParam() : _M_completeCount(0), _M_numTasks(0)
6236 void _Resize(
size_t _Len)
6241 task_completion_event<_Unit_type> _M_completed;
6246 inline void _JoinAllTokens_Add(
const cancellation_token_source& _MergedSrc, _CancellationTokenState *_PJoinedTokenState)
6251 _T.register_callback( [=](){
6252 _MergedSrc.cancel();
6257 template<
typename _ElementType,
typename _Function,
typename _TaskType>
6258 void _WhenAllContinuationWrapper(_RunAllParam<_ElementType>* _PParam, _Function _Func, task<_TaskType>& _Task)
6260 if (_Task._GetImpl()->_IsCompleted())
6273 _ASSERTE(_Task._GetImpl()->_IsCanceled());
6274 if (_Task._GetImpl()->_HasUserException())
6277 _PParam->_M_completed._Cancel(_Task._GetImpl()->_GetExceptionHolder());
6281 _PParam->_M_completed._Cancel();
6291 template<
typename _ElementType,
typename _Iterator>
6294 static task<std::vector<_ElementType>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6296 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6298 auto _PParam =
new _RunAllParam<_ElementType>();
6299 cancellation_token_source _MergedSource;
6302 task_options _Options(_TaskOptions);
6303 _Options.set_cancellation_token(_MergedSource.get_token());
6304 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6306 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> {
6307 return _PParam->_M_vector.Get();
6313 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6314 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6318 size_t _TaskNum = 0;
6319 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6322 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6324 _PParam->_Resize(_TaskNum);
6328 if( _Begin == _End )
6336 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6338 if (_PTask->is_apartment_aware())
6340 _ReturnTask._SetAsync();
6343 _PTask->_Then([_PParam, _Index](task<_ElementType> _ResultTask) {
6346 typedef _ElementType _ElementTypeDev10;
6347 auto _PParamCopy = _PParam;
6348 auto _IndexCopy = _Index;
6349 auto _Func = [_PParamCopy, _IndexCopy, &_ResultTask](){
6350 _PParamCopy->_M_vector._Result[_IndexCopy] = _ResultTask._GetImpl()->_GetResult();
6353 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6364 template<
typename _ElementType,
typename _Iterator>
6365 struct _WhenAllImpl<
std::
vector<_ElementType>, _Iterator>
6367 static task<std::vector<_ElementType>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6369 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6371 auto _PParam =
new _RunAllParam<std::vector<_ElementType>>();
6372 cancellation_token_source _MergedSource;
6375 task_options _Options(_TaskOptions);
6376 _Options.set_cancellation_token(_MergedSource.get_token());
6377 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6379 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ElementType> {
6380 _ASSERTE(_PParam->_M_completeCount == _PParam->_M_numTasks);
6381 std::vector<_ElementType> _Result;
6382 for(
size_t _I = 0; _I < _PParam->_M_numTasks; _I++)
6384 const std::vector<_ElementType>& _Vec = _PParam->_M_vector[_I].Get();
6385 _Result.insert(_Result.end(), _Vec.begin(), _Vec.end());
6393 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6394 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6398 size_t _TaskNum = 0;
6399 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6402 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6404 _PParam->_Resize(_TaskNum);
6408 if( _Begin == _End )
6416 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6418 if (_PTask->is_apartment_aware())
6420 _ReturnTask._SetAsync();
6423 _PTask->_Then([_PParam, _Index](task<std::vector<_ElementType>> _ResultTask) {
6425 typedef _ElementType _ElementTypeDev10;
6426 auto _PParamCopy = _PParam;
6427 auto _IndexCopy = _Index;
6428 auto _Func = [_PParamCopy, _IndexCopy, &_ResultTask]() {
6429 _PParamCopy->_M_vector[_IndexCopy].Set(_ResultTask._GetImpl()->_GetResult());
6432 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6443 template<
typename _Iterator>
6444 struct _WhenAllImpl<void, _Iterator>
6446 static task<void> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6448 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6450 auto _PParam =
new _RunAllParam<_Unit_type>();
6451 cancellation_token_source _MergedSource;
6454 task_options _Options(_TaskOptions);
6455 _Options.set_cancellation_token(_MergedSource.get_token());
6456 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _Options);
6458 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) {
6464 _JoinAllTokens_Add(_MergedSource, _PTokenState);
6465 _PParam->_Resize(static_cast<size_t>(
std::distance(_Begin, _End)));
6469 size_t _TaskNum = 0;
6470 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6473 _JoinAllTokens_Add(_MergedSource, _PTask->_GetImpl()->_M_pTokenState);
6475 _PParam->_Resize(_TaskNum);
6479 if( _Begin == _End )
6486 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6488 if (_PTask->is_apartment_aware())
6490 _ReturnTask._SetAsync();
6493 _PTask->_Then([_PParam](task<void> _ResultTask) {
6494 auto _Func = [](){};
6495 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6504 template<
typename _ReturnType>
6505 task<std::vector<_ReturnType>> _WhenAllVectorAndValue(
const task<std::vector<_ReturnType>>& _VectorTask,
const task<_ReturnType>& _ValueTask,
6506 bool _OutputVectorFirst)
6508 auto _PParam =
new _RunAllParam<_ReturnType>();
6509 cancellation_token_source _MergedSource;
6512 task<_Unit_type> _All_tasks_completed(_PParam->_M_completed, _MergedSource.get_token());
6514 auto _ReturnTask = _All_tasks_completed._Then([=](_Unit_type) -> std::vector<_ReturnType> {
6515 _ASSERTE(_PParam->_M_completeCount == 2);
6516 auto _Result = _PParam->_M_vector.Get();
6517 auto _mergeVal = _PParam->_M_mergeVal.Get();
6519 if (_OutputVectorFirst ==
true)
6521 _Result.push_back(_mergeVal);
6525 _Result.insert(_Result.begin(), _mergeVal);
6531 _JoinAllTokens_Add(_MergedSource, _VectorTask._GetImpl()->_M_pTokenState);
6532 _JoinAllTokens_Add(_MergedSource, _ValueTask._GetImpl()->_M_pTokenState);
6535 _PParam->_Resize(2,
true);
6537 if (_VectorTask.is_apartment_aware() || _ValueTask.is_apartment_aware())
6539 _ReturnTask._SetAsync();
6541 _VectorTask._Then([_PParam](task<std::vector<_ReturnType>> _ResultTask) {
6543 typedef _ReturnType _ReturnTypeDev10;
6544 auto _PParamCopy = _PParam;
6545 auto _Func = [_PParamCopy, &_ResultTask]() {
6546 auto _ResultLocal = _ResultTask._GetImpl()->_GetResult();
6547 _PParamCopy->_M_vector.Set(_ResultLocal);
6550 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6552 _ValueTask._Then([_PParam](task<_ReturnType> _ResultTask) {
6554 typedef _ReturnType _ReturnTypeDev10;
6555 auto _PParamCopy = _PParam;
6556 auto _Func = [_PParamCopy, &_ResultTask]() {
6557 auto _ResultLocal = _ResultTask._GetImpl()->_GetResult();
6558 _PParamCopy->_M_mergeVal.Set(_ResultLocal);
6561 _WhenAllContinuationWrapper(_PParam, _Func, _ResultTask);
6591 template <
typename _Iterator>
6592 auto when_all(_Iterator _Begin, _Iterator _End,
const task_options& _TaskOptions = task_options())
6593 -> decltype (details::_WhenAllImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_TaskOptions, _Begin, _End))
6595 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6596 return details::_WhenAllImpl<_ElementType, _Iterator>::_Perform(_TaskOptions, _Begin, _End);
6624 template<
typename _ReturnType>
6625 task<std::vector<_ReturnType>>
operator&&(
const task<_ReturnType> & _Lhs,
const task<_ReturnType> & _Rhs)
6627 task<_ReturnType> _PTasks[2] = {_Lhs, _Rhs};
6628 return when_all(_PTasks, _PTasks+2);
6656 template<
typename _ReturnType>
6657 task<std::vector<_ReturnType>>
operator&&(
const task<std::vector<_ReturnType>> & _Lhs,
const task<_ReturnType> & _Rhs)
6659 return details::_WhenAllVectorAndValue(_Lhs, _Rhs,
true);
6687 template<
typename _ReturnType>
6688 task<std::vector<_ReturnType>>
operator&&(
const task<_ReturnType> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6690 return details::_WhenAllVectorAndValue(_Rhs, _Lhs,
false);
6718 template<
typename _ReturnType>
6719 task<std::vector<_ReturnType>>
operator&&(
const task<std::vector<_ReturnType>> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
6721 task<std::vector<_ReturnType>> _PTasks[2] = {_Lhs, _Rhs};
6722 return when_all(_PTasks, _PTasks+2);
6750 inline task<void>
operator&&(
const task<void> & _Lhs,
const task<void> & _Rhs)
6752 task<void> _PTasks[2] = {_Lhs, _Rhs};
6753 return when_all(_PTasks, _PTasks+2);
6759 template <
typename _CompletionType>
6762 _RunAnyParam() : _M_exceptionRelatedToken(nullptr), _M_completeCount(0), _M_numTasks(0), _M_fHasExplicitToken(false)
6768 _M_exceptionRelatedToken->_Release();
6770 task_completion_event<_CompletionType> _M_Completed;
6771 cancellation_token_source _M_cancellationSource;
6772 _CancellationTokenState * _M_exceptionRelatedToken;
6775 bool _M_fHasExplicitToken;
6778 template<
typename _CompletionType,
typename _Function,
typename _TaskType>
6779 void _WhenAnyContinuationWrapper(_RunAnyParam<_CompletionType> * _PParam,
const _Function & _Func, task<_TaskType>& _Task)
6781 bool _IsTokenCancled = !_PParam->_M_fHasExplicitToken && _Task._GetImpl()->_M_pTokenState !=
_CancellationTokenState::_None() && _Task._GetImpl()->_M_pTokenState->_IsCanceled();
6782 if (_Task._GetImpl()->_IsCompleted() && !_IsTokenCancled)
6792 _ASSERTE(_Task._GetImpl()->_IsCanceled() || _IsTokenCancled);
6793 if (_Task._GetImpl()->_HasUserException() && !_IsTokenCancled)
6795 if (_PParam->_M_Completed._StoreException(_Task._GetImpl()->_GetExceptionHolder()))
6798 _PParam->_M_exceptionRelatedToken = _Task._GetImpl()->_M_pTokenState;
6799 _ASSERTE(_PParam->_M_exceptionRelatedToken);
6803 _PParam->_M_exceptionRelatedToken->_Reference();
6811 if (!_PParam->_M_Completed._IsTriggered())
6814 if (!_PParam->_M_fHasExplicitToken)
6816 if (_PParam->_M_exceptionRelatedToken)
6818 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PParam->_M_exceptionRelatedToken);
6824 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _Task._GetImpl()->_M_pTokenState);
6828 _PParam->_M_Completed._Cancel();
6835 template<
typename _ElementType,
typename _Iterator>
6838 static task<std::pair<_ElementType, size_t>> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6840 if( _Begin == _End )
6842 throw invalid_operation(
"when_any(begin, end) cannot be called on an empty container.");
6844 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6845 auto _PParam =
new _RunAnyParam<std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *>>();
6849 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PTokenState);
6850 _PParam->_M_fHasExplicitToken =
true;
6853 task_options _Options(_TaskOptions);
6854 _Options.set_cancellation_token(_PParam->_M_cancellationSource.get_token());
6855 task<std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _Options);
6858 auto _CancellationSource = _PParam->_M_cancellationSource;
6860 _PParam->_M_numTasks =
static_cast<size_t>(
std::distance(_Begin, _End));
6862 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6864 if (_PTask->is_apartment_aware())
6866 _Any_tasks_completed._SetAsync();
6869 _PTask->_Then([_PParam, _Index](task<_ElementType> _ResultTask) {
6870 auto _PParamCopy = _PParam;
6871 auto _IndexCopy = _Index;
6872 auto _Func = [&_ResultTask, _PParamCopy, _IndexCopy]() {
6873 _PParamCopy->_M_Completed.set(
std::make_pair(
std::make_pair(_ResultTask._GetImpl()->_GetResult(), _IndexCopy), _ResultTask._GetImpl()->_M_pTokenState));
6876 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6883 return _Any_tasks_completed._Then([=](std::pair<std::pair<_ElementType, size_t>, _CancellationTokenState *> _Result) -> std::pair<_ElementType, size_t> {
6887 _JoinAllTokens_Add(_CancellationSource, _Result.second);
6889 return _Result.first;
6894 template<
typename _Iterator>
6895 struct _WhenAnyImpl<void, _Iterator>
6897 static task<size_t> _Perform(
const task_options& _TaskOptions, _Iterator _Begin, _Iterator _End)
6899 if( _Begin == _End )
6901 throw invalid_operation(
"when_any(begin, end) cannot be called on an empty container.");
6904 _CancellationTokenState *_PTokenState = _TaskOptions.has_cancellation_token() ? _TaskOptions.get_cancellation_token()._GetImplValue() :
nullptr;
6905 auto _PParam =
new _RunAnyParam<std::pair<size_t, _CancellationTokenState *>>();
6909 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _PTokenState);
6910 _PParam->_M_fHasExplicitToken =
true;
6913 task_options _Options(_TaskOptions);
6914 _Options.set_cancellation_token(_PParam->_M_cancellationSource.get_token());
6915 task<std::pair<size_t, _CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _Options);
6918 auto _CancellationSource = _PParam->_M_cancellationSource;
6920 _PParam->_M_numTasks =
static_cast<size_t>(
std::distance(_Begin, _End));
6922 for (
auto _PTask = _Begin; _PTask != _End; ++_PTask)
6924 if (_PTask->is_apartment_aware())
6926 _Any_tasks_completed._SetAsync();
6929 _PTask->_Then([_PParam, _Index](task<void> _ResultTask) {
6930 auto _PParamCopy = _PParam;
6931 auto _IndexCopy = _Index;
6932 auto _Func = [&_ResultTask, _PParamCopy, _IndexCopy]() {
6933 _PParamCopy->_M_Completed.set(
std::make_pair(_IndexCopy, _ResultTask._GetImpl()->_M_pTokenState));
6935 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
6942 return _Any_tasks_completed._Then([=](std::pair<size_t, _CancellationTokenState *> _Result) ->
size_t {
6946 _JoinAllTokens_Add(_CancellationSource, _Result.second);
6948 return _Result.first;
6974 template<
typename _Iterator>
6975 auto when_any(_Iterator _Begin, _Iterator _End,
const task_options& _TaskOptions = task_options())
6976 -> decltype (details::_WhenAnyImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_TaskOptions, _Begin, _End))
6978 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
6979 return details::_WhenAnyImpl<_ElementType, _Iterator>::_Perform(_TaskOptions, _Begin, _End);
7006 template<
typename _Iterator>
7007 auto when_any(_Iterator _Begin, _Iterator _End, cancellation_token _CancellationToken)
7008 -> decltype (details::_WhenAnyImpl<
typename std::iterator_traits<_Iterator>::value_type::result_type, _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End))
7010 typedef typename std::iterator_traits<_Iterator>::value_type::result_type _ElementType;
7011 return details::_WhenAnyImpl<_ElementType, _Iterator>::_Perform(_CancellationToken._GetImplValue(), _Begin, _End);
7040 template<
typename _ReturnType>
7041 task<_ReturnType>
operator||(
const task<_ReturnType> & _Lhs,
const task<_ReturnType> & _Rhs)
7043 auto _PParam =
new details::_RunAnyParam<std::pair<_ReturnType, size_t>>();
7045 task<std::pair<_ReturnType, size_t>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
7048 auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair<_ReturnType, size_t> _Ret) -> _ReturnType {
7050 _JoinAllTokens_Add(_PParam->_M_cancellationSource, reinterpret_cast<details::_CancellationTokenState *>(_Ret.second));
7054 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
7056 _ReturnTask._SetAsync();
7059 _PParam->_M_numTasks = 2;
7060 auto _Continuation = [_PParam](task<_ReturnType> _ResultTask) {
7062 auto _PParamCopy = _PParam;
7063 auto _Func = [&_ResultTask, _PParamCopy]() {
7064 _PParamCopy->_M_Completed.set(
std::make_pair(_ResultTask._GetImpl()->_GetResult(),
reinterpret_cast<size_t>(_ResultTask._GetImpl()->_M_pTokenState)));
7066 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
7101 template<
typename _ReturnType>
7102 task<std::vector<_ReturnType>>
operator||(
const task<std::vector<_ReturnType>> & _Lhs,
const task<_ReturnType> & _Rhs)
7104 auto _PParam =
new details::_RunAnyParam<std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *>>();
7106 task<std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *>> _Any_tasks_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
7110 auto _ReturnTask = _Any_tasks_completed._Then([=](std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *> _Ret) -> std::vector<_ReturnType> {
7112 _JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second);
7116 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
7118 _ReturnTask._SetAsync();
7121 _PParam->_M_numTasks = 2;
7122 _Lhs._Then([_PParam](task<std::vector<_ReturnType>> _ResultTask) {
7124 auto _PParamCopy = _PParam;
7125 auto _Func = [&_ResultTask, _PParamCopy]() {
7126 auto _Result = _ResultTask._GetImpl()->_GetResult();
7127 _PParamCopy->_M_Completed.set(
std::make_pair(_Result, _ResultTask._GetImpl()->_M_pTokenState));
7129 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
7133 _Rhs._Then([_PParam](task<_ReturnType> _ResultTask)
7136 typedef _ReturnType _ReturnTypeDev10;
7137 auto _PParamCopy = _PParam;
7138 auto _Func = [&_ResultTask, _PParamCopy]() {
7139 auto _Result = _ResultTask._GetImpl()->_GetResult();
7141 std::vector<_ReturnTypeDev10> _Vec;
7142 _Vec.push_back(_Result);
7143 _PParamCopy->_M_Completed.set(
std::make_pair(_Vec, _ResultTask._GetImpl()->_M_pTokenState));
7145 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
7177 template<
typename _ReturnType>
7178 task<std::vector<_ReturnType>>
operator||(
const task<_ReturnType> & _Lhs,
const task<std::vector<_ReturnType>> & _Rhs)
7180 return _Rhs || _Lhs;
7209 inline task<void>
operator||(
const task<void> & _Lhs,
const task<void> & _Rhs)
7211 auto _PParam =
new details::_RunAnyParam<std::pair<details::_Unit_type, details::_CancellationTokenState *>>();
7213 task<std::pair<details::_Unit_type, details::_CancellationTokenState *>> _Any_task_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
7216 auto _ReturnTask = _Any_task_completed._Then([=](std::pair<details::_Unit_type, details::_CancellationTokenState *> _Ret) {
7218 details::_JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second);
7221 if (_Lhs.is_apartment_aware() || _Rhs.is_apartment_aware())
7223 _ReturnTask._SetAsync();
7226 _PParam->_M_numTasks = 2;
7227 auto _Continuation = [_PParam](task<void> _ResultTask)
mutable {
7229 auto _PParam1 = _PParam;
7230 auto _Func = [&_ResultTask, _PParam1]() {
7233 _WhenAnyContinuationWrapper(_PParam, _Func, _ResultTask);
7242 template<
typename _Ty>
7243 task<_Ty> task_from_result(_Ty _Param,
const task_options& _TaskOptions = task_options())
7245 task_completion_event<_Ty> _Tce;
7247 return create_task(_Tce, _TaskOptions);
7251 #if _MSC_VER == 1600
7252 inline task<bool> task_from_result(
bool _Param)
7254 task_completion_event<bool> _Tce;
7256 return create_task(_Tce, task_options());
7259 inline task<void> task_from_result(
const task_options& _TaskOptions = task_options())
7261 task_completion_event<void> _Tce;
7263 return create_task(_Tce, _TaskOptions);
7266 template<
typename _TaskType,
typename _ExType>
7267 task<_TaskType> task_from_exception(_ExType _Exception,
const task_options& _TaskOptions = task_options())
7269 task_completion_event<_TaskType> _Tce;
7270 _Tce.set_exception(_Exception);
7271 return create_task(_Tce, _TaskOptions);
7284 task<bool> do_while(std::function<task<bool>(
void)> func)
7286 task<bool> first = func();
7287 return first.then([=](
bool guard) -> task<bool> {
7289 return do_while(func);
7299 #pragma pop_macro("new")
7300 #pragma warning(pop)
7303 #endif // _PPLTASKS_H
Definition: ppltasks.h:1173
_InitialTaskHandle(const typename details::_Task_ptr< _ReturnType >::_Type &_TaskImpl, const _Function &_func)
Definition: ppltasks.h:3653
void _LogWorkItemStarted()
Definition: ppltasks.h:1549
std::shared_ptr< _ExceptionHolder > _M_exceptionHolder
Definition: ppltasks.h:2291
void _set_creation_callstack(const _TaskCreationCallstack &_callstack)
Definition: ppltasks.h:1178
void _RethrowUserException()
Definition: ppltasks.h:918
virtual ~_PPLTaskHandle()
Definition: ppltasks.h:1584
std::function< _Unit_type(void)> _MakeVoidToUnitFunc(const std::function< void(void)> &_Func)
Definition: ppltasks.h:2582
bool _IsCompleted()
Definition: ppltasks.h:1879
static _TaskCreationCallstack _CaptureSingleFrameCallstack(void *_SingleFrame)
Definition: ppltasks.h:229
_TaskCreationCallstack _M_presetCreationCallstack
Definition: ppltasks.h:1176
_Ty _Type
Definition: ppltasks.h:260
scheduler_ptr _M_Scheduler
Definition: ppltasks.h:1360
void _TaskInitMaybeFunctor(_Function &_Func, std::true_type)
Initializes a task using a callable object.
Definition: ppltasks.h:4549
Definition: ppltasks.h:446
_T atomic_exchange(std::atomic< _T > &_Target, _T _Value)
Definition: pplinterface.h:154
void _LogScheduleTask(bool)
Definition: ppltasks.h:1547
void _Continue(std::false_type, details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3804
void _SyncCancelAndPropagateException() const
Definition: ppltasks.h:3783
task_options()
Default list of task creation options
Definition: ppltasks.h:1203
bool _M_HasScheduler
Definition: ppltasks.h:1365
std::function< _Unit_type(_Unit_type)> _MakeUnitToUnitFunc(const std::function< void(void)> &_Func)
Definition: ppltasks.h:2599
This class describes an exception thrown when an invalid operation is performed that is not more accu...
Definition: concrt.h:1705
Definition: ppltasks.h:1393
void _LogTaskExecutionCompleted()
Definition: ppltasks.h:1552
_ContextCallback & operator=(_ContextCallback &&)
Definition: ppltasks.h:756
_CRTIMP _In_ int _Value
Definition: setjmp.h:190
bool _HasUserException()
Definition: ppltasks.h:1889
Definition: ppltasks.h:1556
_ContextCallback(_ContextCallback &&)
Definition: ppltasks.h:747
_ContextCallback(bool=false)
Definition: ppltasks.h:739
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:4505
exception_ptr current_exception()
Definition: exception:527
std::shared_ptr< _Task_impl_base > _Task_ptr_base
Definition: ppltasks.h:1390
_Holder(_TaskProcThunk *_PThunk)
Definition: ppltasks.h:503
#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:3623
future< typename result_of< _Fty(_ArgTypes...)>::type > _Async(_Launch_type _Policy, _Fty &&_Fnarg, _ArgTypes &&..._Args)
Definition: future:1874
std::function< _Type(_Unit_type)> _MakeUnitToTFunc(const std::function< _Type(void)> &_Func)
Definition: ppltasks.h:2588
_ContinuationList _M_Continuations
Definition: ppltasks.h:2296
details::_Task_ptr< _ReturnType >::_Type _M_ancestorTaskImpl
Definition: ppltasks.h:3751
_Ty _Type
Definition: ppltasks.h:290
void _Perform() const
Definition: ppltasks.h:3668
auto _IsCallable(_Function _Func, int) -> decltype(_Func(), std::true_type())
Definition: ppltasks.h:395
std::vector< void * > _M_frames
Definition: ppltasks.h:221
_TaskCreationCallstack _M_stackTrace
Definition: ppltasks.h:948
scheduler_ptr _GetScheduler() const
Definition: ppltasks.h:2275
~_Task_completion_event_impl()
Definition: ppltasks.h:2562
bool operator==(const _Concurrent_queue_iterator< _C, _Ty > &_I, const _Concurrent_queue_iterator< _C, _U > &_J)
Definition: concurrent_queue.h:317
Definition: concrt.h:4426
Definition: concrt.h:5277
void _LogTaskExecutionStarted()
Definition: ppltasks.h:1551
_Task_ptr_base _GetTaskImplBase() const
Definition: ppltasks.h:1630
void _RunContinuation(_ContinuationTaskHandleBase *_PTaskHandle)
Function executes a continuation. This function is recorded by a parent task implementation when a co...
Definition: ppltasks.h:1964
details::_NormalizeVoidToUnitType< _ContinuationReturnType >::_Type _NormalizedContinuationReturnType
Definition: ppltasks.h:3749
task_options(cancellation_token _Token)
Task option that specify a cancellation token
Definition: ppltasks.h:1215
Definition: ppltasks.h:254
_ContextCallback & operator=(const _ContextCallback &)
Definition: ppltasks.h:751
_PPLTaskHandle(const typename _Task_ptr< _ReturnType >::_Type &_PTask)
Definition: ppltasks.h:1580
static cancellation_token none()
Returns a cancellation token which can never be subject to cancellation.
Definition: pplcancellation_token.h:628
_ContinuationTaskHandleBase * _M_next
Definition: ppltasks.h:1395
auto _FilterValidTaskType(_Ty _Param, int) -> decltype(_GetTaskType(_Param, _IsCallable(_Param, 0)))
bool _IsCanceled()
Definition: ppltasks.h:1884
task(const task &_Other)
Constructs a task object.
Definition: ppltasks.h:3285
This class describes an exception thrown by the PPL tasks layer in order to force the current task to...
Definition: concrt.h:1879
void _Resolve(bool) const
Definition: ppltasks.h:766
task< details::_Unit_type > _M_unitTask
Definition: ppltasks.h:4564
::Concurrency::details::_Task_generator_oversubscriber _Task_generator_oversubscriber_t
Definition: pplconcrt.h:287
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: ppltasks.h:2623
auto _ThenImpl(const _Function &_Func, details::_CancellationTokenState *_PTokenState, const task_continuation_context &_ContinuationContext, scheduler_ptr _Scheduler, details::_TaskCreationCallstack _CreationStack, details::_TaskInliningMode_t _InliningMode=details::_NoInline) const -> typename details::_ContinuationTypeTraits< _Function, _InternalReturnType >::_TaskOfType
The one and only implementation of then for void and non-void tasks.
Definition: ppltasks.h:4062
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:4496
Definition: exception:427
Definition: concrt.h:4427
_Unit_type _Type
Definition: ppltasks.h:266
::Concurrency::details::_TaskCollection_t _M_TaskCollection
Definition: ppltasks.h:2305
task_completion_event()
Constructs a task_completion_event object.
Definition: ppltasks.h:2630
bool _M_fHasValue
Definition: ppltasks.h:2577
_Task_ptr< _ReturnType >::_Type _M_pTask
Definition: ppltasks.h:1635
__declspec(noinline) bool set_exception(std
Propagates an exception to all tasks associated with this event.
Definition: ppltasks.h:2714
_ContextCallback(const _ContextCallback &)
Definition: ppltasks.h:743
task< typename _TaskTypeTraits< typename _FunctionTypeTraits< _Function, _ReturnType >::_FuncRetType >::_TaskRetType > _TaskOfType
Definition: ppltasks.h:448
_In_ intptr_t _In_ int _Action
Definition: process.h:202
static const bool _Value
Definition: ppltasks.h:272
_OutIt move(_InIt _First, _InIt _Last, _OutIt _Dest)
Definition: xutility:2447
file_status status(const _Path &_Pval)
Definition: filesystem:1604
void _Init(details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3683
__declspec(noinline) explicit task(_Ty _Param)
Constructs a task object.
Definition: ppltasks.h:3200
cancellation_token _M_CancellationToken
Definition: ppltasks.h:1361
_Internal_task_options & _get_internal_task_options(task_options &options)
Definition: ppltasks.h:1370
typedef void(__cdecl *_se_translator_function)(unsigned int
void reserve(size_type _Count)
Definition: vector:998
_Function _M_function
Definition: ppltasks.h:3652
Definition: ppltasks.h:789
void _SetImpl(typename details::_Task_ptr< _ReturnType >::_Type &&_Impl)
Set the implementation of the task to be the supplied implementaion using a move instead of a copy...
Definition: ppltasks.h:3606
bool operator==(const task< void > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:4436
std::vector< typename _Task_ptr< _ResultType >::_Type > _TaskList
Definition: ppltasks.h:2550
void _Perform() const
Definition: ppltasks.h:3778
void _TaskInitNoFunctor(task_completion_event< _ReturnType > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:3988
Definition: pplconcrt.h:97
Represents the allowed options for creating a task
Definition: ppltasks.h:1195
task()
Constructs a task object.
Definition: ppltasks.h:4151
The Concurrency namespace provides classes and functions that provide access to the Concurrency Runti...
Definition: agents.h:42
Definition: ppltasks.h:253
Definition: ppltasks.h:3649
bool _M_isTaskBasedContinuation
Definition: ppltasks.h:1397
Definition: ppltasks.h:4618
bool _Cancel(bool _SynchronousCancel)
Definition: ppltasks.h:1810
The implementation of a first-class task. This structure contains the task group used to execute the ...
Definition: ppltasks.h:1380
void _TaskRetType
Definition: ppltasks.h:401
void _SetAsync(bool _Async=true)
Sets a property determining whether the task is apartment aware.
Definition: ppltasks.h:4488
cancellation_token get_cancellation_token() const
Returns the cancellation token
Definition: ppltasks.h:1325
_TaskEventLogger _M_taskEventLogger
Definition: ppltasks.h:2310
#define _REPORT_PPLTASK_UNOBSERVED_EXCEPTION()
Definition: pplconcrt.h:81
_ExceptionHolder(const std::exception_ptr &_E, const _TaskCreationCallstack &_stackTrace)
Definition: ppltasks.h:891
Definition: ppltasks.h:1650
Definition: ppltasks.h:384
_CancellationTokenState * _M_pTokenState
Definition: ppltasks.h:2299
reference_wrapper< _Ty > ref(_Ty &_Val) _NOEXCEPT
Definition: xrefwrap:691
_TaskInliningMode_t _M_inliningMode
Definition: ppltasks.h:1400
integral_constant< bool, false > false_type
Definition: xtr1common:48
bool _IsApartmentAware()
Definition: ppltasks.h:1900
void _Cancel() const
Cancel the task_completion_event. Any task created using this event will be marked as canceled if it ...
Definition: ppltasks.h:2929
Definition: ppltasks.h:1653
scheduler_ptr scheduler() const
Returns the scheduler for this task
Definition: ppltasks.h:4412
iterator_traits< _InIt >::difference_type distance(_InIt _First, _InIt _Last)
Definition: xutility:755
Definition: concrt.h:5273
auto _LogWorkItemAndInvokeUserLambda(_Func &&_func, _Arg &&_value) const -> decltype(_func(std::forward< _Arg >(_value)))
Definition: ppltasks.h:3772
_TypeSelectorNoAsync _AsyncKind
Definition: ppltasks.h:477
task_completion_event< details::_Unit_type > _M_unitEvent
Definition: ppltasks.h:2974
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: ppltasks.h:2883
_Internal_task_options()
Definition: ppltasks.h:1183
unsigned char _Unit_type
Definition: ppltasks.h:247
virtual ~_InitialTaskHandle()
Definition: ppltasks.h:3659
A non-reentrant mutex which is explicitly aware of the Concurrency Runtime.
Definition: concrt.h:3548
__declspec(noinline) bool set_exception(_E _Except) const
Definition: ppltasks.h:2905
bool _CancelWithException(const std::exception_ptr &_Exception)
Definition: ppltasks.h:1831
bool is_done() const
Determines if the task is completed.
Definition: ppltasks.h:3507
Definition: ppltasks.h:378
_TaskProcThunk * _M_pThunk
Definition: ppltasks.h:512
_TaskWorkItemRAIILogger(_TaskEventLogger &)
Definition: ppltasks.h:1558
bool has_scheduler() const
Indicates whether a scheduler n was specified by the user
Definition: ppltasks.h:1341
_TaskCreationCallstack()
Definition: ppltasks.h:223
bool _IsTriggered() const
Tests whether current event has been either Set, or Canceled.
Definition: ppltasks.h:2773
void _DeregisterCancellation()
Definition: ppltasks.h:1854
void _LogWorkItemCompleted()
Definition: ppltasks.h:1550
void _ScheduleContinuationTask(_ContinuationTaskHandleBase *_PTaskHandle)
Definition: ppltasks.h:1996
Definition: concrt.h:5275
Definition: ppltasks.h:270
static std::shared_ptr< details::_ExceptionHolder > _ToExceptionHolder(std::exception_ptr _ExceptionPtr, const details::_TaskCreationCallstack &_SetExceptionAddressHint)
Definition: ppltasks.h:2785
details::_Internal_task_options _M_InternalTaskOptions
Definition: ppltasks.h:1363
task_status _Wait()
Definition: ppltasks.h:1679
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:2948
void * _M_SingleFrame
Definition: ppltasks.h:220
void _SetImpl(details::_Task_ptr< details::_Unit_type >::_Type &&_Impl)
Set the implementation of the task to be the supplied implementaion using a move instead of a copy...
Definition: ppltasks.h:4480
void _TaskInitMaybeFunctor(_Function &_Func, std::true_type)
Initializes a task using a callable object.
Definition: ppltasks.h:4030
#define _ASSERTE(expr)
Definition: crtdbg.h:216
bool operator==(const _ContextCallback &) const
Definition: ppltasks.h:775
_In_ size_t _In_z_ const unsigned char * _Src
Definition: mbstring.h:95
task()
Constructs a task object.
Definition: ppltasks.h:3158
Definition: ppltasks.h:878
void _Continue(std::false_type, details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3818
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:2369
shared_ptr< _Ty > make_shared(_Types &&..._Args)
Definition: memory:1000
void _Init(details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3696
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:4105
volatile _TaskInternalState _M_TaskState
Definition: ppltasks.h:2281
_UnwrapTaskType< _Type >::_Type _TaskRetType
Definition: ppltasks.h:386
_TaskEventLogger(_Task_impl_base *)
Definition: ppltasks.h:1554
Definition: vccorlib.h:112
_TaskInliningMode
The enum defines inlining scheduling policy for ppltasks. Scheduling a chore or a functor with _TaskI...
Definition: concrt.h:5270
virtual ~_Task_impl_base()
Definition: ppltasks.h:1670
::Concurrency::extensibility::critical_section_t _M_ContinuationsCritSec
Definition: ppltasks.h:2295
#define FAILED(hr)
Definition: comutil.h:71
_ResultHolder< _ResultType > _M_value
Definition: ppltasks.h:2575
bool has_cancellation_token() const
Indicates whether a cancellation token was specified by the user
Definition: ppltasks.h:1317
#define bool
Definition: stdbool.h:10
task_continuation_context get_continuation_context() const
Returns the continuation context
Definition: ppltasks.h:1333
_ContinuationTaskHandleBase * _ContinuationList
Definition: ppltasks.h:2293
_Boolarray operator&&(const valarray< _Ty > &_Left, const _Ty &_Right)
Definition: valarray:661
bool operator!=(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent different internal tasks.
Definition: ppltasks.h:3568
_TaskList _M_tasks
Definition: ppltasks.h:2573
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:328
void _LogCancelTask()
Definition: ppltasks.h:1548
std::shared_ptr< _Task_impl< _ReturnType > > _Type
Definition: ppltasks.h:1385
static void _RunTask(TaskProc _Proc, void *_Parameter, _TaskInliningMode _InliningMode)
Definition: pplconcrt.h:237
auto _IsValidTaskCtor(_Ty _Param, int, int, int, int) -> decltype(_Param(), std::true_type())
atomic_long _M_exceptionObserved
Definition: ppltasks.h:936
_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:2780
_TaskTypeTraits< _FuncRetType >::_AsyncKind _AsyncKind
Definition: ppltasks.h:469
Definition: ppltasks.h:258
bool _IsCreated()
Definition: ppltasks.h:1864
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: ppltasks.h:4120
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:3461
The tasks queued to the task_group or structured_task_group object completed successfully.
Definition: pplinterface.h:127
bool _IsTriggered() const
Test whether current event has been either Set, or Canceled.
Definition: ppltasks.h:2956
bool operator!=(const task< void > &_Rhs) const
Determines whether two task objects represent different internal tasks.
Definition: ppltasks.h:4448
auto _ThenImpl(const _Function &_Func, const task_options &_TaskOptions) const -> typename details::_ContinuationTypeTraits< _Function, _InternalReturnType >::_TaskOfType
Definition: ppltasks.h:4045
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplinterface.h:133
auto _IsTaskHelper(_Type t, _Function _Func, int, int) -> decltype(_Func(_To_task(t)), std::true_type())
Definition: pplcancellation_token.h:104
Definition: ppltasks.h:1383
void _ScheduleContinuation(_ContinuationTaskHandleBase *_PTaskHandle)
Schedule the actual continuation. This will either schedule the function on the continuation task's i...
Definition: ppltasks.h:2067
::Concurrency::extensibility::critical_section_t _M_taskListCritSec
Definition: ppltasks.h:2574
task_options(task_continuation_context _ContinuationContext)
Task option that specify a continuation context. This is valid only for continuations (then) ...
Definition: ppltasks.h:1227
Definition: ppltasks.h:249
__declspec(noinline) static _TaskCreationCallstack _CaptureMultiFramesCallstack(size_t _CaptureFrames)
Definition: ppltasks.h:237
Definition: ppltasks.h:1545
bool _CancelWithExceptionHolder(const std::shared_ptr< _ExceptionHolder > &_ExHolder, bool _PropagatedFromAncestor)
Definition: ppltasks.h:1816
auto _ReturnTypeHelper(_Type t, _Function _Func, int, int) -> decltype(_Func(_To_task(t)))
_TaskInternalState
Definition: ppltasks.h:1647
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:2757
__declspec(noinline) auto then(const _Function &_Func) const -> typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_TaskOfType
Adds a continuation task to this task.
Definition: ppltasks.h:3375
void rethrow_exception(_In_ exception_ptr _P)
Definition: exception:532
details::_Task_completion_event_impl< details::_Unit_type >::_TaskList _TaskList
Definition: ppltasks.h:2794
std::exception_ptr _M_stdException
Definition: ppltasks.h:939
Definition: pplconcrt.h:129
std::function< _Unit_type(_Type)> _MakeTToUnitFunc(const std::function< void(_Type)> &_Func)
Definition: ppltasks.h:2594
#define false
Definition: stdbool.h:11
void Set(const _Type &_type)
Definition: ppltasks.h:791
bool is_apartment_aware() const
Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such ...
Definition: ppltasks.h:3540
#define or
Definition: iso646.h:15
auto _GetUnwrappedReturnType(_Ty _Arg, int) -> decltype(_GetUnwrappedType(_Arg))
_TaskCollection_t::_TaskProcHandle_t _UnrealizedChore_t
Definition: ppltasks.h:1389
static _ContextCallback _CaptureCurrent()
Definition: ppltasks.h:734
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:2968
auto _VoidIsTaskHelper(_Function _Func, int, int) -> decltype(_Func(_To_task()), std::true_type())
Definition: ppltasks.h:2542
bool __cdecl is_task_cancellation_requested()
Returns an indication of whether the task that is currently executing has received a request to cance...
Definition: ppltasks.h:188
_Task_impl_base(_CancellationTokenState *_PTokenState, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1657
bool _IsPendingCancel()
Definition: ppltasks.h:1874
task & operator=(task &&_Other)
Replaces the contents of one task object with another.
Definition: ppltasks.h:3345
The task_continuation_context class allows you to specify where you would like a continuation to be e...
Definition: ppltasks.h:1088
task(task &&_Other)
Constructs a task object.
Definition: ppltasks.h:3312
void _SetImpl(const typename details::_Task_ptr< _ReturnType >::_Type &_Impl)
Set the implementation of the task to be the supplied implementaion.
Definition: ppltasks.h:3597
Represents a pointer to a scheduler. This class exists to allow the the specification of a shared lif...
Definition: pplinterface.h:58
bool _M_hasPresetCreationCallstack
Definition: ppltasks.h:1175
_TaskCreationCallstack _M_pTaskCreationCallstack
Definition: ppltasks.h:2308
virtual ~_ContinuationTaskHandle()
Definition: ppltasks.h:3769
void _SetAsync(bool _Async=true)
Sets a property determining whether the task is apartment aware.
Definition: ppltasks.h:3615
_CancellationTokenRegistration * _M_pRegistration
Definition: ppltasks.h:2302
void _ScheduleTask(_UnrealizedChore_t *_PTaskHandle, _TaskInliningMode_t _InliningMode)
Helper function to schedule the task on the Task Collection.
Definition: ppltasks.h:1929
void set_continuation_context(task_continuation_context _ContinuationContext)
Sets the given continuation context in the options
Definition: ppltasks.h:1309
bool _CancelInternal() const
Cancels the task_completion_event.
Definition: ppltasks.h:2799
task_options(const task_options &_TaskOptions)
Task option copy constructor
Definition: ppltasks.h:1288
_Task_impl(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:2354
_In_ wctype_t _Type
Definition: ctype.h:205
bool operator==(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:3556
_Function _M_function
Definition: ppltasks.h:3752
bool _M_fUnwrappedTask
Definition: ppltasks.h:2286
bool _IsDone()
Definition: ppltasks.h:2525
bool operator!=(const _ContextCallback &) const
Definition: ppltasks.h:780
Definition: ppltasks.h:430
bool _M_fFromAsync
Definition: ppltasks.h:2284
virtual _Task_ptr_base _GetTaskImplBase() const =0
_T atomic_increment(std::atomic< _T > &_Target)
Definition: pplinterface.h:160
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:2846
static bool _IsValid(_In_opt_ _CancellationTokenState *_PToken)
Definition: pplcancellation_token.h:333
task_options(scheduler_ptr _Scheduler)
Task option that specify a scheduler
Definition: ppltasks.h:1276
_Boolarray operator||(const valarray< _Ty > &_Left, const _Ty &_Right)
Definition: valarray:675
Definition: ppltasks.h:414
void _CreateImpl(details::_CancellationTokenState *_Ct, scheduler_ptr _Scheduler)
Create an underlying task implementation.
Definition: ppltasks.h:3576
std::shared_ptr< _ExceptionHolder > _M_exceptionHolder
Definition: ppltasks.h:2576
task_options(std::shared_ptr< _SchedType > _Scheduler)
Task option that specify a scheduler with shared lifetime
Definition: ppltasks.h:1252
void ReportUnhandledError()
Definition: ppltasks.h:881
#define _T(x)
Definition: tchar.h:2498
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:2938
void _TaskInitWithFunctor(const _Function &_Func)
Initializes a task using a lambda, function pointer or function object.
Definition: ppltasks.h:3975
task_group_status
Describes the execution status of a task_group or structured_task_group object. A value of this type ...
Definition: pplinterface.h:114
__declspec(noinline) bool set_exception(std
Propagates an exception to all tasks associated with this event.
Definition: ppltasks.h:2918
bool _IsStarted()
Definition: ppltasks.h:1869
#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:162
for(;0< _Count;)
Definition: algorithm:1944
Definition: ppltasks.h:538
void _Continue(std::true_type, details::_TypeSelectorNoAsync) const
Definition: ppltasks.h:3885
_ReturnType result_type
The type of the result an object of this class produces.
Definition: ppltasks.h:3134
static _Type _Make(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1386
bool set(_ResultType _Result) const
Sets the task completion event.
Definition: ppltasks.h:2651
Definition: pplcancellation_token.h:212
task_continuation_context _M_continuationContext
Definition: ppltasks.h:1396
_Task_completion_event_impl()
Definition: ppltasks.h:2552
std::shared_ptr< details::_Task_completion_event_impl< _ResultType > > _M_Impl
Definition: ppltasks.h:2865
if(__pUnknown!=*__ppTargetUnknown)
Definition: vccorlib.h:394
void set_cancellation_token(cancellation_token _Token)
Sets the given token in the options
Definition: ppltasks.h:1300
void _SetImpl(const details::_Task_ptr< details::_Unit_type >::_Type &_Impl)
Set the implementation of the task to be the supplied implementaion.
Definition: ppltasks.h:4472
static void __cdecl _Bridge(void *_PData)
Definition: ppltasks.h:492
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: ppltasks.h:134
Definition: ppltasks.h:114
__declspec(noinline) bool set_exception(_E _Except) const
Definition: ppltasks.h:2700
bool _M_fIsCanceled
Definition: ppltasks.h:2578
scheduler_ptr scheduler() const
Returns the scheduler for this task
Definition: ppltasks.h:3523
void _LogTaskCompleted()
Definition: ppltasks.h:1553
#define _ASSERT(expr)
Definition: crtdbg.h:212
auto _VoidReturnTypeHelper(_Function _Func, int, int) -> decltype(_Func(_To_task()))
add_rvalue_reference< _Ty >::type declval() _NOEXCEPT
_ResultHolder< _ReturnType > _M_Result
Definition: ppltasks.h:2535
_ImplType _GetImplValue() const
Definition: pplcancellation_token.h:748
integral_constant< bool, true > true_type
Definition: xtr1common:47
bool _Cancel() const
Internal method to cancel the task_completion_event. Any task created using this event will be marked...
Definition: ppltasks.h:2725
_Diff _Count
Definition: algorithm:1941
task< _Type > _To_task(_Type t)
Definition: ppltasks.h:282
static void _AsyncInit(const typename _Task_ptr< _ReturnType >::_Type &_OuterTask, const task< _InternalReturnType > &_UnwrappedTask)
Definition: ppltasks.h:2240
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler())
_Type Get()
Definition: ppltasks.h:796
bool _HasCapturedContext() const
Definition: ppltasks.h:761
void _LogCancelTask(_Task_impl_base *)
Definition: ppltasks.h:1544
Helper object used for LWT invocation.
Definition: ppltasks.h:485
task_continuation_context _M_ContinuationContext
Definition: ppltasks.h:1362
std::atomic< long > atomic_long
Atomics
Definition: pplinterface.h:142
auto _LogWorkItemAndInvokeUserLambda(_Func &&_func) const -> decltype(_func())
Definition: ppltasks.h:3662
__declspec(deprecated("Concurrency::EnableTracing is a deprecated function.")) _CRTIMP HRESULT __cdecl EnableTracing()
Enables tracing in the Concurrency Runtime. This function is deprecated because ETW tracing is now on...
The task handle type used to create a 'continuation task'.
Definition: ppltasks.h:3745
void _Continue(std::true_type, details::_TypeSelectorAsyncOperationOrTask) const
Definition: ppltasks.h:3903
Definition: xtr1common:94
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:1239
exception_ptr make_exception_ptr(_E _Except)
Definition: exception:539
void _SetTaskCreationCallstack(const _TaskCreationCallstack &_Callstack)
Definition: ppltasks.h:1915
_TypeSelectorNoAsync _AsyncKind
Definition: ppltasks.h:402
_Ty _Type
Definition: ppltasks.h:284
const std::shared_ptr< _ExceptionHolder > & _GetExceptionHolder()
Definition: ppltasks.h:1894
Definition: ppltasks.h:1651
bool is_apartment_aware() const
Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such ...
Definition: ppltasks.h:4424
_Ty _GetUnwrappedType(task< _Ty >)
The following type traits are used for the create_task function.
void _RunTaskContinuations()
Definition: ppltasks.h:2133
_TypeSelectorAsyncTask _AsyncOperationKindSelector(task< _T >)
task & operator=(const task &_Other)
Replaces the contents of one task object with another.
Definition: ppltasks.h:3325
_Unit_type _NormalizedTaskRetType
Definition: ppltasks.h:403
bool _M_HasCancellationToken
Definition: ppltasks.h:1364
bool _HasUserException()
Definition: ppltasks.h:2557
void result_type
The type of the result an object of this class produces.
Definition: ppltasks.h:4127
static task_continuation_context use_default()
Creates the default task continuation context.
Definition: ppltasks.h:1109
The base implementation of a first-class task. This class contains all the non-type specific implemen...
Definition: ppltasks.h:1645
void _FinalizeAndRunContinuations(_ReturnType _Result)
Definition: ppltasks.h:2465
_TaskCreationCallstack _GetTaskCreationCallstack()
Definition: ppltasks.h:1910
bool operator!=(const _Concurrent_queue_iterator< _C, _Ty > &_I, const _Concurrent_queue_iterator< _C, _U > &_J)
Definition: concurrent_queue.h:323
void _CreateImpl(details::_CancellationTokenState *_Ct, scheduler_ptr _Scheduler)
Create an underlying task implementation.
Definition: ppltasks.h:4456
void _SyncCancelAndPropagateException() const
Definition: ppltasks.h:3673
task_options(scheduler_interface &_Scheduler)
Task option that specify a scheduler reference
Definition: ppltasks.h:1264
const details::_Task_ptr< details::_Unit_type >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:4464
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:3634
An exception safe RAII wrapper for a critical_section object.
Definition: concrt.h:3661
Definition: ppltasks.h:4627
std::function< void(void)> _CallbackFunction
Definition: ppltasks.h:540
~_Holder()
Definition: ppltasks.h:507
virtual ~_ContinuationTaskHandleBase()
Definition: ppltasks.h:1409
Definition: pplcancellation_token.h:167
Definition: ppltasks.h:467
_FwdIt const _Ty _Val
Definition: algorithm:1938
bool set() const
Sets the task completion event.
Definition: ppltasks.h:2899
virtual void invoke() const
Definition: ppltasks.h:1590
void _CallInContext(_CallbackFunction _Func) const
Definition: ppltasks.h:770
std::function< void()> _M_func
Definition: ppltasks.h:518
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3589
Definition: ppltasks.h:255
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:4373
_ContinuationTaskHandleBase()
Definition: ppltasks.h:1404
void _RegisterCancellation(std::weak_ptr< _Task_impl_base > _WeakPtr)
Definition: ppltasks.h:1838
virtual ~_Task_impl()
Definition: ppltasks.h:2362
_TaskProcThunk(const std::function< void()> &_Callback)
Definition: ppltasks.h:487
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:3754
long __cdecl _InterlockedCompareExchange(long volatile *, long, long)
std::shared_ptr< ::Concurrency::scheduler_interface > get_ambient_scheduler()
Definition: pplconcrt.h:64
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:533
Definition: ppltasks.h:252
bool _TransitionedToStarted()
Definition: ppltasks.h:2494
#define true
Definition: stdbool.h:12
Definition: ppltasks.h:251
The _PPLTaskHandle is the strong-typed task handle base. All user task functions need to be wrapped i...
Definition: ppltasks.h:1578
void _TaskInitMaybeFunctor(_T &_Param, std::false_type)
Initializes a task using a non-callable object.
Definition: ppltasks.h:4558
task_continuation_context(bool _DeferCapture=false)
Definition: ppltasks.h:1165
task_group_status task_status
A type that represents the terminal state of a task. Valid values are completed and canceled...
Definition: ppltasks.h:132
bool is_done() const
Determines if the task is completed.
Definition: ppltasks.h:4401
pair< typename _Unrefwrap< _Ty1 >::type, typename _Unrefwrap< _Ty2 >::type > make_pair(_Ty1 &&_Val1, _Ty2 &&_Val2)
Definition: utility:267
scheduler_ptr get_scheduler() const
Returns the scheduler
Definition: ppltasks.h:1349
const _Ty & _Right
Definition: algorithm:4087
_Type _Result
Definition: ppltasks.h:801
Definition: ppltasks.h:501
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:2736
Definition: ppltasks.h:1652
void _SetAsync(bool _Async=true)
Definition: ppltasks.h:1905
void _TaskInitNoFunctor(task_completion_event< void > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:4521
void _TaskInitMaybeFunctor(_Ty &_Param, std::false_type)
Initializes a task using a non-callable object.
Definition: ppltasks.h:4039
void _ValidateTaskConstructorArgs(_Ty _Param)
Definition: ppltasks.h:3007
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:215
_ReturnType _GetResult()
Definition: ppltasks.h:2530
__declspec(noinline)~_ExceptionHolder()
Definition: ppltasks.h:906
Definition: ppltasks.h:250