28 #ifndef _PPLXINTERFACE_H
29 #define _PPLXINTERFACE_H
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
37 #if (_MSC_VER >= 1700)
38 #define _USE_REAL_ATOMICS
41 #define _USE_REAL_ATOMICS
45 #ifdef _USE_REAL_ATOMICS
49 #define _pplx_cdecl __cdecl
64 struct __declspec(novtable) scheduler_interface
66 virtual void schedule(
TaskProc_t, _In_
void* ) = 0;
79 explicit scheduler_ptr(std::shared_ptr<scheduler_interface> scheduler) : m_sharedScheduler(std::move(scheduler))
81 m_scheduler = m_sharedScheduler.get();
87 explicit scheduler_ptr(_In_opt_ scheduler_interface * pScheduler) : m_scheduler(pScheduler)
102 scheduler_interface *
get()
const
110 operator bool()
const {
return get() !=
nullptr; }
114 std::shared_ptr<scheduler_interface> m_sharedScheduler;
115 scheduler_interface * m_scheduler;
157 #ifdef _USE_REAL_ATOMICS
158 typedef std::atomic<long> atomic_long;
159 typedef std::atomic<size_t> atomic_size_t;
161 template<
typename _T>
162 _T atomic_compare_exchange(std::atomic<_T>& _Target, _T _Exchange, _T _Comparand)
164 _T _Result = _Comparand;
165 _Target.compare_exchange_strong(_Result, _Exchange);
169 template<
typename _T>
170 _T atomic_exchange(std::atomic<_T>& _Target, _T _Value)
172 return _Target.exchange(_Value);
175 template<
typename _T>
176 _T atomic_increment(std::atomic<_T>& _Target)
178 return _Target.fetch_add(1) + 1;
181 template<
typename _T>
182 _T atomic_decrement(std::atomic<_T>& _Target)
184 return _Target.fetch_sub(1) - 1;
187 template<
typename _T>
188 _T atomic_add(std::atomic<_T>& _Target, _T value)
190 return _Target.fetch_add(value) + value;
193 #else // not _USE_REAL_ATOMICS
195 typedef long volatile atomic_long;
196 typedef size_t volatile atomic_size_t;
199 inline T atomic_exchange(T
volatile& _Target, T _Value)
201 return _InterlockedExchange(&_Target, _Value);
204 inline long atomic_increment(
long volatile & _Target)
206 return _InterlockedIncrement(&_Target);
209 inline long atomic_add(
long volatile & _Target,
long value)
211 return _InterlockedExchangeAdd(&_Target, value) + value;
214 inline size_t atomic_increment(
size_t volatile & _Target)
216 #if (defined(_M_IX86) || defined(_M_ARM))
217 return static_cast<size_t>(_InterlockedIncrement(reinterpret_cast<long volatile *>(&_Target)));
219 return static_cast<size_t>(_InterlockedIncrement64(reinterpret_cast<__int64 volatile *>(&_Target)));
223 inline long atomic_decrement(
long volatile & _Target)
225 return _InterlockedDecrement(&_Target);
228 inline size_t atomic_decrement(
size_t volatile & _Target)
230 #if (defined(_M_IX86) || defined(_M_ARM))
231 return static_cast<size_t>(_InterlockedDecrement(reinterpret_cast<long volatile *>(&_Target)));
233 return static_cast<size_t>(_InterlockedDecrement64(reinterpret_cast<__int64 volatile *>(&_Target)));
237 inline long atomic_compare_exchange(
long volatile & _Target,
long _Exchange,
long _Comparand)
239 return _InterlockedCompareExchange(&_Target, _Exchange, _Comparand);
242 inline size_t atomic_compare_exchange(
size_t volatile & _Target,
size_t _Exchange,
size_t _Comparand)
244 #if (defined(_M_IX86) || defined(_M_ARM))
245 return static_cast<size_t>(_InterlockedCompareExchange(reinterpret_cast<long volatile *>(_Target), static_cast<long>(_Exchange), static_cast<long>(_Comparand)));
247 return static_cast<size_t>(_InterlockedCompareExchange64(reinterpret_cast<__int64 volatile *>(_Target), static_cast<__int64>(_Exchange), static_cast<__int64>(_Comparand)));
250 #endif // _USE_REAL_ATOMICS
254 #endif // _PPLXINTERFACE_H
void(_pplx_cdecl * TaskProc_t)(void *)
An elementary abstraction for a task, defined as void (__cdecl * TaskProc_t)(void *)...
Definition: pplxinterface.h:59
The pplx namespace provides classes and functions that give you access to the Concurrency Runtime...
Definition: pplx.h:81
scheduler_ptr(std::shared_ptr< scheduler_interface > scheduler)
Creates a scheduler pointer from shared_ptr to scheduler
Definition: pplxinterface.h:79
Represents a pointer to a scheduler. This class exists to allow the the specification of a shared lif...
Definition: pplxinterface.h:74
The tasks queued to the task_group object have not completed. Note that this value is not presently r...
Definition: pplxinterface.h:137
The tasks queued to the task_group or structured_task_group object completed successfully.
Definition: pplxinterface.h:143
scheduler_ptr(_In_opt_ scheduler_interface *pScheduler)
Creates a scheduler pointer from raw pointer to scheduler
Definition: pplxinterface.h:87
scheduler_interface * operator->() const
Behave like a pointer
Definition: pplxinterface.h:94
task_group_status
Describes the execution status of a task_group or structured_task_group object. A value of this type ...
Definition: pplxinterface.h:130
The task_group or structured_task_group object was canceled. One or more tasks may not have executed...
Definition: pplxinterface.h:149