1 /***
2 * ==++==
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * ==--==
17 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
18 *
19 * Utilities to convert between PPL tasks and PPLX tasks
20 *
21 * For the latest on this and related APIs, please see http://casablanca.codeplex.com.
22 *
23 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
24 ****/
25
26 #pragma once
27
28 #ifndef _PPLXCONV_H
29 #define _PPLXCONV_H
30
31 #ifndef _WIN32
32 #error This is only supported on Windows
33 #endif
34
35 #if defined(_MSC_VER) && (_MSC_VER >= 1700) && (_MSC_VER < 1800) && !CPPREST_FORCE_PPLX
36
37 #include <ppltasks.h>
38 #include "pplx/pplxtasks.h"
39
41 {
42 namespace _Ppl_conv_helpers
43 {
44 template<typename _Tc, typename _F>
45 auto _Set_value(_Tc _Tcp, const _F& _Func) -> decltype(_Tcp.set(_Func())) { return _Tcp.set(_Func()); }
46
47 template<typename _Tc, typename _F>
48 auto _Set_value(_Tc _Tcp, const _F& _Func, ...) -> decltype(_Tcp.set()) { _Func(); return _Tcp.set(); }
49
50 template<typename _TaskType, typename _OtherTaskType, typename _OtherTCEType>
51 _OtherTaskType _Convert_task(_TaskType _Task)
52 {
53 _OtherTCEType _Tc;
54 _Task.then([_Tc](_TaskType _Task2) {
55 try
56 {
57 _Ppl_conv_helpers::_Set_value(_Tc, [=]{ return _Task2.get(); });
58 }
59 catch(...)
60 {
61 _Tc.set_exception(std::current_exception());
62 }
63 });
64 _OtherTaskType _T_other(_Tc);
65 return _T_other;
66 }
67 }
68
69 template<typename _TaskType>
71 {
72 return _Ppl_conv_helpers::_Convert_task<typename pplx::task<_TaskType>, concurrency::task<_TaskType>, concurrency::task_completion_event<_TaskType>>(_Task);
73 }
74
75 template<typename _TaskType>
77 {
79 }
80 } // namespace pplx
81
82 #endif
83
84 #endif // _PPLXCONV_H
The pplx namespace provides classes and functions that give you access to the Concurrency Runtime...
Definition: pplx.h:81
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: pplxtasks.h:176
The task_completion_event class allows you to delay the execution of a task until a condition is sati...
Definition: pplxtasks.h:2674