STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Concurrency::task< _ReturnType > Class Template Reference

The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed asynchronously, and concurrently with other tasks and parallel work produced by parallel algorithms in the Concurrency Runtime. It produces a result of type _ResultType on successful completion. Tasks of type task<void> produce no result. A task can be waited upon and canceled independently of other tasks. It can also be composed with other tasks using continuations(then), and join(when_all) and choice(when_any) patterns. More...

#include <ppltasks.h>

Classes

struct  _ContinuationTaskHandle
 The task handle type used to create a 'continuation task'. More...
 
struct  _InitialTaskHandle
 

Public Types

typedef _ReturnType result_type
 The type of the result an object of this class produces. More...
 

Public Member Functions

 task ()
 Constructs a task object. More...
 
template<typename _Ty >
 __declspec (noinline) explicit task(_Ty _Param)
 Constructs a task object. More...
 
template<typename _Ty >
 __declspec (noinline) explicit task(_Ty _Param
 Constructs a task object. More...
 
 _CreateImpl (_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler())
 
 _SetTaskCreationCallstack (details::_get_internal_task_options(_TaskOptions)._M_hasPresetCreationCallstack?details::_get_internal_task_options(_TaskOptions)._M_presetCreationCallstack:_CAPTURE_CALLSTACK())
 
 _TaskInitMaybeFunctor (_Param, decltype(details::_IsCallable(_Param, 0))())
 
 task (const task &_Other)
 Constructs a task object. More...
 
 task (task &&_Other)
 Constructs a task object. More...
 
taskoperator= (const task &_Other)
 Replaces the contents of one task object with another. More...
 
taskoperator= (task &&_Other)
 Replaces the contents of one task object with another. More...
 
template<typename _Function >
 __declspec (noinline) auto then(const _Function &_Func) const -> typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_TaskOfType
 Adds a continuation task to this task. More...
 
template<typename _Function >
 __declspec (noinline) auto then(const _Function &_Func
 Adds a continuation task to this task. More...
 
return _ThenImpl (typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_StdFuncT(_Func), _Options)
 
template<typename _Function >
 __declspec (noinline) auto then(const _Function &_Func
 Adds a continuation task to this task. More...
 
 details::_get_internal_task_options (_TaskOptions)._set_creation_callstack(_CAPTURE_CALLSTACK())
 
return _ThenImpl (typename details::_ContinuationTypeTraits< _Function, _ReturnType >::_StdFuncT(_Func), _Options)
 
task_status wait () const
 Waits for this task to reach a terminal state. It is possible for wait to execute the task inline, if all of the tasks dependencies are satisfied, and it has not already been picked up for execution by a background worker. More...
 
_ReturnType get () const
 Returns the result this task produced. If the task is not in a terminal state, a call to get will wait for the task to finish. This method does not return a value when called on a task with a result_type of void. More...
 
bool is_done () const
 Determines if the task is completed. More...
 
scheduler_ptr scheduler () const
 Returns the scheduler for this task More...
 
bool is_apartment_aware () const
 Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such a task. More...
 
bool operator== (const task< _ReturnType > &_Rhs) const
 Determines whether two task objects represent the same internal task. More...
 
bool operator!= (const task< _ReturnType > &_Rhs) const
 Determines whether two task objects represent different internal tasks. More...
 
void _CreateImpl (details::_CancellationTokenState *_Ct, scheduler_ptr _Scheduler)
 Create an underlying task implementation. More...
 
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl () const
 Return the underlying implementation for this task. More...
 
const details::_Task_ptr< _ReturnType >::_Type & _ThenGetImpl () const
 
void _SetImpl (const typename details::_Task_ptr< _ReturnType >::_Type &_Impl)
 Set the implementation of the task to be the supplied implementation. More...
 
void _SetImpl (typename details::_Task_ptr< _ReturnType >::_Type &&_Impl)
 Set the implementation of the task to be the supplied implementation using a move instead of a copy. More...
 
void _SetAsync (bool _Async=true)
 Sets a property determining whether the task is apartment aware. More...
 
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 method. More...
 
template<typename _Function >
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 default. When _ForceInline is set to false, continuations inlining will be limited to default _DefaultAutoInline. This function is Used for runtime internal continuations only. More...
 

Public Attributes

const task_options_TaskOptions
 
auto _ContinuationContext = _TaskOptions.get_continuation_context()
 
auto _Options = details::_ThenImplOptions::_CreateOptions(_TaskOptions, _ContinuationContext, _ThenGetImpl()->_GetScheduler())
 
cancellation_token _CancellationToken
 

Private Member Functions

template<typename _InternalReturnType , typename _Function >
void _TaskInitWithFunctor (const _Function &_Func)
 Initializes a task using a lambda, function pointer or function object. More...
 
void _TaskInitNoFunctor (task_completion_event< _ReturnType > &_Event)
 Initializes a task using a task completion event. More...
 
template<typename _Function >
void _TaskInitMaybeFunctor (_Function &_Func, std::true_type)
 Initializes a task using a callable object. More...
 
template<typename _Ty >
void _TaskInitMaybeFunctor (_Ty &_Param, std::false_type)
 Initializes a task using a non-callable object. More...
 
template<typename _InternalReturnType , typename _Function >
auto _ThenImpl (const _Function &_Func, details::_ThenImplOptions &_Options) const -> typename details::_ContinuationTypeTraits< _Function, _InternalReturnType >::_TaskOfType
 The one and only implementation of then for void and non-void tasks. More...
 

Private Attributes

details::_Task_ptr< _ReturnType >::_Type _M_Impl
 

Friends

template<typename _Ty >
class task
 

Detailed Description

template<typename _ReturnType>
class Concurrency::task< _ReturnType >

The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed asynchronously, and concurrently with other tasks and parallel work produced by parallel algorithms in the Concurrency Runtime. It produces a result of type _ResultType on successful completion. Tasks of type task<void> produce no result. A task can be waited upon and canceled independently of other tasks. It can also be composed with other tasks using continuations(then), and join(when_all) and choice(when_any) patterns.

Template Parameters
_ReturnTypeThe result type of this task.

For more information, see Task Parallelism (Concurrency Runtime).

Member Typedef Documentation

template<typename _ReturnType>
typedef _ReturnType Concurrency::task< _ReturnType >::result_type

The type of the result an object of this class produces.

Constructor & Destructor Documentation

template<typename _ReturnType>
Concurrency::task< _ReturnType >::task ( )
inline

Constructs a task object.

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

For more information, see Task Parallelism (Concurrency Runtime).

2911  : _M_Impl(nullptr)
2912  {
2913  // The default constructor should create a task with a nullptr impl. This is a signal that the
2914  // task is not usable and should throw if any wait(), get() or then() APIs are used.
2915  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
Concurrency::task< _ReturnType >::task ( const task< _ReturnType > &  _Other)
inline

Constructs a task object.

Parameters
_OtherThe source task object.

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

For more information, see Task Parallelism (Concurrency Runtime).

3038 : _M_Impl(_Other._M_Impl) {}
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
Concurrency::task< _ReturnType >::task ( task< _ReturnType > &&  _Other)
inline

Constructs a task object.

Parameters
_OtherThe source task object.

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

For more information, see Task Parallelism (Concurrency Runtime).

3065 : _M_Impl(std::move(_Other._M_Impl)) {}
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290

Member Function Documentation

template<typename _ReturnType>
template<typename _Ty >
Concurrency::task< _ReturnType >::__declspec ( noinline  )
inline

Constructs a task object.

Template Parameters
_TyThe type of the parameter from which the task is to be constructed.
Parameters
_ParamThe parameter from which the task is to be constructed. This could be a lambda, a function object, a task_completion_event<result_type> object, or a Windows::Foundation::IAsyncInfo if you are using tasks in your Windows Store app. The lambda or function object should be a type equivalent to std::function<X(void)>, where X can be a variable of type result_type, task<result_type>, or a Windows::Foundation::IAsyncInfo in Windows Store apps.
_TokenThe cancellation token to associate with this task. A task created without a cancellation token cannot be canceled. It implicitly receives the token cancellation_token::none().

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

For more information, see Task Parallelism (Concurrency Runtime).

2955  {
2956  task_options _TaskOptions;
2957  details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param);
2958 
2959  _CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler());
2960  // Do not move the next line out of this function. It is important that _CAPTURE_CALLSTACK() evaluates to the call site of the task constructor.
2962 
2963  _TaskInitMaybeFunctor(_Param, decltype(details::_IsCallable(_Param,0))());
2964  }
const task_options & _TaskOptions
Definition: ppltasks.h:3003
auto _IsCallable(_Function _Func, int) -> decltype(_Func(), std::true_type())
_TaskInitMaybeFunctor(_Param, decltype(details::_IsCallable(_Param, 0))())
_SetTaskCreationCallstack(details::_get_internal_task_options(_TaskOptions)._M_hasPresetCreationCallstack?details::_get_internal_task_options(_TaskOptions)._M_presetCreationCallstack:_CAPTURE_CALLSTACK())
#define _CAPTURE_CALLSTACK()
Helper macro to determine how many stack frames need to be saved. When any number less or equal to 1 ...
Definition: ppltasks.h:117
_CreateImpl(_TaskOptions.get_cancellation_token()._GetImplValue(), _TaskOptions.get_scheduler())
template<typename _ReturnType>
template<typename _Ty >
Concurrency::task< _ReturnType >::__declspec ( noinline  )

Constructs a task object.

Template Parameters
_TyThe type of the parameter from which the task is to be constructed.
Parameters
_ParamThe parameter from which the task is to be constructed. This could be a lambda, a function object, a task_completion_event<result_type> object, or a Windows::Foundation::IAsyncInfo if you are using tasks in your Windows Store app. The lambda or function object should be a type equivalent to std::function<X(void)>, where X can be a variable of type result_type, task<result_type>, or a Windows::Foundation::IAsyncInfo in Windows Store apps.
_TaskOptionsThe task options include cancellation token, scheduler etc

The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.

A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.

The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.

Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lambda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lambda returns.

task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.

The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Windows Store apps.

For more information, see Task Parallelism (Concurrency Runtime).

template<typename _ReturnType>
template<typename _Function >
Concurrency::task< _ReturnType >::__declspec ( noinline  ) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
inline

Adds a continuation task to this task.

Template Parameters
_FunctionThe type of the function object that will be invoked by this task.
Parameters
_FuncThe continuation function to execute when this task completes. This continuation function must take as input a variable of either result_type or task<result_type>, where result_type is the type of the result this task produces.
Returns
The newly created continuation task. The result type of the returned task is determined by what _Func returns.

The overloads of then that take a lambda or functor that returns a Windows::Foundation::IAsyncInfo interface, are only available to Windows Store apps.

For more information on how to use task continuations to compose asynchronous work, see Task Parallelism (Concurrency Runtime).

3130  {
3131  task_options _TaskOptions;
3133 
3134  // Note: _ThenImpl's implementation makes a copy of the continuation_context when it schedules the continuation.
3135  // The Continuation Context used to create the _ThenImplOptions must still exist when _ThenImpl executes.
3136  auto _ContinuationContext = _TaskOptions.get_continuation_context();
3137  auto _Options = details::_ThenImplOptions::_CreateOptions(_TaskOptions, _ContinuationContext, _ThenGetImpl()->_GetScheduler());
3138 
3139 #ifndef _PPLTASKS_NO_STDFUNC
3140  return _ThenImpl<_ReturnType>(typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_StdFuncT(_Func), _Options);
3141 #else
3142  return _ThenImpl<_ReturnType>(_Func, _Options);
3143 #endif
3144  }
void _set_creation_callstack(const _TaskCreationCallstack &_callstack)
Definition: ppltasks.h:1042
const task_options & _TaskOptions
Definition: ppltasks.h:3003
const details::_Task_ptr< _ReturnType >::_Type & _ThenGetImpl() const
Definition: ppltasks.h:3375
_Internal_task_options & _get_internal_task_options(task_options &_Options)
Definition: ppltasks.h:1266
auto _Options
Definition: ppltasks.h:3179
auto _ContinuationContext
Definition: ppltasks.h:3178
static _ThenImplOptions _CreateOptions(const task_options &_Task_Options, const task_continuation_context &_ContinuationContext, const scheduler_ptr &impl_scheduler)
Definition: ppltasks.h:1250
#define _CAPTURE_CALLSTACK()
Helper macro to determine how many stack frames need to be saved. When any number less or equal to 1 ...
Definition: ppltasks.h:117
std::function< _RetTypeT __cdecl(_ArgTypeT)> _StdFuncT
Definition: ppltasks.h:406
template<typename _ReturnType>
template<typename _Function >
Concurrency::task< _ReturnType >::__declspec ( noinline  ) const

Adds a continuation task to this task.

Template Parameters
_FunctionThe type of the function object that will be invoked by this task.
Parameters
_FuncThe continuation function to execute when this task completes. This continuation function must take as input a variable of either result_type or task<result_type>, where result_type is the type of the result this task produces.
_TaskOptionsThe task options include cancellation token, scheduler and continuation context. By default the former 3 options are inherited from the antecedent task
Returns
The newly created continuation task. The result type of the returned task is determined by what _Func returns.

The overloads of then that take a lambda or functor that returns a Windows::Foundation::IAsyncInfo interface, are only available to Windows Store apps.

For more information on how to use task continuations to compose asynchronous work, see Task Parallelism (Concurrency Runtime).

template<typename _ReturnType>
template<typename _Function >
Concurrency::task< _ReturnType >::__declspec ( noinline  ) const

Adds a continuation task to this task.

Template Parameters
_FunctionThe type of the function object that will be invoked by this task.
Parameters
_FuncThe continuation function to execute when this task completes. This continuation function must take as input a variable of either result_type or task<result_type>, where result_type is the type of the result this task produces.
_CancellationTokenThe cancellation token to associate with the continuation task. A continuation task that is created without a cancellation token will inherit the token of its antecedent task.
_ContinuationContextA variable that specifies where the continuation should execute. This variable is only useful when used in a Windows Store style app. For more information, see task_continuation_context
Returns
The newly created continuation task. The result type of the returned task is determined by what _Func returns.

The overloads of then that take a lambda or functor that returns a Windows::Foundation::IAsyncInfo interface, are only available to Windows Store apps.

For more information on how to use task continuations to compose asynchronous work, see Task Parallelism (Concurrency Runtime).

template<typename _ReturnType>
Concurrency::task< _ReturnType >::_CreateImpl ( _TaskOptions.  get_cancellation_token)._GetImplValue(,
_TaskOptions.  get_scheduler() 
)
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_CreateImpl ( details::_CancellationTokenState _Ct,
scheduler_ptr  _Scheduler 
)
inline

Create an underlying task implementation.

3358  {
3359  _ASSERTE(_Ct != nullptr);
3362  {
3363  _M_Impl->_RegisterCancellation(_M_Impl);
3364  }
3365  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:332
static _Type _Make(_CancellationTokenState *_Ct, scheduler_ptr _Scheduler_arg)
Definition: ppltasks.h:1282
template<typename _ReturnType>
const details::_Task_ptr<_ReturnType>::_Type& Concurrency::task< _ReturnType >::_GetImpl ( ) const
inline

Return the underlying implementation for this task.

3371  {
3372  return _M_Impl;
3373  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetAsync ( bool  _Async = true)
inline

Sets a property determining whether the task is apartment aware.

3407  {
3408  _GetImpl()->_SetAsync(_Async);
3409  }
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3370
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetImpl ( const typename details::_Task_ptr< _ReturnType >::_Type &  _Impl)
inline

Set the implementation of the task to be the supplied implementation.

3389  {
3390  _ASSERTE(!_M_Impl);
3391  _M_Impl = _Impl;
3392  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetImpl ( typename details::_Task_ptr< _ReturnType >::_Type &&  _Impl)
inline

Set the implementation of the task to be the supplied implementation using a move instead of a copy.

3398  {
3399  _ASSERTE(!_M_Impl);
3400  _M_Impl = std::move(_Impl);
3401  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
template<typename _ReturnType>
Concurrency::task< _ReturnType >::_SetTaskCreationCallstack ( details::  _get_internal_task_options_TaskOptions)._M_hasPresetCreationCallstack?details::_get_internal_task_options(_TaskOptions)._M_presetCreationCallstack:_CAPTURE_CALLSTACK()
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_SetTaskCreationCallstack ( const details::_TaskCreationCallstack _callstack)
inline

Sets a field in the task impl to the return callstack for calls to the task constructors and the then method.

3415  {
3416  _GetImpl()->_SetTaskCreationCallstack(_callstack);
3417  }
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3370
template<typename _ReturnType>
Concurrency::task< _ReturnType >::_TaskInitMaybeFunctor ( _Param  ,
decltype(details::_IsCallable(_Param, 0))()   
)
template<typename _ReturnType>
template<typename _Function >
void Concurrency::task< _ReturnType >::_TaskInitMaybeFunctor ( _Function &  _Func,
std::true_type   
)
inlineprivate

Initializes a task using a callable object.

3828  {
3829  _TaskInitWithFunctor<_ReturnType, _Function>(_Func);
3830  }
template<typename _ReturnType>
template<typename _Ty >
void Concurrency::task< _ReturnType >::_TaskInitMaybeFunctor ( _Ty &  _Param,
std::false_type   
)
inlineprivate

Initializes a task using a non-callable object.

3837  {
3838  _TaskInitNoFunctor(_Param);
3839  }
void _TaskInitNoFunctor(task_completion_event< _ReturnType > &_Event)
Initializes a task using a task completion event.
Definition: ppltasks.h:3788
template<typename _ReturnType>
void Concurrency::task< _ReturnType >::_TaskInitNoFunctor ( task_completion_event< _ReturnType > &  _Event)
inlineprivate

Initializes a task using a task completion event.

3789  {
3790  _Event._RegisterTask(_M_Impl);
3791  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
template<typename _InternalReturnType , typename _Function >
void Concurrency::task< _ReturnType >::_TaskInitWithFunctor ( const _Function &  _Func)
inlineprivate

Initializes a task using a lambda, function pointer or function object.

3776  {
3777  typedef typename details::_InitFunctorTypeTraits<_InternalReturnType, std::result_of_t<_Function()>> _Async_type_traits;
3778 
3779  _M_Impl->_M_fFromAsync = _Async_type_traits::_IsAsyncTask;
3780  _M_Impl->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3781  _M_Impl->_M_taskEventLogger._LogScheduleTask(false);
3782  _M_Impl->_ScheduleTask(new _InitialTaskHandle<_InternalReturnType, _Function, typename _Async_type_traits::_AsyncKind>(_GetImpl(), _Func), details::_NoInline);
3783  }
Definition: pplinterface.h:224
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3370
template<typename _ReturnType>
template<typename _Function >
auto Concurrency::task< _ReturnType >::_Then ( const _Function &  _Func,
details::_CancellationTokenState _PTokenState,
details::_TaskInliningMode_t  _InliningMode = details::_ForceInline 
) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType
inline

An internal version of then that takes additional flags and always execute the continuation inline by default. When _ForceInline is set to false, continuations inlining will be limited to default _DefaultAutoInline. This function is Used for runtime internal continuations only.

3427  {
3428  // inherit from antecedent
3429  auto _Scheduler = _GetImpl()->_GetScheduler();
3430 
3431  // Note: _ThenImpl's implementation makes a copy of the continuation_context when it schedules the continuation. '
3432  // The Continuation Context used to create the _ThenImplOptions must still exist when _ThenImpl executes.
3433  auto _Default_Context = task_continuation_context::use_default();
3434  details::_ThenImplOptions _Options (_PTokenState, &_Default_Context, _Scheduler, _CAPTURE_CALLSTACK(), _InliningMode);
3435 
3436 #ifndef _PPLTASKS_NO_STDFUNC
3437  return _ThenImpl<_ReturnType>(typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_StdFuncT(_Func), _Options);
3438 #else
3439  return _ThenImpl<_ReturnType>(_Func, _Options);
3440 #endif
3441  }
auto _Options
Definition: ppltasks.h:3179
#define _CAPTURE_CALLSTACK()
Helper macro to determine how many stack frames need to be saved. When any number less or equal to 1 ...
Definition: ppltasks.h:117
static task_continuation_context use_default()
Creates the default task continuation context.
Definition: ppltasks.h:936
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3370
std::function< _RetTypeT __cdecl(_ArgTypeT)> _StdFuncT
Definition: ppltasks.h:406
template<typename _ReturnType>
const details::_Task_ptr<_ReturnType>::_Type& Concurrency::task< _ReturnType >::_ThenGetImpl ( ) const
inline
3376  {
3377  if (!_M_Impl)
3378  {
3379  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3380  }
3381 
3382  return _M_Impl;
3383  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
return Concurrency::task< _ReturnType >::_ThenImpl ( typename details::_ContinuationTypeTraits< _Function, _ReturnType >::  _StdFuncT_Func,
_Options   
)
template<typename _ReturnType>
return Concurrency::task< _ReturnType >::_ThenImpl ( typename details::_ContinuationTypeTraits< _Function, _ReturnType >::  _StdFuncT_Func,
_Options   
)
template<typename _ReturnType>
template<typename _InternalReturnType , typename _Function >
auto Concurrency::task< _ReturnType >::_ThenImpl ( const _Function &  _Func,
details::_ThenImplOptions _Options 
) const -> typename details::_ContinuationTypeTraits<_Function, _InternalReturnType>::_TaskOfType
inlineprivate

The one and only implementation of then for void and non-void tasks.

3846  {
3847 
3848  typedef details::_FunctionTypeTraits<_Function, _InternalReturnType> _Function_type_traits;
3849  typedef details::_TaskTypeTraits<typename _Function_type_traits::_FuncRetType> _Async_type_traits;
3850  typedef typename _Async_type_traits::_TaskRetType _TaskType;
3851 
3852  //
3853  // A **nullptr** token state indicates that it was not provided by the user. In this case, we inherit the antecedent's token UNLESS this is a
3854  // an exception handling continuation. In that case, we break the chain with a _None. That continuation is never canceled unless the user
3855  // explicitly passes the same token.
3856  //
3857  if (_Options._PTokenState == nullptr)
3858  {
3859  if (_Function_type_traits::_Takes_task::value)
3860  {
3862  }
3863  else
3864  {
3865  _Options._PTokenState = _GetImpl()->_M_pTokenState;
3866  }
3867  }
3868 
3869  task<_TaskType> _ContinuationTask;
3870  _ContinuationTask._CreateImpl(_Options._PTokenState, _Options._Scheduler);
3871 
3872  _ContinuationTask._GetImpl()->_M_fFromAsync = (_GetImpl()->_M_fFromAsync || _Async_type_traits::_IsAsyncTask);
3873  _ContinuationTask._GetImpl()->_M_fUnwrappedTask = _Async_type_traits::_IsUnwrappedTaskOrAsync;
3874  _ContinuationTask._SetTaskCreationCallstack(_Options._CreationStack);
3875 
3876  _GetImpl()->_ScheduleContinuation(new _ContinuationTaskHandle<_InternalReturnType, _TaskType, _Function, typename _Function_type_traits::_Takes_task, typename _Async_type_traits::_AsyncKind>(
3877  _GetImpl(), _ContinuationTask._GetImpl(), _Func, *_Options._PContinuationContext, _Options._InliningMode));
3878 
3879  return _ContinuationTask;
3880  }
auto _Options
Definition: ppltasks.h:3179
static _CancellationTokenState * _None()
Definition: pplcancellation_token.h:332
const details::_Task_ptr< _ReturnType >::_Type & _GetImpl() const
Return the underlying implementation for this task.
Definition: ppltasks.h:3370
template<typename _ReturnType>
Concurrency::task< _ReturnType >::details::_get_internal_task_options ( _TaskOptions  )
template<typename _ReturnType>
_ReturnType Concurrency::task< _ReturnType >::get ( ) const
inline

Returns the result this task produced. If the task is not in a terminal state, a call to get will wait for the task to finish. This method does not return a value when called on a task with a result_type of void.

Returns
The result of the task.

If the task is canceled, a call to get will throw a task_canceled exception. If the task encountered an different exception or an exception was propagated to it from an antecedent task, a call to get will throw that exception.

3265  {
3266  if (!_M_Impl)
3267  {
3268  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3269  }
3270 
3271  if (_M_Impl->_Wait() == canceled)
3272  {
3273  _THROW_NCEE(task_canceled, _EMPTY_ARGUMENT);
3274  }
3275 
3276  return _M_Impl->_GetResult();
3277  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
#define _THROW_NCEE(x, y)
Definition: xstddef:78
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplinterface.h:121
#define _EMPTY_ARGUMENT
Definition: xstddef:82
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::is_apartment_aware ( ) const
inline

Determines whether the task unwraps a Windows Runtime IAsyncInfo interface or is descended from such a task.

Returns
true if the task unwraps an IAsyncInfo interface or is descended from such a task, false otherwise.
3322  {
3323  if (!_M_Impl)
3324  {
3325  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3326  }
3327  return _M_Impl->_IsApartmentAware();
3328  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::is_done ( ) const
inline

Determines if the task is completed.

Returns
True if the task has completed, false otherwise.

The function returns true if the task is completed or canceled (with or without user exception).

3289  {
3290  if (!_M_Impl)
3291  {
3292  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3293  }
3294 
3295  return _M_Impl->_IsDone();
3296  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::operator!= ( const task< _ReturnType > &  _Rhs) const
inline

Determines whether two task objects represent different internal tasks.

Returns
true if the objects refer to different underlying tasks, and false otherwise.
3350  {
3351  return !operator==(_Rhs);
3352  }
bool operator==(const task< _ReturnType > &_Rhs) const
Determines whether two task objects represent the same internal task.
Definition: ppltasks.h:3337
template<typename _ReturnType>
task& Concurrency::task< _ReturnType >::operator= ( const task< _ReturnType > &  _Other)
inline

Replaces the contents of one task object with another.

Parameters
_OtherThe source task object.

As task behaves like a smart pointer, after a copy assignment, this task objects represents the same actual task as _Other does.

3079  {
3080  if (this != &_Other)
3081  {
3082  _M_Impl = _Other._M_Impl;
3083  }
3084  return *this;
3085  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
task& Concurrency::task< _ReturnType >::operator= ( task< _ReturnType > &&  _Other)
inline

Replaces the contents of one task object with another.

Parameters
_OtherThe source task object.

As task behaves like a smart pointer, after a copy assignment, this task objects represents the same actual task as _Other does.

3099  {
3100  if (this != &_Other)
3101  {
3102  _M_Impl = std::move(_Other._M_Impl);
3103  }
3104  return *this;
3105  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
template<typename _ReturnType>
bool Concurrency::task< _ReturnType >::operator== ( const task< _ReturnType > &  _Rhs) const
inline

Determines whether two task objects represent the same internal task.

Returns
true if the objects refer to the same underlying task, and false otherwise.
3338  {
3339  return (_M_Impl == _Rhs._M_Impl);
3340  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
scheduler_ptr Concurrency::task< _ReturnType >::scheduler ( ) const
inline

Returns the scheduler for this task

Returns
A pointer to the scheduler
3305  {
3306  if (!_M_Impl)
3307  {
3308  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3309  }
3310 
3311  return _M_Impl->_GetScheduler();
3312  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883
template<typename _ReturnType>
task_status Concurrency::task< _ReturnType >::wait ( ) const
inline

Waits for this task to reach a terminal state. It is possible for wait to execute the task inline, if all of the tasks dependencies are satisfied, and it has not already been picked up for execution by a background worker.

Returns
A task_status value which could be either completed or canceled. If the task encountered an exception during execution, or an exception was propagated to it from an antecedent task, wait will throw that exception.
3243  {
3244  if (!_M_Impl)
3245  {
3246  details::_DefaultTaskHelper::_NoCallOnDefaultTask_ErrorImpl();
3247  }
3248 
3249  return _M_Impl->_Wait();
3250  }
details::_Task_ptr< _ReturnType >::_Type _M_Impl
Definition: ppltasks.h:3883

Friends And Related Function Documentation

template<typename _ReturnType>
template<typename _Ty >
friend class task
friend

Member Data Documentation

template<typename _ReturnType>
cancellation_token Concurrency::task< _ReturnType >::_CancellationToken
template<typename _ReturnType>
auto Concurrency::task< _ReturnType >::_ContinuationContext = _TaskOptions.get_continuation_context()
template<typename _ReturnType>
details::_Task_ptr<_ReturnType>::_Type Concurrency::task< _ReturnType >::_M_Impl
private
template<typename _ReturnType>
auto Concurrency::task< _ReturnType >::_Options = details::_ThenImplOptions::_CreateOptions(_TaskOptions, _ContinuationContext, _ThenGetImpl()->_GetScheduler())
template<typename _ReturnType>
const task_options& Concurrency::task< _ReturnType >::_TaskOptions
Initial value:
{
details::_ValidateTaskConstructorArgs<_ReturnType,_Ty>(_Param)

The documentation for this class was generated from the following file: