STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pplinterface.h
Go to the documentation of this file.
1 /***
2 * ==++==
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 * ==--==
7 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
8 *
9 * pplinterface.h
10 *
11 * Parallel Patterns Library - PPL interface definitions
12 *
13 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
14 ****/
15 
16 #pragma once
17 
18 #ifndef _PPLINTERFACE_H
19 #define _PPLINTERFACE_H
20 
21 #include <memory>
22 #include <atomic>
23 
24 namespace Concurrency
25 {
26 
31 
32 typedef void (__cdecl * TaskProc_t)(void *);
33 
37 struct __declspec(novtable) scheduler_interface
38 {
39  virtual void schedule( TaskProc_t, void* ) = 0;
40 };
41 
48 {
52  explicit scheduler_ptr(std::shared_ptr<scheduler_interface> _Scheduler) : _M_sharedScheduler(std::move(_Scheduler))
53  {
55  }
56 
60  explicit scheduler_ptr(_In_opt_ scheduler_interface * _PScheduler) : _M_scheduler(_PScheduler)
61  {
62  }
63 
67  scheduler_interface *operator->() const
68  {
69  return get();
70  }
71 
75  scheduler_interface * get() const
76  {
77  return _M_scheduler;
78  }
79 
83  operator bool() const { return get() != nullptr; }
84 
85 private:
86 
87  std::shared_ptr<scheduler_interface> _M_sharedScheduler;
88  scheduler_interface * _M_scheduler;
89 };
90 
101 
103 {
108 
110 
114 
116 
120 
122 };
123 
131 
132 class invalid_operation : public std::exception
133 {
134 public:
141 
142  explicit invalid_operation(_In_z_ const char* _Message) _NOEXCEPT
143  : exception(_Message)
144  { }
145 
149 
151  : exception()
152  {}
153 };
154 
162 
163 class task_canceled : public std::exception
164 {
165 public:
172 
173  explicit task_canceled(_In_z_ const char * _Message) _NOEXCEPT
174  : exception(_Message)
175  {}
176 
180 
182  : exception()
183  {}
184 };
185 
186 namespace details
187 {
188 
189 //
190 // An internal exception that is used for cancellation. Users do not "see" this exception except through the
191 // resulting stack unwind. This exception should never be intercepted by user code. It is intended
192 // for use by the runtime only.
193 //
194 class _Interruption_exception : public std::exception
195 {
196 public:
197  explicit _Interruption_exception(const char * _Message) _NOEXCEPT
198  : exception(_Message)
199  {}
200 
202  : exception()
203  {}
204 };
205 
222 {
223  // Disable inline scheduling
225  // Let runtime decide whether to do inline scheduling or not
227  // Always do inline scheduling
229 };
230 
234 typedef std::atomic<long> atomic_long;
235 typedef std::atomic<size_t> atomic_size_t;
236 
237 template<typename _T>
238 _T atomic_compare_exchange(std::atomic<_T>& _Target, _T _Exchange, _T _Comparand)
239 {
240  _T _Result = _Comparand;
241  _Target.compare_exchange_strong(_Result, _Exchange);
242  return _Result;
243 }
244 
245 template<typename _T>
246 _T atomic_exchange(std::atomic<_T>& _Target, _T _Value)
247 {
248  return _Target.exchange(_Value);
249 }
250 
251 template<typename _T>
252 _T atomic_increment(std::atomic<_T>& _Target)
253 {
254  return _Target.fetch_add(1) + 1;
255 }
256 
257 template<typename _T>
258 _T atomic_decrement(std::atomic<_T>& _Target)
259 {
260  return _Target.fetch_sub(1) - 1;
261 }
262 
263 template<typename _T>
264 _T atomic_add(std::atomic<_T>& _Target, _T _Value)
265 {
266  return _Target.fetch_add(_Value) + _Value;
267 }
268 
269 }} // namespace Concurrency::details
270 
271 #endif // _PPLINTERFACE_H
_T atomic_exchange(std::atomic< _T > &_Target, _T _Value)
Definition: pplinterface.h:246
scheduler_ptr(std::shared_ptr< scheduler_interface > _Scheduler)
Creates a scheduler pointer from shared_ptr to scheduler
Definition: pplinterface.h:52
This class describes an exception thrown when an invalid operation is performed that is not more accu...
Definition: pplinterface.h:132
scheduler_ptr(_In_opt_ scheduler_interface *_PScheduler)
Creates a scheduler pointer from raw pointer to scheduler
Definition: pplinterface.h:60
_Interruption_exception() _NOEXCEPT
Definition: pplinterface.h:201
_T atomic_compare_exchange(std::atomic< _T > &_Target, _T _Exchange, _T _Comparand)
Definition: pplinterface.h:238
scheduler_interface * _M_scheduler
Definition: pplinterface.h:88
Definition: pplinterface.h:228
std::atomic< size_t > atomic_size_t
Definition: pplinterface.h:235
This class describes an exception thrown by the PPL tasks layer in order to force the current task to...
Definition: pplinterface.h:163
#define _NOEXCEPT
Definition: yvals.h:25
scheduler_interface * operator->() const
Behave like a pointer
Definition: pplinterface.h:67
STL namespace.
The Concurrency namespace provides classes and functions that provide access to the Concurrency Runti...
Definition: agents.h:43
The tasks queued to the task_group object have not completed. Note that this value is not presently r...
Definition: pplinterface.h:109
_T atomic_decrement(std::atomic< _T > &_Target)
Definition: pplinterface.h:258
invalid_operation() _NOEXCEPT
Constructs an invalid_operation object.
Definition: pplinterface.h:150
task_canceled(_In_z_ const char *_Message) _NOEXCEPT
Constructs a task_canceled object.
Definition: pplinterface.h:173
Definition: pplinterface.h:224
_Interruption_exception(const char *_Message) _NOEXCEPT
Definition: pplinterface.h:197
Definition: pplinterface.h:226
std::shared_ptr< scheduler_interface > _M_sharedScheduler
Definition: pplinterface.h:87
#define _In_z_
Definition: sal.h:310
_TaskInliningMode
The enum defines inlining scheduling policy for ppltasks. Scheduling a chore or a functor with _TaskI...
Definition: pplinterface.h:221
#define _In_opt_
Definition: sal.h:306
#define bool
Definition: stdbool.h:15
The tasks queued to the task_group or structured_task_group object completed successfully.
Definition: pplinterface.h:115
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplinterface.h:121
_T atomic_add(std::atomic< _T > &_Target, _T _Value)
Definition: pplinterface.h:264
const void * _Target(const _XSTD2 type_info &_Info) const _NOEXCEPT
Definition: functional:413
Represents a pointer to a scheduler. This class exists to allow the the specification of a shared lif...
Definition: pplinterface.h:47
void(__cdecl * TaskProc_t)(void *)
An elementary abstraction for a task, defined as void (__cdecl * TaskProc_t)(void *)...
Definition: pplinterface.h:32
_T atomic_increment(std::atomic< _T > &_Target)
Definition: pplinterface.h:252
task_group_status
Describes the execution status of a task_group or structured_task_group object. A value of this type ...
Definition: pplinterface.h:102
task_canceled() _NOEXCEPT
Constructs a task_canceled object.
Definition: pplinterface.h:181
Definition: exception:80
Definition: pplinterface.h:194
constexpr remove_reference< _Ty >::type && move(_Ty &&_Arg) _NOEXCEPT
Definition: type_traits:1290
std::atomic< long > atomic_long
Atomics
Definition: pplinterface.h:234
invalid_operation(_In_z_ const char *_Message) _NOEXCEPT
Constructs an invalid_operation object.
Definition: pplinterface.h:142
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *unexpected_handler)()
_In_ int _Value
Definition: setjmp.h:173