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 * Parallel Patterns Library
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 _PPLX_H
29 #define _PPLX_H
30
31 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) && !CPPREST_FORCE_PPLX
32 #error This file must not be included for Visual Studio 12 or later
33 #endif
34
35 #ifndef _WIN32
36 #if defined(_WIN32) || defined(__cplusplus_winrt)
37 #define _WIN32
38 #endif
39 #endif // _WIN32
40
41 #ifdef _NO_PPLXIMP
42 #define _PPLXIMP
43 #else
44 #ifdef _PPLX_EXPORT
45 #define _PPLXIMP __declspec(dllexport)
46 #else
47 #define _PPLXIMP __declspec(dllimport)
48 #endif
49 #endif
50
51 #include "cpprest/details/cpprest_compat.h"
52
53 // Use PPLx
54 #ifdef _WIN32
55 #include "pplx/pplxwin.h"
56 #elif defined(__APPLE__)
57 #undef _PPLXIMP
58 #define _PPLXIMP
59 #include "pplx/pplxlinux.h"
60 #else
61 #include "pplx/pplxlinux.h"
62 #endif // _WIN32
63
64 // Common implementation across all the non-concrt versions
65 #include "pplx/pplxcancellation_token.h"
66 #include <functional>
67
68 // conditional expression is constant
69 #if defined(_MSC_VER)
70 #pragma warning(push)
71 #pragma warning(disable: 4127)
72 #endif
73
74 #pragma pack(push,_CRT_PACKING)
75
80
82 {
83
87 _PPLXIMP
void _pplx_cdecl
set_ambient_scheduler(std::shared_ptr<pplx::scheduler_interface> _Scheduler);
88
93
94 namespace details
95 {
96 //
97 // An internal exception that is used for cancellation. Users do not "see" this exception except through the
98 // resulting stack unwind. This exception should never be intercepted by user code. It is intended
99 // for use by the runtime only.
100 //
102 {
103 public:
105 };
106
107 template<typename _T>
109 {
112 _T *_Ptr;
113 };
114
116 {
118 {
119 }
120
122 virtual void invoke() const = 0;
123
124 static void _pplx_cdecl _RunChoreBridge(void * _Parameter)
125 {
128 _PTaskHandle->invoke();
129 }
130 };
131
132 enum _TaskInliningMode
133 {
134 // Disable inline scheduling
135 _NoInline = 0,
136 // Let runtime decide whether to do inline scheduling or not
137 _DefaultAutoInline = 16,
138 // Always do inline scheduling
139 _ForceInline = -1,
140 };
141
142 // This is an abstraction that is built on top of the scheduler to provide these additional functionalities
143 // - Ability to wait on a work item
144 // - Ability to cancel a work item
145 // - Ability to inline work on invocation of RunAndWait
147 {
148 public:
149
151
153 : _M_pScheduler(_PScheduler)
154 {
155 }
156
157 void _ScheduleTask(_TaskProcHandle_t* _PTaskHandle, _TaskInliningMode _InliningMode)
158 {
159 if (_InliningMode == _ForceInline)
160 {
161 _TaskProcHandle_t::_RunChoreBridge(_PTaskHandle);
162 }
163 else
164 {
165 _M_pScheduler->schedule(_TaskProcHandle_t::_RunChoreBridge, _PTaskHandle);
166 }
167 }
168
169 void _Cancel()
170 {
171 // No cancellation support
172 }
173
174 void _RunAndWait()
175 {
176 // No inlining support yet
177 _Wait();
178 }
179
180 void _Wait()
181 {
182 _M_Completed.wait();
183 }
184
185 void _Complete()
186 {
187 _M_Completed.set();
188 }
189
191 {
192 return _M_pScheduler;
193 }
194
195 // Fire and forget
196 static void _RunTask(
TaskProc_t _Proc,
void * _Parameter, _TaskInliningMode _InliningMode)
197 {
198 if (_InliningMode == _ForceInline)
199 {
200 _Proc(_Parameter);
201 }
202 else
203 {
204 // Schedule the work on the ambient scheduler
206 }
207 }
208
209 static bool _pplx_cdecl _Is_cancellation_requested()
210 {
211 // We do not yet have the ability to determine the current task. So return false always
212 return false;
213 }
214 private:
215
218 };
219
220 // For create_async lambdas that return a (non-task) result, we oversubscriber the current task for the duration of the
221 // lambda.
223
225 typedef _TaskInliningMode _TaskInliningMode_t;
227
228 } // namespace details
229
230 } // namespace pplx
231
232 #pragma pack(pop)
233 #if defined(_MSC_VER)
234 #pragma warning(pop)
235 #endif
236
237 #endif // _PPLX_H
void(_pplx_cdecl * TaskProc_t)(void *)
An elementary abstraction for a task, defined as void (__cdecl * TaskProc_t)(void *)...
Definition: pplxinterface.h:59
_PPLXIMP void _pplx_cdecl set_ambient_scheduler(std::shared_ptr< pplx::scheduler_interface > _Scheduler)
Sets the ambient scheduler to be used by the PPL constructs.
The pplx namespace provides classes and functions that give you access to the Concurrency Runtime...
Definition: pplx.h:81
_PPLXIMP std::shared_ptr< pplx::scheduler_interface > _pplx_cdecl get_ambient_scheduler()
Gets the ambient scheduler to be used by the PPL constructs
Represents a pointer to a scheduler. This class exists to allow the the specification of a shared lif...
Definition: pplxinterface.h:74
Manual reset event
Definition: pplxlinux.h:84