/*** * ==++== * * Copyright (c) Microsoft Corporation. All rights reserved. * * Modified for native C++ WRL support by Gregory Morse * * ==--== * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ * * ppltasks_winrt.h * * Parallel Patterns Library - PPL Tasks * * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ****/ #pragma once #include #include #include #include #include #include #include #ifndef __cplusplus_winrt #include #include #include #include #ifndef _UITHREADCTXT_SUPPORT #ifdef WINAPI_FAMILY // It is safe to include winapifamily as WINAPI_FAMILY was defined by the user #include #if WINAPI_FAMILY == WINAPI_FAMILY_APP /*IFSTRIP=IGN*/ // UI thread context support is not required for desktop and Windows Store apps #define _UITHREADCTXT_SUPPORT 0 #elif WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP /*IFSTRIP=IGN*/ // UI thread context support is not required for desktop and Windows Store apps #define _UITHREADCTXT_SUPPORT 0 #else #define _UITHREADCTXT_SUPPORT 1 #endif #else // Not supported without a WINAPI_FAMILY setting. #define _UITHREADCTXT_SUPPORT 0 #endif // #ifdef WINAPI_FAMILY #endif // #ifndef _UITHREADCTXT_SUPPORT #if _UITHREADCTXT_SUPPORT #include #endif // _UITHREADCTXT_SUPPORT #pragma detect_mismatch("_PPLTASKS_WITH_WINRT", "0") #pragma pack(push,_CRT_PACKING) #pragma warning(push) #pragma warning(disable: 28197) #pragma warning(disable: 4100) // Unreferenced formal parameter - needed for document generation #pragma warning(disable: 4702) // Unreachable code - it is caused by user lambda throw exceptions // All CRT public header files are required to be protected from the macro new #pragma push_macro("new") #undef new #define __is_valid_winrt_type(_Type) (std::is_void<_Type>::value || \ std::is_same<_Type, BYTE>::value || \ std::is_same<_Type, INT16>::value || \ std::is_same<_Type, UINT16>::value || \ std::is_same<_Type, INT32>::value || \ std::is_same<_Type, UINT32>::value || \ std::is_same<_Type, INT64>::value || \ std::is_same<_Type, UINT64>::value || \ std::is_same<_Type, FLOAT>::value || \ std::is_same<_Type, DOUBLE>::value || \ std::is_same<_Type, WCHAR>::value || \ std::is_same<_Type, boolean>::value || \ std::is_same<_Type, HSTRING>::value || \ std::is_same<_Type, IInspectable *>::value || \ std::is_same<_Type, GUID>::value || \ std::is_same<_Type, ABI::Windows::Foundation::DateTime>::value || \ std::is_same<_Type, ABI::Windows::Foundation::TimeSpan>::value || \ std::is_same<_Type, ABI::Windows::Foundation::Point>::value || \ std::is_same<_Type, ABI::Windows::Foundation::Size>::value || \ std::is_same<_Type, ABI::Windows::Foundation::Rect>::value || \ std::is_same<_Type, BYTE*>::value || \ std::is_same<_Type, INT16*>::value || \ std::is_same<_Type, UINT16*>::value || \ std::is_same<_Type, INT32*>::value || \ std::is_same<_Type, UINT32*>::value || \ std::is_same<_Type, INT64*>::value || \ std::is_same<_Type, UINT64*>::value || \ std::is_same<_Type, FLOAT*>::value || \ std::is_same<_Type, DOUBLE*>::value || \ std::is_same<_Type, WCHAR*>::value || \ std::is_same<_Type, boolean*>::value || \ std::is_same<_Type, HSTRING*>::value || \ std::is_same<_Type, IInspectable **>::value || \ std::is_same<_Type, GUID*>::value || \ std::is_same<_Type, ABI::Windows::Foundation::DateTime*>::value || \ std::is_same<_Type, ABI::Windows::Foundation::TimeSpan*>::value || \ std::is_same<_Type, ABI::Windows::Foundation::Point*>::value || \ std::is_same<_Type, ABI::Windows::Foundation::Size*>::value || \ std::is_same<_Type, ABI::Windows::Foundation::Rect*>::value) /// /// The Concurrency_winrt namespace provides classes and functions that give you access to the Concurrency Runtime, /// a concurrent programming framework for C++. For more information, see . /// /**/ namespace Concurrency_winrt { /// /// A type that represents the terminal state of a task. Valid values are completed and canceled. /// /// /**/ typedef Concurrency::task_group_status task_status; template class task; template <> class task; /// /// Returns an indication of whether the task that is currently executing has received a request to cancel its /// execution. Cancellation is requested on a task if the task was created with a cancellation token, and /// the token source associated with that token is canceled. /// /// /// true if the currently executing task has received a request for cancellation, false otherwise. /// /// /// If you call this method in the body of a task and it returns true, you must respond with a call to /// cancel_current_task to acknowledge the cancellation request, /// after performing any cleanup you need. This will abort the execution of the task and cause it to enter into /// the canceled state. If you do not respond and continue execution, or return instead of calling /// cancel_current_task, the task will enter the completed state when it is done. /// state. /// A task is not cancellable if it was created without a cancellation token. /// /// /// /// /// /**/ _CRTIMP2 bool __cdecl is_task_cancellation_requested(); /// /// Cancels the currently executing task. This function can be called from within the body of a task to abort the /// task's execution and cause it to enter the canceled state. While it may be used in response to /// the is_task_cancellation_requested function, you may /// also use it by itself, to initiate cancellation of the task that is currently executing. /// It is not a supported scenario to call this function if you are not within the body of a task. /// Doing so will result in undefined behavior such as a crash or a hang in your application. /// /// /// /**/ _CRTIMP2 __declspec(noreturn) void __cdecl cancel_current_task(); namespace details { typedef UINT32 _Unit_type; struct _TypeSelectorNoAsync {}; struct _TypeSelectorAsyncOperationOrTask {}; struct _TypeSelectorAsyncOperation : public _TypeSelectorAsyncOperationOrTask { }; struct _TypeSelectorAsyncTask : public _TypeSelectorAsyncOperationOrTask { }; struct _TypeSelectorAsyncAction {}; struct _TypeSelectorAsyncActionWithProgress {}; struct _TypeSelectorAsyncOperationWithProgress {}; template struct _NormalizeVoidToUnitType { typedef _Ty _Type; }; template<> struct _NormalizeVoidToUnitType { typedef _Unit_type _Type; }; template struct _IsUnwrappedAsyncSelector { static const bool _Value = true; }; template<> struct _IsUnwrappedAsyncSelector<_TypeSelectorNoAsync> { static const bool _Value = false; }; template struct _UnwrapTaskType { typedef _Ty _Type; }; template struct _UnwrapTaskType> { typedef _Ty _Type; }; template _TypeSelectorAsyncTask _AsyncOperationKindSelector(task<_T>); _TypeSelectorNoAsync _AsyncOperationKindSelector(...); template struct _Unhat { typedef _Type _Value; }; template struct _Unhat<_Type*> { typedef _Type _Value; }; struct _NonUserType { public: int _Dummy; }; template struct _ValueTypeOrRefType { typedef _NonUserType _Value; }; template struct _ValueTypeOrRefType<_Type, true> { typedef _Type _Value; }; template _T2 _ProgressTypeSelector(ABI::Windows::Foundation::IAsyncOperationWithProgress<_T1, _T2>*); template _T1 _ProgressTypeSelector(ABI::Windows::Foundation::IAsyncActionWithProgress<_T1>*); template struct _GetProgressType { typedef decltype(_ProgressTypeSelector(std::declval<_Type>())) _Value; }; template